Icons show transparent background as black

Greetings,

On OSX 10.5.6, when I attempt to create a TaskBar Icon from a PNG using
the sample code shown in (I think bigdemo.rb), with some PNGs, (the ones
that I create) the icon shows up with the transparent background shown
as black.

I’ve tried different variations of loading the image, using init_alph,
convert_alpha_to_mask, etc., all with the same results.

I’ve also tried creating the image with several different programs,
Seashore, GIMP, Acorn, again all with the same results.

The only way I’ve been able to successfully get an icon with a
transparent background is to use ICOFX on Windows to convert my PNG to a
windows .ico, but the results seem sub-optimal to me.

All of the PNGs I’ve created show that the background is transparent in
the creating program, in Preview, as well as Camino and Firefox, so I
don’t think it is a problem with the way I’m creating the image.

I’m wondering if it is a problem with the way I’m loading the image, or
if this is a bug in Wx, and in any case if there is something I can do
to get around this problem.

The method below does work with some images, just not the ones that I
create with other than ICOFX.

I’m a newbie as far as image manipulation is concerned, so I would
appreciate any level of help.


def make_icon(imgname)
# Different platforms have different requirements for the
# taskbar icon size
filename = “#{Environment.app_root}/image/#{imgname}”
img = Wx::Image.new(filename)
if Wx::PLATFORM == “WXMSW”
img = img.scale(32, 32)
elsif Wx::PLATFORM == “WXGTK”
img = img.scale(22, 22)
elsif Wx::PLATFORM == “WXMAC”
# img = img.scale(16, 16)
end
# WXMAC can be any size up to 128x128, so don’t scale
icon = Wx::Icon.new
icon.copy_from_bitmap(Wx::Bitmap.new(img))
return icon
end

Daniel Zepeda wrote:

On OSX 10.5.6, when I attempt to create a TaskBar Icon from a PNG using
the sample code shown in (I think bigdemo.rb), with some PNGs, (the ones
that I create) the icon shows up with the transparent background shown
as black.

I’m not sure exactly what is happening here, but I know that it does
work in my app. I checked the code I use to load the icon and it’s
similar to yours - no extra calls to mask/alpha functions needed. The
icon image file is 128x128, RGB, 8 bits / channel. You might want to
check the depth and bits / channel being saved - I use Pixelmator but
I’m sure the other image programs you mention should work.

If you want to post the image as an attachment I’m happy to try
tinkering with it.

alex

Bump.

Thanks Alex, I appreciate your time. I’ve attached an example image.
This was
the result of taking two pre-existing images (I think they were jpegs),
adding an alpha channel, selecting and deleting the areas I wanted to be
transparent, and then putting one over the other in different layers.

Like my other efforts, the areas I want to be transparent (basically the
entire border around the globe) appears transparent in every program
I’ve tried, except
for loading it in wxRuby.

I have no idea what is wrong with it, or how to even find out what is
wrong
with it, so anything you can tell me to point me in the right direction
will be appreciated.

Thanks!

DZ

Alex F. wrote:

If you want to post the image as an attachment I’m happy to try
tinkering with it.

alex

Alex F. wrote:

Daniel Zepeda wrote:

Resize the source image file so that it’s exactly 128x128 and it seems
the problem disappears.

I guess some call to resize the image internally if it’s not 128x128 is
losing the alpha channel on OS X.

a

Yes that did it! I tried resizing it, but not to the maximum. That does
the trick with all my task bar images. Thank you Alex. You’re always a
great help.

DZ

Daniel Zepeda wrote:

Thanks Alex, I appreciate your time. I’ve attached an example image.
This was
the result of taking two pre-existing images (I think they were jpegs),
adding an alpha channel, selecting and deleting the areas I wanted to be
transparent, and then putting one over the other in different layers.

Like my other efforts, the areas I want to be transparent (basically the
entire border around the globe) appears transparent in every program
I’ve tried, except
for loading it in wxRuby.

Resize the source image file so that it’s exactly 128x128 and it seems
the problem disappears.

I guess some call to resize the image internally if it’s not 128x128 is
losing the alpha channel on OS X.

a