簡體   English   中英

將System.Windows.Media.ImageSource轉換為System.Drawing.Bitmap

[英]Convert System.Windows.Media.ImageSource to System.Drawing.Bitmap

如何將System.Windows.Media.ImageSource轉換為C#中的System.Drawing.Bitmap?

它的舊OP,但它仍然可以為其他人派上用場,因為它需要一些時間來找到沒有DLL互操作或剪貼板黑客的清潔解決方案。

這對我有用,你可以使用pngencoder在保存到文件或rtf流之前剪切圖像大小

private System.Drawing.Image ImageWpfToGDI(System.Windows.Media.ImageSource image) {
  MemoryStream ms = new MemoryStream();
  var encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
  encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(image as System.Windows.Media.Imaging.BitmapSource));
  encoder.Save(ms);
  ms.Flush();      
  return System.Drawing.Image.FromStream(ms);
}

請參閱如何在WINFORMS中使用IMAGESOURCE(NO HANDLER)作為SYSTEM.DRAWING.BITMAP(HBITMAP)

如何輕松地將WinForms System.Drawing.Bitmap轉換為您從本文中學到的WPF ImageSource。 今天,我將解釋如何做到這一點。 實際上,他所要做的就是從BitmapSource中提取處理程序,但是,這種方法不受支持,因此我們唯一能做的就是將BitmapSource(或BitmapFrame)的像素復制到字節數組中,然后將它們復制到指針中。 HBITMAP。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM