bitmapData.Scan0指向的图像数据已经是位对齐(bitmapData.Width%4==0)的,
GenImageInterleaved算子的图像输入参数是不需要位对齐的图像数据,所以需要进行下面的数据转换。
public static HImage Bitmap_24bppRgbToHImage(Bitmap bitmap)
{
Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat);
byte[] imageBytes = new byte[bitmapData.Stride * bitmap.Height];
Marshal.Copy(bitmapData.Scan0, imageBytes, 0, imageBytes.Length);
byte[] imageBytesT = new byte[bitmapData.Width*3 * bitmap.Height];
GCHandle gCHandle = GCHandle.Alloc(imageBytesT, GCHandleType.Pinned);
IntPtr intPtr = gCHandle.AddrOfPinnedObject();
for (int i = 0; i < bitmap.Height; i++)
{
Marshal.Copy(