マネージド ビットマップをアンマネージド float 配列にコピーしようとしています (Opencl.net ラッパーの Cl.CreateImage2D で使用するため)。残念ながら例外が発生しますが、配列の長さ (srcIMGBytesSize) を 4 で除算すると成功します。配列の長さに問題はありますか? 画像フォーマットは Format32bppArgb です。モノを使用しています。
System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap(inputImage);
bitmapData = bmpImage.LockBits( new Rectangle(0, 0, bmpImage.Width, bmpImage.Height), ImageLockMode.ReadOnly, inputImage.PixelFormat);
IntPtr srcBmpPtr = bitmapData.Scan0;
int bitsPerPixel = Image.GetPixelFormatSize( inputImage.PixelFormat );
srcIMGBytesSize = bitmapData.Stride * bitmapData.Height;
float[] srcImage2DData = new float[srcIMGBytesSize];
Marshal.Copy(srcBmpPtr, srcImage2DData, 0, srcIMGBytesSize); //Exception at this line
bmpImage.UnlockBits( bitmapData );
データを float[] 配列にコピーしようとすると、次の例外が発生します。
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length)
at System.Runtime.InteropServices.Marshal.Copy(IntPtr source, Single[] destination, Int32 startIndex, Int32 length)
ありがとうございました!