私は現在、writeablebitmapを使用してIntPtr
画像のスキャンを取得し、それぞれをに変換しようとしていBitmap
ます。標準のgdiGDI
+ System.Drawing.Bitmapでエラーが発生するため、writeablebitmapを使用したいパラメータが断続的に無効です
http://msdn.microsoft.com/en-us/library/aa346817.aspxWriteableBitmap
と呼ばれるメソッドがありますWritePixels
バッファとストライドに何を設定したかわからないのですが、エラーがスローされますが、ストライドが0と表示されていることがわかります。ストライドを5に設定すると、画像が黒く表示されます。私はこれが最も効率的なコードではないかもしれないことを知っていますが、どんな助けもいただければ幸いです。
//create bitmap header
bmi = new BITMAPINFOHEADER();
//create initial rectangle
Int32Rect rect = new Int32Rect(0, 0, 0, 0);
//create duplicate intptr to use while in global lock
dibhand = dibhandp;
bmpptr = GlobalLock(dibhand);
//get the pixel sizes
pixptr = GetPixelInfo(bmpptr);
//create writeable bitmap
var wbitm = new WriteableBitmap(bmprect.Width, bmprect.Height, 96.0, 96.0, System.Windows.Media.PixelFormats.Bgr32, null);
//draw the image
wbitm.WritePixels(rect, dibhandp, 10, 0);
//convert the writeable bitmap to bitmap
var stream = new MemoryStream();
var encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(wbitm));
encoder.Save(stream);
byte[] buffer = stream.GetBuffer();
var bitmap = new System.Drawing.Bitmap(new MemoryStream(buffer));
GlobalUnlock(dibhand);
GlobalFree(dibhand);
GlobalFree(dibhandp);
GlobalFree(bmpptr);
dibhand = IntPtr.Zero;
return bitmap;