Monogame: PngWriter - ZlibStream dropping data

Created on 6 Apr 2019  路  8Comments  路  Source: MonoGame/MonoGame

I have an image that gets truncated by the ZlibStream class when I save it to a stream using Texture2D.SaveAsPng.

Input:
img

Result after saving to a FileStream using Texture2D.SaveAsPng (note the missing bottom portion):
result

On top of that, attempting to load this image in MonoGame afterwards will cause the program to hang because of failed decompression.

What version of MonoGame does the bug occur on:

  • MonoGame 3.7

What operating system are you using:

  • Windows

What MonoGame platform are you using:

  • WindowsDX

Most helpful comment

@Jjagg,
I dont want my opinion to look like promotion of StbImageWriteSharp(which I maintain) and yet I think it would make sense to completely remove PngWriter and replace it with StbImageWriteSharp.

All 8 comments

I think the reported size in the png does not match the pixel data in the file. The imagedata for the bottom portion is missing. Some image viewers cannot succesfully read the file, others will use a zero color to display the missing data. Depending on how the image is loaded and rendered in the used image viewer, you might not see that the data is missing.

Opening it in feh (it uses libpng) gives me the following:
image

It also reports: libpng error: Not enough image data

@rds1983 @juanjp600

EDIT: I created a png file with a reported width and height, but no image data and I get the same error message.

The first image on the issue should have the complete pixel data: https://user-images.githubusercontent.com/8607119/55673800-2b2f7000-5883-11e9-9771-dd91e6dd1e14.png

The second image is what MonoGame.WindowsDX outputs when using Texture2D.SaveAsPng, the changes made in #6704 allow it to correctly write all the data.

Ah, i got the image from the linked issue in the barotrauma repo. I'll give this another shot.

@Jjagg,
I dont want my opinion to look like promotion of StbImageWriteSharp(which I maintain) and yet I think it would make sense to completely remove PngWriter and replace it with StbImageWriteSharp.

I agree.

@juanjp600 this should be resolved with #6867. The development build should be updated in a bit. Please give it a try if you can :)

Tested, it seems to be working correctly now :)

Great, thanks for verifying!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryancheung picture ryancheung  路  4Comments

MichaelDePiazzi picture MichaelDePiazzi  路  4Comments

monsieurmax picture monsieurmax  路  5Comments

griseus picture griseus  路  5Comments

NET-D3v3l0p3r picture NET-D3v3l0p3r  路  3Comments