我是一个有用的助手,可以为您翻译文本。
我正在使用一个第三方DLL,它的参数是RGB缓冲区。 我已经使用以下代码从
问题在于生成的RGB缓冲区不正确。如果我使用正确的参数在IrfanView中打开此缓冲区,则生成的图像不正确(看起来像是被移位了)。
如果我使用C ++代码读取的缓冲区,则可以正常工作。
我注意到比我预期的* 多1个单位。(我知道.NET使用4字节对齐)。
问题是:为什么RGB缓冲区不正确?
我正在使用一个第三方DLL,它的参数是RGB缓冲区。 我已经使用以下代码从
Bitmap
中读取RGB缓冲区:private byte[] GetBGRValues(Bitmap bmp)
{
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;
// Declare an array to hold the bytes of the bitmap.
int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
byte[] rgbValues = new byte[bytes];
// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
bmp.UnlockBits(bmpData);
return rgbValues;
}
问题在于生成的RGB缓冲区不正确。如果我使用正确的参数在IrfanView中打开此缓冲区,则生成的图像不正确(看起来像是被移位了)。
如果我使用C ++代码读取的缓冲区,则可以正常工作。
我注意到比我预期的* 多1个单位。(我知道.NET使用4字节对齐)。
问题是:为什么RGB缓冲区不正确?