Loading 16 bit PNG using Image.FromFile method

When I save an image as (16bit) PNG and load it again using Image.FromFile method the loaded image data is corrupt. This is also visible in the CVB Viewer. If I convert the PNG to TIF first, using some other tool, the resulting image data is correct. So it appears the FromFile method has some issue with reading a 16 bit png file.

Saving a 16 bit mono stream image:

using (StreamImage image = Device.Stream.Wait())
{
image.Save(“image.png”);
}

Loading the saved 16 bit png image:

Image image = Image.FromFile(“image.png”);

Is this a known issue or am I doing something wrong/unsupported?

Hi @Laurens,

sorry for the late reply. I was able to reproduce the problem and we need to analyze it more closely. Do you have to use png or can you use tif? It works fine with this.

Regards,
Arno

Hi @Arno,

Thanks for looking into this. There was no particular reason to use either png or tif so I have indeed switched to using tif instead. But it is good to know that it is unexpected behavior and not something I overlooked.

1 Like

It does in fact look like it’s the loading of the 16 bit PNG that fails, not the saving. Not that this would make matters significantly better… :thinking:

You are correct, that is why I could still use the saved png’s I already had as the information contained in them was valid (so no data lost). I haven’t tested if there is anything special about the saved 16bit png that makes the load behave like this. The loaded image looks like the wrap around >8bit display mode, but changing the display mode makes no difference as the imagedata is actually like that.

The resolution turned out to be comparatively simple: PNG assumes network byte order for high-bit images - and the switch to that was missing in the loader code. The issue will be fixed in release 13.3.

2 Likes