本文介紹了在 C# 中將 WriteableBitmap 轉換為 Bitmap的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
有什么方法可以轉換WriteableBitmap 到 C# 中的位圖?
Is there any way for converting WriteableBitmap to Bitmap in C# ?
推薦答案
實際上非常簡單.下面是一些應該工作的代碼.我還沒有測試過它,我是從頭開始寫的.
It's pretty straightforward, actually. Here's some code that should work. I haven't tested it and I'm writing it from the top of my head.
private System.Drawing.Bitmap BitmapFromWriteableBitmap(WriteableBitmap writeBmp)
{
System.Drawing.Bitmap bmp;
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create((BitmapSource)writeBmp));
enc.Save(outStream);
bmp = new System.Drawing.Bitmap(outStream);
}
return bmp;
}
WriteableBitmap 繼承自 BitmapSource,可以直接保存到流中.然后,您從此流構建位圖.
The WriteableBitmap inherits from a BitmapSource, which can be saved directly to a stream. Then, you build a Bitmap from this stream.
這篇關于在 C# 中將 WriteableBitmap 轉換為 Bitmap的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!