Reputation: 119
I'm really confused by this and I can't tell if its a bug or not.
In my SWT app I'm creating a System Tray icon. It shows up just fine, but the transparency is being ignored. The icon is stored as a PNG and viewing it in Preview on OSX shows that the transparency is there, however when it appears on the tray, it has a white background.
The icon is 2 colors, #00000 for background and the alpha is set on that, and then #010101 for the actual icon.
Here is an example of the icon:
Here is how it appears on the bar:
I've had other icons with actual color in them work and have proper transparency, so I can't help but wonder, is this some kind of rendering bug or some oddity with how Mac handles system tray icons?
Update: Channels and layers: https://i.sstatic.net/c9TH5.png
Update 2:
scratch that
Upvotes: 0
Views: 375
Reputation: 119
I figured it out, it was a face palm moment, sort of.
All logos were loaded from a loader class I made. There is a method which allows the size of the logo to be specified and then scaled down. I was scaling the logo initially, but after I created the new logo it didn't need to be scaled but I forgot to update that method call.
Here's some code to show what was going on.
public static Image getLogo(LogoType type, Display display, int width, int height) {
ClassLoader loader = AppLogo.class.getClassLoader();
InputStream stream = loader.getResourceAsStream(type.getFileName());
Image img;
if(width > 0 && height > 0) {
Image orig = new Image(display, stream);
img = new Image(display, width, height);
GC gc = new GC(img);
gc.drawImage(orig, 0, 0, orig.getBounds().width, orig.getBounds().height, 0, 0, width, height);
gc.dispose();
orig.dispose();
}
else {
img = new Image(display, stream);
}
return img;
}
It seems that using GC to scale the image causes the alpha values to be ignored. I also tried setting a transparency color on the ImageData but that still doesn't work. I've seen some examples where people use an algorithm to go in and scale and in that case they can actually set the pixels and it works. But drawImage doesn't.
Upvotes: 1