将System.Windows.Media.Imaging.BitmapSource转换为System.Drawing.Image [英] Convert System.Windows.Media.Imaging.BitmapSource to System.Drawing.Image

查看:1089
本文介绍了将System.Windows.Media.Imaging.BitmapSource转换为System.Drawing.Image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把两个图书馆联系在一起。一个只提供 System.Windows.Media.Imaging.BitmapSource 类型的输出,另一个只接受 System.Drawing.Image

I'm tying together two libraries. One only gives output of type System.Windows.Media.Imaging.BitmapSource, the other only accepts input of type System.Drawing.Image.

如何执行此转换?

推荐答案

private System.Drawing.Bitmap BitmapFromSource(BitmapSource bitmapsource)
{
  System.Drawing.Bitmap bitmap;
  using (MemoryStream outStream = new MemoryStream())
  {
    BitmapEncoder enc = new BmpBitmapEncoder();
    enc.Frames.Add(BitmapFrame.Create(bitmapsource));
    enc.Save(outStream);
    bitmap = new System.Drawing.Bitmap(outStream);
  }
  return bitmap;
}

这篇关于将System.Windows.Media.Imaging.BitmapSource转换为System.Drawing.Image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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