4

I am having trouble understanding how to use FormatConvertedBitmap to convert a WriteableBitmap I have from Pbgra32 to Bgr32. The application I'm building was initially using Bgr32, and I introduced WriteableBitmapEx (which uses Pbgra32) to flip an image. Now, I need to convert from Pbgra32 back to Bgr32 to maintain consistency with the rest of the program. The following is what I have:

FormatConvertedBitmap newFormat = new FormatConvertedBitmap(this.colorBitmap, PixelFormats.Bgr32, null, 0);

...which I believe to be correct for doing the conversion. However, I am unsure how to retrieve a WriteableBitmap from this.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
cryptic_star
  • 1,863
  • 3
  • 26
  • 47
  • Couldn't you just create a new WriteableBitmap by passing `newFormat` to [this constructor](http://msdn.microsoft.com/en-us/library/aa346377.aspx)? – Clemens Jan 06 '13 at 20:26

1 Answers1

2

You're on the right track, you just have to cast it to a WriteableBitmap so you can store it as one. And to do this, you have to cast it to a BitmapSource first and create a new WriteableBitmap. So something like this:

WriteableBitmap yourConvertedPicture = new WriteableBitmap(
   (BitmapSource)(new FormatConvertedBitmap(thePictureToConvert, PixelFormats.Bgr32, null, 0))
);

This will also work for converting to any other PixelFormat

Oztaco
  • 3,399
  • 11
  • 45
  • 84