本文介紹了在 C# 中將 WriteableBitmap 轉(zhuǎn)換為 Bitmap的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
有什么方法可以轉(zhuǎn)換WriteableBitmap 到 C# 中的位圖?
Is there any way for converting WriteableBitmap to Bitmap in C# ?
推薦答案
實(shí)際上非常簡單.下面是一些應(yīng)該工作的代碼.我還沒有測試過它,我是從頭開始寫的.
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,可以直接保存到流中.然后,您從此流構(gòu)建位圖.
The WriteableBitmap inherits from a BitmapSource, which can be saved directly to a stream. Then, you build a Bitmap from this stream.
這篇關(guān)于在 C# 中將 WriteableBitmap 轉(zhuǎn)換為 Bitmap的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!