I have a byte[] array with the bgra bytes of an image, from which I produce a BitmapSource like so:
BitmapSource bmsOut = BitmapSource.Create(
iPixelWidth, iPixelHeight, 96, 96, PixelFormats.Bgra32, null, bytOutput, iStride);
this displays fine on an wpf Image element. HOWEVER, when I then try to create a file from the BitmapSource:
private void mtdSave(BitmapSource bitmapSource, string path, BitmapEncoder encoder)
{
using (var stream = new FileStream(path, FileMode.Create))
{
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
encoder.Save(stream);
}
}
I get strange output dependent on the encoder used: bmp gives a little, maybe 10x10 pixel image of the centre of the image in a sea of black, png does the same without the black. The displayed area looks as if the picture has been cropped by a thumbnail outline (just to describe the visula effect) Furthermore, if you then open the png in Paint the whole picture is there and displayed, but not for the bmp version (Irfanview cannot cope with either of the files)
What is going on? What am I missing?