tags:

views:

70

answers:

2

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?

+1  A: 

A 24bpp bitmap doesn't have an alpha channel. Supported by the PNG encoder. Create a WriteableBitmap with PixelFormats.Rgb24.

Hans Passant
I don't have control over the bitmapsource i receive, how can i convert the bitmapsource i receive to one with PixelFormats.Rgb24?
Kyle
+2  A: 

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);
Ray Burns