I'm trying to get a SoftwareBitmap
to be usable by stuff in WPF as a Bitmap
.
Approaches like this question shows look promising, but they seem to be using objects from different namespaces that don't quite work in my case. For context, I'm using MediaCapture
from UWP land for webcam streaming in my app which is WPF.
public static WriteableBitmap WriteableBitmapFromSoftwareBitmap(SoftwareBitmap soft)
{
WriteableBitmap writeable = new
WriteableBitmap(soft.PixelWidth, soft.PixelHeight);
soft.CopyToBuffer(writeable.PixelBuffer);
return writeable;
}
public static Bitmap BitmapFromWriteableBitmap(WriteableBitmap writeBmp)
{
Bitmap bmp;
using (MemoryStream outStream = new MemoryStream())
{
System.Windows.Media.Imaging.BitmapEncoder enc = new
BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(writeBmp)); // Error here
enc.Save(outStream);
bmp = new Bitmap(outStream);
}
return bmp;
}
Unfortunately, in BitmapFromWriteableBitmap
, the call to BitmapFrame.Create
is complaining that it can't create a URI from that kind of WriteableBitmap
.
Note that the WriteableBitmap
is a Windows.UI.Xaml.Media.Imaging.WriteableBitmap
,
the SoftwareBitmap
is a Windows.Graphics.Imaging.SoftwareBitmap
,
and the desired Bitmap
is a System.Drawing.Bitmap
.