Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert WriteableBitmap pixel format to Bgra32 in c# wpf

I have a WriteableBitmap which loads the bitmap image from file(mostly bmp). The bitmap files I am using have different pixel formats such as Indexed8, Bgra32, etc etc. The problem is that my code only works for bgra32 pixel format. So I need help in converting the bitmaps to Bgra32 pixel format in c# wpf.

Thanks

like image 234
Vinod Maurya Avatar asked Nov 17 '10 07:11

Vinod Maurya


1 Answers

I have found the solution:

 if (bmpSource.Format != PixelFormats.Bgra32)
     bmpSource = new FormatConvertedBitmap(bmpSource, PixelFormats.Bgra32, null, 0);
like image 127
Vinod Maurya Avatar answered Oct 23 '22 02:10

Vinod Maurya