ネットのどこかで見つけたコードがあります。
unsafe static Bitmap SaveFrame(IntPtr pFrame, int width, int height)
{
try
{
int x, y;
int linesize = width * 3;
byte* scan0 = (byte*)Marshal.ReadIntPtr(pFrame);
IntPtr bufferPtr = Marshal.AllocHGlobal(linesize * height);
byte* buffer = (byte*)bufferPtr;
for (y = 0; y < height; y++)
{
for (x = 0; x < linesize; x = x + 3)
{
*buffer++ = (byte)*(scan0 + y * linesize + x + 2);
*buffer++ = (byte)*(scan0 + y * linesize + x + 1);
*buffer++ = (byte)*(scan0 + y * linesize + x);
}
}
Bitmap b = new Bitmap(width, height, linesize, System.Drawing.Imaging.PixelFormat.Format24bppRgb, bufferPtr);
return b;
}
catch (Exception ex) { throw new Exception(ex.Message); }
}
上記のコードは有効なビットマップを提供しますが、WPFを使用しており、BitmapImageに含める必要があります
このプロセスを経ずに、私はコードを試しています
byte[] ptr = ....
Marshal.Copy(pFrame, ptr , 0, ptr .Length);
BitmapImage aBitmapImage = new BitmapImage();
aBitmapImage.BeginInit();
aBitmapImage.StreamSource = new MemoryStream(ptr); //FLastImageMemStream;//
aBitmapImage.EndInit();
動作しません...
私も試しました
System.Windows.Media.Imaging.BitmapSource.Create(width, height, 96, 96,
System.Windows.Media.PixelFormats.Rgb24, null, bufferPtr,linesize * height,
width * 3 ));
これも私にそれが見える画像を与えません(それをImageのSourceプロパティに割り当てた後)
誰かが私に何かヒントを与えることができますか?ありがとうアレン