首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-01-11 
如何将image对象转化成二进制编码如何将image对象转化成二进制编码[解决办法]static public byte[] ImageT

如何将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();        } 

热点排行