WriteableBitmap的转换在C#位图 [英] Converting WriteableBitmap to Bitmap in C#

查看:523
本文介绍了WriteableBitmap的转换在C#位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法转换 WriteableBitmap的位图在C#中

推荐答案

这是pretty的直白,其实。下面是一些code,它的应该的工作。我没有测试过,我从我的头顶写它。

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.

这篇关于WriteableBitmap的转换在C#位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆