# Icons show transparent background as black

**URL:** <https://www.ruby-forum.com/t/icons-show-transparent-background-as-black/164936>\
**Category:** wxRuby\
**Created:** [April 7, 2009, 4:57pm UTC](https://www.ruby-forum.com/t/icons-show-transparent-background-as-black/164936 "2009-04-07T16:57:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzhou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dzhou](https://www.ruby-forum.com/u/dzhou)\
**Post date:** [April 7, 2009, 4:57pm UTC](https://www.ruby-forum.com/t/icons-show-transparent-background-as-black/164936/1 "2009-04-07T16:57:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dzhou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dzhou](https://www.ruby-forum.com/u/dzhou)\
**Post date:** [April 14, 2009, 1:52pm UTC](https://www.ruby-forum.com/t/icons-show-transparent-background-as-black/164936/2 "2009-04-14T13:52:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dzhou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dzhou](https://www.ruby-forum.com/u/dzhou)\
**Post date:** [April 10, 2009, 12:02am UTC](https://www.ruby-forum.com/t/icons-show-transparent-background-as-black/164936/3 "2009-04-10T00:02:53Z")

</div>

Bump.

---

<div class="post-metadata">

**Author:** ![dzhou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dzhou](https://www.ruby-forum.com/u/dzhou)\
**Post date:** [April 19, 2009, 11:43pm UTC](https://www.ruby-forum.com/t/icons-show-transparent-background-as-black/164936/4 "2009-04-19T23:43:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dzhou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dzhou](https://www.ruby-forum.com/u/dzhou)\
**Post date:** [April 20, 2009, 6:34am UTC](https://www.ruby-forum.com/t/icons-show-transparent-background-as-black/164936/5 "2009-04-20T06:34:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dzhou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dzhou](https://www.ruby-forum.com/u/dzhou)\
**Post date:** [April 20, 2009, 1:14am UTC](https://www.ruby-forum.com/t/icons-show-transparent-background-as-black/164936/6 "2009-04-20T01:14:31Z")

</div>

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
