我知道如何将字节数组转换为图像。这是我的代码:
//Here create the Bitmap to the know height, width and format
Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
//Bitmap bmp = new Bitmap(width, height);
//Create a BitmapData and Lock all pixels to be written
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(
new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.WriteOnly, bmp.PixelFormat);
//Copy the data from the byte array into BitmapData.Scan0
Marshal.Copy(imgDataArray, 0, bmpData.Scan0, imgDataArray.Length);
//Unlock the pixels
bmp.UnlockBits(bmpData);
bmp.Save("output1.png", System.Drawing.Imaging.ImageFormat.Png);
但是当字节数组是BGR格式时,图像颜色错误(红色为蓝色;蓝色为红色)。任何人都可以帮我弄明白吗?谢谢。
答案 0 :(得分:2)
看起来你需要遍历数组并交换每个像素的R / B值。这应该是相当简单的。
Edge Enhancement标题下的http://www.codeproject.com/Articles/2056/Image-Processing-for-Dummies-with-C-and-GDI-Part-3文章中有代码可以完成这项工作。