2

I have been searching for hours how to convert XImage (From XLib) to a PNG format. There were some sources, but none of them did work. I want to restrain to libpng or OpenCV if that is possible. How can I achieve this?

Sources:

http://www.codemadness.nl/downloads/xscreenshot.c // Doesn't work, outputs "corrupted" png file

Saving xlib XImage to PNG // I don't want to use Cairo

Community
  • 1
  • 1
Overholt
  • 867
  • 1
  • 10
  • 23
  • That first code snippet uses pnglib, so even if the conversion was not correct, the result should be a valid PNG file. Maybe there is something wrong with your local pnglib? – Jongware May 14 '15 at 09:44
  • I can't imagine there is something wrong with my pnglib. He is converting the image in self defined functions such as "convertrow_msb". I think its more likely, the error is there. – Overholt May 14 '15 at 09:52
  • Then please [edit] the "corrupted png" in your post. You must mean the image data after converting is not correct (if the PNG itself is technically sound). – Jongware May 14 '15 at 09:56
  • "Opening 'aaa.png' failed: Error while reading 'aaa.png'. File corrupted?" - Thats what I get from gimp. Therefore I can't check if the data is correct, because I can't open the image. – Overholt May 14 '15 at 09:59
  • Provide a link to one of the XImages you want to convert and I'll give it a try. Perhaps it's that source code that causes the error -- some memory overflow that messes up pnglib. – Jongware May 14 '15 at 10:01
  • Thank you very much! I was trying that given code snipped, which takes a screenshot and then converts it. You can use that for testing, no need for any extra image. – Overholt May 14 '15 at 10:04
  • I don't want to install XLib to test just the PNG encoder part... – Jongware May 14 '15 at 10:10
  • You want me to serialize the XImage? How am I supposed to do that? I mean, it's basically my question how to do this. Sorry if I misunderstood you. -- EDIT: Oh you want the output .png I get from the converter? – Overholt May 14 '15 at 10:13
  • Here is the link: http://www.filedropper.com/aaa – Overholt May 14 '15 at 10:16
  • I have mistaken "XImage" to be a file format, not a purely internal one. So without XLib I cannot test the PNG end. I'm going to bow out of this discussion - I hope anyone else can help you. – Jongware May 14 '15 at 10:16
  • Okay, thank you anyway for your time! – Overholt May 14 '15 at 10:21
  • (cough) couldn't resist at least checking the png out. It's 'damaged' because there is lots of crap at the start. Removing the first 379 bytes, all the way up to the start of the PNG (`89 50 4E 47`) makes it valid. No idea where it came from - I suspect it picked up your entire stdout stream. – Jongware May 14 '15 at 10:26
  • Haha oh I didn't even check the beginning of the file. So stupid >.< Well, thank you so much, that was perfect help!! – Overholt May 14 '15 at 10:39

0 Answers0