BitmapSourceからBitmapに変換する唯一の方法は、安全でないコードを使用することです...このように(Lesters WPFブログから):
myBitmapSource.CopyPixels(bits, stride, 0);
unsafe
{
fixed (byte* pBits = bits)
{
IntPtr ptr = new IntPtr(pBits);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(
width,
height,
stride,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb,ptr);
return bitmap;
}
}
逆にするには:
System.Windows.Media.Imaging.BitmapSource bitmapSource =
System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
bitmap.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
フレームワークにもっと簡単な方法はありますか?そして、それがそこにない理由は何ですか(そうでない場合)?かなり使いやすいと思います。
これが必要な理由は、AForgeを使用してWPFアプリで特定の画像操作を実行するためです。WPFはBitmapSource/ImageSourceを表示したいのですが、AForgeはビットマップで動作します。