[WPF]Drawing.BitmapをBitmapSourceへ変換
昔のDLLがBitmapしか対応してないので、System.DrawingのBitmapをWPFのBitmapSourceへ変換する。
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
public BitmapSource BmpToWPFBmp(System.Drawing.Bitmap bitmap)
{
IntPtr hBitmap = bitmap.GetHbitmap();
BitmapSource source;
source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
DeleteObject(hBitmap);
return source;
}