Convert WriteableBitmap to Bitmap in C #

Is there a way to convert WriteableBitmap to Bitmap in C #?

+4
source share
1 answer

It is pretty simple, actually. Here is some code that should work. I have not tested it, and I write it on top.

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 inherits from BitmapSource, which can be stored directly in the stream. Then you create a Bitmap from this thread.

+19
source

Source: https://habr.com/ru/post/1488087/


All Articles