GDI+ Bitmap与WPF BitmapImage的相互转换

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;
 }

你可能感兴趣的:(WPF研究,C#类,GDI+图形类)