I’m trying to save a WriteableBitmap to png but always end up with a 24 bit image (no alpha channel).
WriteableBitmap image = new WriteableBitmap(100, 100, 600, 600, PixelFormats.Bgra32, null);
int stride = image.PixelWidth * image.Format.BitsPerPixel / 8;
image.WritePixels(new System.Windows.Int32Rect(0, 0, image.PixelWidth, image.PixelHeight), emptyArray, stride, 0);
FileStream filestream = new FileStream(imageSrc, FileMode.Create);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create((image)));
encoder.Save(filestream);
emptyArray is an array with all pixels being (255, 0, 0, 0) so I can test if the saving has worked.
Any ideas?
I managed to find the problem: the file was altered some place else and overwrote the intial image. So the initial saving of the image worked fine. Sorry for the hassle!