读书人

怎么将image对象转化成二进制编码

发布时间: 2012-01-11 22:28:46 作者: rapoo

如何将image对象转化成二进制编码
如何将image对象转化成二进制编码

[解决办法]
static public byte[] ImageToByteArray(Image image)
{
// make a memory stream to work with the image bytes
MemoryStream imageStream = new MemoryStream();

// put the image into the memory stream
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);

// make byte array the same size as the image
byte[] imageContent = new Byte[imageStream.Length];

// rewind the memory stream
imageStream.Position = 0;

// load the byte array with the image
imageStream.Read(imageContent, 0, (int)imageStream.Length);
return imageStream.ToArray();
}
[解决办法]

C# code
        public static byte[] ImageToByteArray(Image image)        {            MemoryStream stream = new MemoryStream();            image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);            return stream.ToArray();        } 

读书人网 >C#

热点推荐