日期:2014-05-18  浏览次数:20767 次

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