Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - How do I save a PNG without any alpha channel?

Tags:

c#

image

wpf

I have a BitmapSource. I save it to a png like this:

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

How can I save it without any alpha channel?

like image 842
Kyle Avatar asked Oct 15 '22 04:10

Kyle


1 Answers

Use FormatConvertedBitmap to convert 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);
like image 65
Ray Burns Avatar answered Oct 18 '22 10:10

Ray Burns