Embedding PNG (converting PNG to c/h file) Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3915
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Embedding PNG (converting PNG to c/h file)

Post by ONEEYEMAN » Sat Oct 26, 2019 2:53 pm

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.

User avatar
T-Rex
Moderator
Moderator
Posts: 1190
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

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

Post by T-Rex » Sat Oct 26, 2019 4:53 pm

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.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3915
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN » Sat Oct 26, 2019 9:30 pm

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.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3915
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN » Sun Oct 27, 2019 4:27 am

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.

Post Reply