WPF - How to save PNG without alpha channel?

I have one BitmapSource. I save it in png as follows:

PngBitmapEncoder enc = new PngBitmapEncoder();
enc.Frames.Add(myBitmapSource);
enc.Save(fs);

How can I save it without alpha?

+5
source share
2 answers

Use FormatConvertedBitmapto convert up to 24 bits per pixel before encoding it:

var noAlphaSource = new FormatConvertedBitmap
{
  Source = myBitmapSource,
  DestinationFormat = PixelFormats.Rgb24
};

var encoder = new PngBitmapEncoder();
enc.Frames.Add(noAlphaSource);
enc.Save(fs);
+4
source

The 24bpp bitmap does not have an alpha channel. Supported by PNG encoder. Create a WriteableBitmap with PixelFormats.Rgb24.

+1
source

All Articles