How to create a 32 bit RGBA 8888 png file?

574 views
Skip to first unread message

Patrick Steele

unread,
Dec 23, 2007, 11:56:58 AM12/23/07
to wx-u...@lists.wxwidgets.org
wxWidgets: 2.8.6
OS: XP SP 2
IDE: VS 2005

Hi,
Can someone tell me what is going wrong here? I wish to have a 32 bit
RGBA 8888 png that I can use for some opengl multitexturing work, but
I am always missing the alpha channel eg

//save a jpg as a png

wxImage test1( "c:/existing_file.jpg" );
test1.SaveFile( "c:/test1.png" );

//add alpha to the png and save it out

wxImage test2( "c:/test1.png" );
test2.InitAlpha();
test2.SaveFile( "c:/test2.png" );

if ( test2.HasAlpha() )
{
//it enters here ok

int i = 0;
}

//test that the saved file has alpha

wxImage test3( "c:/test2.png" );

if ( test3.HasAlpha() )
{
//it doesn't enter here

int i = 0;
}

I don't get why it doesn't enter the second if statement.
Alternatively, can someone tell me how to create a 32 bit RGBA 8888
png from either Photoshop or Gimp? Every time I try to create one in
either of these applications, I would read the png file into wxWidgets
and I would always get told that it has no alpha in it. An artist I am
not :)
Thanks for any help,
Patrick

Vadim Zeitlin

unread,
Dec 31, 2007, 5:20:45 AM12/31/07
to wx-u...@lists.wxwidgets.org
On Sun, 23 Dec 2007 16:56:58 +0000 Patrick Steele <steele....@gmail.com> wrote:

PS> Can someone tell me what is going wrong here? I wish to have a 32 bit
PS> RGBA 8888 png

Sorry, what do you mean by this ("8888")?

PS> I am always missing the alpha channel eg
PS>
PS> //save a jpg as a png
PS>
PS> wxImage test1( "c:/existing_file.jpg" );
PS> test1.SaveFile( "c:/test1.png" );
PS>
PS> //add alpha to the png and save it out
PS>
PS> wxImage test2( "c:/test1.png" );
PS> test2.InitAlpha();
PS> test2.SaveFile( "c:/test2.png" );

This is not enough, the saved PNG won't have any alpha channel data if all
pixels are opaque. Try really making some pixels (even one would be enough)
[semi-]transparent.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Patrick Steele

unread,
Dec 31, 2007, 5:37:51 PM12/31/07
to wx-u...@lists.wxwidgets.org
Hey Vadim,
By RGBA 8888 .png file, I mean a 32 bit .png image with 8 bits
assigned per pixel for each of red, green, blue and alpha.
So from what you're saying, you cannot save out a .png file with
completely opaque alpha pixels? Is this some sort of optimisation to
force it to be RGB then in this case?
In order to continue progress, I instead went with using .tga files,
which Photoshop can easily save out as 32 bit RGBA. The downside is
that the image files are massive in comparison. With .png files, I
still haven't found a nice way for it to do the same. I'll try out
your way of doing it programatically with one alpha pixel different,
see if that works.
Thanks,
Patrick

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
> For additional commands, e-mail: wx-use...@lists.wxwidgets.org
>
>

Reply all
Reply to author
Forward
0 new messages