Community
Participate
Working Groups
Image class ignores the transparency of the attached PNG file with transparency while the Windows Exlorer shows the transparency.
Created attachment 4141 [details] The png file with transparency This is the attachment
The attached PNG file is a indexed pallete based one and contains a TRNS chunk with index'ed alhpa values and I looked into the Image, ImageData and PNG loading class and they handle this case properly. They must be a problem when bringing the imageData Object on the display. I use the image in a ToolItem.
Ok, more infos: I loaded the image like this: ImageData source = new ImageData(name); ImageData mask = source.getTransparencyMask(); Image image = new Image(shell.getDisplay(), source, mask); Because the png image does not contain a transparent pixel (== -1) but only alpha values source.getTransparencyMask() will return a mask with all bits set. Changing the code to ImageData source = new ImageData(name); Image image = new Image(shell.getDisplay(), source); (or Image image = new Image(shell.getDisplay,name); ) ...results in the same problem for PNG images (but GIF transparency still works). The png image object has the alphaData set but it seems to be ignored for ToolItems when the graphics is brought onto the display. Here are some solutions to fix the problem: 1) If the PNG file looks like the previous attached (only has one entry in the TRNS chunk which is set to 0 meaning that it is full transparent) the PNG file gets automatically a transparentPixel to this color entry assigned. 2) Add proper alpha blending in ToolItem and maybe other classes which are missing this. 3) source.getTransparencyMask() returns a "better" mask if getTransparency() returns TRANSPARENCY_ALPHA. Maybe a threseshold should be specified (and defaults to 0x7f) The best would be to implement all three points.
I don't think there is support on the Windows ToolBar for alpha blended images. It only takes an icon (color and mask). On the other hand, I believe Window XP supports icons with alpha transparency. I need to investigate this more.
I'm having the same problem in the GTK port. I tested versions 2.1.1 and 3.0.
*** Bug 41812 has been marked as a duplicate of this bug. ***
*** Bug 45087 has been marked as a duplicate of this bug. ***
One thing I found is that imageData.getTransparencyMask() is documented as returning null if the image has no transparency or if it is not an icon, but the Win32 implementation always returns a mask. If the imagedata does not have a transparentPixel or a transparency mask it simply returns a mask with everything opaque. It never takes the alphaMask into account.
Here is a related Win32 article about how to use 32bit (RGBA) images in WinXP toolbars: http://www.codeguru.com/toolbar/iebars.html
*** Bug 50163 has been marked as a duplicate of this bug. ***
I don't know about the rest of you, but this bug is increadably frustrating and crippling for me. I'm writing a standalone app using SWT right now, and being forced to use GIFs isn't helping one bit. I don't care how it's done, but I sure hope it's done soon. Perhaps you could hack the ImageData so that the platform is tricked into thinking it's another type of image. Manually tune the alpha transparency into the background.
I totally agree with you Daniel, GIF sux, all my icons are .PNGs and converting them to gif make them so ugly... Please fix it :)
*** Bug 66972 has been marked as a duplicate of this bug. ***
Created attachment 13810 [details] Example of PNG alpha trans rendering on menu and toolbar under WinXP An example of inconsistent behaviour for PNG alpha transparrency In the attachment. The toolbar icons display a black background (this is not expected), whereas the menu icons are properly rendered. Also note that the view icons are also alpha-trans PNG's, and these appear to render perfectly on both light and dark backgrounds.
As everybody else here, I've an PNG image with alpha transparency which isn't drawn correctly on Windows XP. The image has a palette, therefore 8 bit color depth, and transparancy values for all palette entries (tRNS chunk). I stepped through the PNG loader and it seems that the image is correctly loaded. Its image data says alpha = -1 depth = 8 transparentPixel = -1 type = -1 alphaData = a byte[] for all pixels palette.isDirect = false if rendered directly onto a GC, it works. Using it for MenuItems works, too. However, if used for ToolItems, Buttons or Labels, I get ugly artifacts. The alphaData is ignored, there's a white or black background instead. Using a CLabel works (because that uses GC#drawImage()). That method eventually uses drawBitmapAlpha() which does the everything "by hand" (quite noticable for larger bitmaps - it's awful slow - can't Windows draw alpha images? Why isn't AlphaBlend() used?) Otherwise, ImageList objects are used to store the images for Windows. According to MSDN, 32 bit alpha channel images are supported for Windows XP. So why doesn't it work as expected? I looked into the codeguru article mentioned above and it seems, that it is enough to provide a 32bit image and a null mask. However, it seems that the Windows bitmap resource created from the Image object has only 8 or 24 bits but not 32 as it should have. The alpha values aren't taken into account. I tried to make SWT create a 32 bit alpha channel Windows bitmap but failed. I'd guess that the OS.BitBlt calls in Image#init() and ImageList#copyBitmap will kill the alpha channel. The code attached creates a 32 bit bitmap, but I can't tell whether with or without alpha values... private Image convertImage(Image image) { ImageData id = image.getImageData(); if (id.depth == 8) { ImageData id2 = new ImageData(id.width, id.height, 32, new PaletteData(0xFF00, 0xFF0000, 0xFF000000), id.scanlinePad, new byte[id.width * id.height * 4]); int i = 0; for (int y = 0; y < id.height; y++) { for (int x = 0; x < id.width; x++) { RGB rgb = id.palette.colors[id.getPixel(x, y)]; id2.data[i++] = (byte) rgb.blue; id2.data[i++] = (byte) rgb.green; id2.data[i++] = (byte) rgb.red; id2.data[i++] = (byte) id.getAlpha(x, y); } } image = new Image(Display.getCurrent(), id2); } return image; } Please fix the bug :)
*** Bug 73170 has been marked as a duplicate of this bug. ***
This is one of those "This just has to work for SWT to be credible" type of bugs. Nobody can afford to use GIF in toolbars now; application users expect higher quality icons, and GIF sucks. I'm a small ISV self-funding the development of my product, and my (contract) coders can jump in and help fix this bug -- IF they can get somebody to help jump-start them. They know SWT pretty well from the API-user point of view, but don't know SWT implementation internals. I'd rather not have to pay them to become SWT-gods. So if somebody can hand us a basic map, compass, and tell us the foxholes to watch out for, we can go try to chase this bug down. Silenio -- any chance for a few minutes of your time with my guys to jump-start them?
Last month in comment 17, Jay Baston offered the use of his developers to help to fix this bug. Is anything happening on this front?
checking in fix
Thanks a ton, Christophe!
v>2004119 fixed with Silenio: toolbar now supports images with alpha on Windows and GTK
On Windows full alpha is supported with XP and the manifest (comctrl 6.0). For other Windows platforms, a threshold (127) is used to generate a transparent mask.
awesome thanks!
Thanks a lot guys !!!!!
Thanks to Chrix and SSQ!
First, a big thank you that it almost works :-) Nevertheless it seems that transparent png images does work correct in menus or shell icons (GTK). I don't know if is a bug of the menu implementations or the image class itself.
Created attachment 16451 [details] Screenshoot A screenshoot where I used the same image for the first toolbar action and the first menu action. Ps. I used a CVS snapshot.
Is this now still a problem? If not, in wich SWT version is it fixed? I tried with 3.1M5a and it still seems to be existing...
Created attachment 19920 [details] For future reference, snippet that runs all the widgets that have setImage. Notice the task tray item and the menu item.
Created attachment 19921 [details] Sample png icon with alpha information used by above snippet (to be copied in same directory as snippet)
Created attachment 19922 [details] gif image with transparency info to compare with alpha in above snippet
Thank you, I tested your code against the CVS HEAD of SWT on GTK/x86. The transparency of the PNG image within the Button, Label and the Shell icon doesn't work. The GIF image seems to work in any case. The background of the tray icon looks a bit odd, but I think its more a problem of GTK.
when do you support complete png support? in 3.1 final? imho it is the most important feature i've been missing in swt!!!
It may be that we run out of time for 3.1. We have fixed many places already. Is there a particular widget that you are using that is still not fixed? Which platform?
i want to use buttons with png images! looks very adventurous in 3.1M6!!! ;-)
It works right now but you need to run with the XP manifest.
When can we start replacing all GIF images in Eclipse to PNGs? :) Especially wizard graphics - I would like to start with the wizard banner graphics because on some platform the background is not white. We would make immediate use of alpha channel to resolve this outstanding issue (since Eclipse 1.0). To upgrade the icons in eclipse from GIFs to PNGs, we need to assure that a one to one replacement on each GIF image with a PNG will work in every possible contexts (toolbar, menu, context menu, tab, local toolbar, tree, button, table, editor, dialog, title bar, wizard, etc, etc...) and platforms. I am very interested in upgrading all the GIFs in eclipse to PNGs format, because this will address many dithering and readability issues with GIFs. But as well it will have a significant quality impact to the overall look and feel.
+1 for PNG support for all UI graphics. See also related bug in support of PNG for wizards: https://bugs.eclipse.org/bugs/show_bug.cgi?id=14905
(In reply to comment #36) > It works right now but you need to run with the XP manifest. Steve, can you enlight my brain and teach me what does that mean, "run with XP manifest"?
You need to copy the file javaw.exe.manifest from the SWT distribution into the directory where you run javaw.exe in order to get the XP look and feel. Most XP native applications embed the contents of this file into their executable but we can't modify the bits of javaw.exe. Thanks Microsoft!
*** Bug 83892 has been marked as a duplicate of this bug. ***
fixed in head > 20050429 fixed on winxp (common control 6), gtk and motif.
Hey, great work! But I have a last minor problem with the PNG image as a shell icon on GTK, which doesn't work. The GIF image works pretty well. BTW, I can't reopen the bug.
Thanks! I opened bug 93349 with a patch for the Shell decorations case on Linux-GTK.
are the common controls 6 the winXP controls? and can i only use these controls with adding a manifiest file into the javaw.exe path?
>BTW, I can't reopen the bug. Not sure why. However, please open specific problem reports to capture places where we might have bugs, rather than reopening this one. >and can i only use these controls with adding a manifiest file into >the javaw.exe path? Yes, you'll need to the manifest for this to work right now on XP.
What about Windows 2000 and Windows 98. Whill this solution with .manifest work?
The XP .manifest is not recognized on those platforms however, when we encounter an image with alpha, we construct a mask for the image.