生の RGB24 データ配列を C# でビットマップに変換しようとしていますが、その際に問題が発生しています。
これは対応するコードです:
using System.Runtime.InteropServices;
byte[] frame;
//... code
frame = new byte[1280 * 960];
// code to get the frame
System.Runtime.InteropServices.GCHandle pinnedArray =
GCHandle.Alloc(frame, GCHandleType.Pinned);
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
Bitmap bmp = new Bitmap(width, height, 3 * width,
PixelFormat.Format24bppRgb, pointer);
MemoryStream JPEGStream = new MemoryStream ();
bmp.Save(filepath, System.Drawing.Imaging.ImageFormat.Bmp);**
私は得る
「System.Drawing.dll で 'System.AccessViolationException' 型の未処理の例外が発生しました」
上記のコードで。
ただし、変更した場合:
Bitmap bmp = new Bitmap(width, height, stride,
PixelFormat.Format24bppRgb, pointer);
に
Bitmap bmp = new Bitmap(width/3, height/3, stride,
PixelFormat.Format24bppRgb, pointer);
クラッシュせず、全領域の 1/3 をカバーする 3 つの画像を取得します。私が取得する必要があるのは、1280 X 960 の領域空間全体をカバーする単一の画像です。