Page 1 of 1

Embedding PNG (converting PNG to c/h file)

Posted: Sat Oct 26, 2019 2:53 pm
by ONEEYEMAN
Hi, ALL,
I am trying to embed a PNG that I downloaded from the web.
I have an original PNG, than I went to the other website and make this PNG 16x16 in order to use it in toolbar.
Then I run

Code: Select all

png2c <my_png_file> > <my_png_embedded>
however the resulting c file contains just a line "This is not valid PNG file".

I guess that the (original) PNG I downloaded is not a valid PNG file?
But then it can be loaded by wxImage::Load().

What are my options? Is there a better way to convert the file that works for any PNG?

Thank you.

Re: Embedding PNG (converting PNG to c/h file)

Posted: Sat Oct 26, 2019 4:53 pm
by T-Rex
There was a bin2c utility which works correctly in case if original file was a valid image. There was an updated version somewhere in forum's topics. Or there is another link.

You could try to open the PNG in XnView and save it from there, to ensure that the file is valid.
Also if you are loading the image from memory, you probably should initialize all image handlers in advance, before actually loading the image. This means that loading of global image object before your app's OnInit(), where you call wxInitAllImageHandlers() will not work.

Re: Embedding PNG (converting PNG to c/h file)

Posted: Sat Oct 26, 2019 9:30 pm
by ONEEYEMAN
T-Rex,
I will try bin2c.
I went to XnView website, but there are multiple products.

What I should download?

And yes - I'm initializing the image handlers.

Thank you.

Re: Embedding PNG (converting PNG to c/h file)

Posted: Sun Oct 27, 2019 4:27 am
by ONEEYEMAN
T-Rex,
Please disregard my previous post.
I compiled bin2c from the second ink you posted and the png got converted successfully.

Thank you.

P.S. I will keep the binary around for future references.