【发布时间】:2014-03-18 17:11:04
【问题描述】:
我有一个字节数组 (imgBuffer),其中包含 jpeg 图像的 rgb 值。我想将此保存到位图。当我使用System.IO.File.WriteAllBytes("fileImg.jpg", imgBuffer); 时,我能够以正确的格式在我的目录中看到图像。当我尝试将相同的字节数组 imgBuffer 写入位图对象时,图像会损坏。 (图片格式为24bpp,320x240)
BitmapData data;
Bitmap myBitmap = new Bitmap(320, 240, PixelFormat.Format24bppRgb);
//convert bytes to a bitmap
data = myBitmap .LockBits(new Rectangle(Point.Empty, bitmapResized.Size), ImageLockMode.WriteOnly,
PixelFormat.Format24bppRgb);
Marshal.Copy(imgBuffer, 0, data.Scan0, imgBuffer.Length);
myBitmap .UnlockBits(data);
myBitmap .Save("bitmapImg.jpg");
我必须更改哪些内容才能将 bitmapImg 正确输出到我的目录?我目前收到以下损坏的图像。
【问题讨论】: