原文:
GDI+ Bitmap与WPF BitmapImage的相互转换
return new Bitmap(bitmapImage.StreamSource);
}
// Convert Bitmap to BitmapImage
private BitmapImage Bitmap2BitmapImage(Bitmap bitmap)
{
BitmapSource i = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(),IntPtr.Zero,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions());
return (BitmapImage)i;
}
using System.Windows.Interop;
//...
// Convert BitmapImage to Bitmap
private Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)
{return new Bitmap(bitmapImage.StreamSource);
}
// Convert Bitmap to BitmapImage
private BitmapImage Bitmap2BitmapImage(Bitmap bitmap)
{
BitmapSource i = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(),IntPtr.Zero,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions());
return (BitmapImage)i;
}