libheatmap icon indicating copy to clipboard operation
libheatmap copied to clipboard

failed create valid png file with the example data.

Open bodong1987 opened this issue 9 years ago • 4 comments

points: 12 123 52 12 321 94 87 483 60 10 90 470

use command command: 500 500 10 < points.txt > heatmap.png it create an empty png file. i open this file in photoshop, it report an error: file parse mode can not parse this file.

bodong1987 avatar Oct 15 '16 11:10 bodong1987

I failed to reproduce this issue: I ran your exact command with your exact points, and it created the following image, which I can open in an image viewer:

heatmap

Can you reproduce this issue if you recompile (make clean and make again) and run your command again? Is the generated file completely empty (0 bytes) or somehow corrupt? If you are using a unix-y system (linux or OSX) you can type file heatmap.png to see if it's a valid file.

lucasb-eyer avatar Oct 16 '16 23:10 lucasb-eyer

Hi, I've noticed this issue too, only on windows. Identical commands on Mac seem to run fine, when run on windows the outputted png does seem corrupted,

teg-git avatar Jan 02 '19 22:01 teg-git

Aha, that is great information (that I completely missed, sorry). This makes me guess it's because windows treats cout as text file and so writes \r\n whenever it sees \n, which is stupid. This probably happens in this line here and can probably be fixed by a call to _setmode prior, as mentioned here. Could anyone who encounters this issue try that out and, if it works, create a PR that adds these lines if windows is detected (via #ifdef)?

lucasb-eyer avatar Nov 02 '19 07:11 lucasb-eyer

Aha, that is great information (that I completely missed, sorry). This makes me guess it's because windows treats cout as text file and so writes \r\n whenever it sees \n, which is stupid. This probably happens in this line here and can probably be fixed by a call to _setmode prior, as mentioned here. Could anyone who encounters this issue try that out and, if it works, create a PR that adds these lines if windows is detected (via #ifdef)?

Great! It's working as you tell. But I am a beginner I don't know how to create a PR. By the way, why here we can't simply use "lodepng::save_file(png, "heatmap.png");" instead of "std::cout.write..."?

tanzhuoning avatar Jun 20 '23 05:06 tanzhuoning