Convert System.Windows.Media.Imaging.BitmapSource to System.Drawing.Image

前端 未结 2 1918
后悔当初
后悔当初 2020-12-09 02:32

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.Dr

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 03:08

    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;
    }
    

提交回复
热议问题