我的目标:
在我的Windows Forms程序中显示一个RGB565原始格式的图像。(离题:数据来自OV7670相机模块)
我的方法:
首先,我创建一个空的Bitmap。接下来,我将图像数据(原始格式:rgb565)插入到空Bitmap的有效载荷部分中。最后,在PictureBox中显示修改后的Bitmap。
我的问题:
一切都运行良好,但测试图像显示为斜条纹而不是垂直条纹(请参见下面的链接)。
原始rgb565原始图像:原始rgb565原始图像
PictureBox截图(带有对角线条纹):PictureBox截图
我曾经通过提取R、G、B并使用SetPixel()来显示图像,但这对我来说太慢了。这就是为什么我想获取底层代码以正确地显示图像。
我的测试图像可以在Dropbox上找到:
测试图像:测试图像
MemoryStream memoryStream = new MemoryStream(1000000);
// Read raw image into byte array
string imgpath = "rgb565_LSB-first_313x240.raw";
FileStream fs = new FileStream(imgpath, FileMode.Open);
fs.CopyTo(memoryStream);
Byte[] buffer = memoryStream.ToArray();
// Create empty Bitmep and inject byte arrays data into bitmap's data area
Bitmap bmp = new Bitmap(313, 240, PixelFormat.Format16bppRgb565);
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, 313, 240);
BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite,
PixelFormat.Format16bppRgb565);
IntPtr ptrToFirstPixel = bmpData.Scan0;
// Inject the rgb565 data (stored in the buffer array)
Marshal.Copy(buffer, 0, ptrToFirstPixel, buffer.Length);
bmp.UnlockBits(bmpData);
// Diplay Bitmap in my PictureBox
pbImage.Image = bmp;
期望结果:竖条纹 :-)
实际结果:斜条纹 :-(