png to xpm conversion with transparency Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mentat
Knows some wx things
Knows some wx things
Posts: 30
Joined: Thu Mar 20, 2008 4:03 pm

png to xpm conversion with transparency

Post by mentat » Sat May 23, 2009 3:22 pm

Hi,

I am using some png files for buttons etc in my project. They are transparent. I would like to embed them in my project exe, but when I tried xpm conversion with both imagemagick and gimp, xpm files are ugly. Perhaps, I couldn't give correct parameters for convert in imagemagick, not sure, but they are not well antialiased (or smooth) at edges (with the transparent parts).

So, does anyone know proper procedure / parameters for imagemagick to convert transparent png's to xpm?

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Sun May 24, 2009 7:24 pm

XPM doesn't support alpha transparency, only image masks. You can embed PNG images directly in an executable in almost the same way you would with XPM though. Take a look here.

mentat
Knows some wx things
Knows some wx things
Posts: 30
Joined: Thu Mar 20, 2008 4:03 pm

Post by mentat » Sun May 24, 2009 8:08 pm

Thanks for the answer, but although xpm does not really support transparency, it does have proper background (a purple?) such that when used as widget images, they look ok. So, xpm's are fine to be used for my purposes.

I also know how to embed png's (your link), however, I use wxFormBuilder as my design tool, and unfortunately it doesn't support that. So, if I decide to embed png's, I have to modify my automatically generated cpp/h files manually all the time which is not ok.

So, to sum up, I will still appreciate settings to generate smooth xpm files.

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Mon May 25, 2009 4:49 pm

mentat wrote:I also know how to embed png's (your link), however, I use wxFormBuilder as my design tool, and unfortunately it doesn't support that. So, if I decide to embed png's, I have to modify my automatically generated cpp/h files manually all the time which is not ok.
You are a programmer, right? Write a script to do it during pre-build.
mentat wrote:So, to sum up, I will still appreciate settings to generate smooth xpm files.
What I'm saying is that, based on your description, the "smooth" aspect of your image is a direct result of alpha transparency values in the image, which the XPM image format doesn't support. It has nothing to do with the GIMP or Imagemagick, it's the XPM format itself. If you want to keep the smooth transparency in your images, you need to use an image format that supports it. PNG supports it, and that's what your original source images are, so it simply makes sense to use PNG, not convert it to something else.

TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV » Mon May 25, 2009 6:11 pm

For conversion, i use nconvert.exe (http://www.xnview.com/en/nconvert.html).

For transparency, edit your .xpm with a text editor and put NONE instead of the #RRGGBB code for the right color (generally the 1st one).

extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Post by extreme001 » Tue May 26, 2009 11:24 am

You can use XPM Convert, too.

It's great. I use it almost every day!

mentat
Knows some wx things
Knows some wx things
Posts: 30
Joined: Thu Mar 20, 2008 4:03 pm

Post by mentat » Tue May 26, 2009 3:11 pm

extreme001: Can you please provide me a link? what is xpm convert?

Post Reply