• 图片与字节流转换问题


    usingSystem;
    usingSystem.Collections.Generic;
    usingSystem.Linq;
    usingSystem.Text;
    usingSystem.Drawing;
    usingSystem.IO;
    namespaceMicrosoft.Form.Base
    {
        classImageToByte
        {
            /// <summary>
            /// 图片转换成字节流
            /// </summary>
            /// <param name="img">要转换的Image对象</param>
            /// <returns>转换后返回的字节流</returns>
            public static byte[] ImgToByt(Image img)
            {
                MemoryStream ms = new MemoryStream();
                byte[] imagedata = null;
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                imagedata = ms.GetBuffer();
                return imagedata;            
            }
            /// <summary>
            /// 字节流转换成图片
            /// </summary>
            /// <param name="byt">要转换的字节流</param>
            /// <returns>转换得到的Image对象</returns>
            public static Image BytToImg(byte[] byt)
            {
                MemoryStream ms = new MemoryStream(byt);
                Image img = Image.FromStream(ms);
                return img;
            }
            //
            /// <summary>
            /// 根据图片路径返回图片的字节流byte[]
            /// </summary>
            /// <param name="imagePath">图片路径</param>
            /// <returns>返回的字节流</returns>
            private static byte[] getImageByte(stringimagePath)
            {
                FileStream files = new FileStream(imagePath, FileMode.Open);
                byte[] imgByte = new byte[files.Length];
                files.Read(imgByte, 0, imgByte.Length);
                files.Close();
                returnimgByte;
            }
        }
    }

  • 相关阅读:
    poj2954
    bzoj1863
    bzoj2002
    bzoj1389
    [POJ3041] Asteroids(最小点覆盖-匈牙利算法)
    [POJ2594] Treasure Exploration(最小路径覆盖-传递闭包 + 匈牙利算法)
    [POJ2446] Chessboard(二分图最大匹配-匈牙利算法)
    [luoguP1266] 速度限制(spfa)
    [luoguP1186] 玛丽卡(spfa)
    [luoguP1027] Car的旅行路线(Floyd)
  • 原文地址:https://www.cnblogs.com/jf-guo/p/6610408.html
Copyright © 2020-2023  润新知