Community
Participate
Working Groups
When images are read from a PNG file with transparency, the transparent area is rendered in black when the image is given to some controls. The following test code demonstrates the PNG is rendered incorrectly for: - toolbar buttons - Labels - coolbar buttons The PNG is rendered correctly for: - menu items - CLabels The attached screenshot shows the window that results from running the test code below. The icon file is also attached to this bug report. This is a big problem when using stock icons from an icon vendor. The code below uses a PNG with a transparent background as supplied by iconexperience.com. Many vendors of stock icons use PNG as their standard delivery format. BTW: I know this relates to 35040. I raised it anyway, because I provide some test code that demonstrates the problem across a number of controls, which 35040 doesn't: ------------8<---------------- package test; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.CoolBar; import org.eclipse.swt.widgets.CoolItem; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; public class PNGBugDemo { // Copy the file worker.png attached to this bug report to the root // directory of your C: drive before running this code. private static final String ICON_FILE = "C:/worker.png"; public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Image image = ImageDescriptor.createFromFile(null, ICON_FILE).createImage(); // Menu item Menu menuBar = new Menu(shell, SWT.BAR); MenuItem file = new MenuItem(menuBar, SWT.CASCADE); file.setText("File"); Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); file.setMenu(fileMenu); MenuItem openItem = new MenuItem(fileMenu, SWT.PUSH); openItem.setText("Menu Item"); openItem.setImage(image); shell.setMenuBar(menuBar); // Toolbar item ToolBar toolbar = new ToolBar(shell, SWT.HORIZONTAL); toolbar.setBounds(0, 0, 200, 70); ToolItem openToolItem = new ToolItem(toolbar, SWT.PUSH); openToolItem.setText("Toolbar Item"); openToolItem.setImage(image); // Ordinary label Label label = new Label(shell, SWT.NONE); label.setImage(image); label.setBounds(0, 80, 200, 70); // Complex label CLabel clabel = new CLabel(shell, SWT.NONE); clabel.setText("CLabel"); clabel.setImage(image); clabel.setBounds(0, 150, 200, 70); // Coolbar CoolBar coolbar = new CoolBar(shell, SWT.NONE); coolbar.setBounds(0, 230, 200, 70); CoolItem coolItem = new CoolItem(coolbar, SWT.PUSH); coolItem.setSize(80, 80); Button b = new Button(coolbar, SWT.PUSH); coolItem.setControl(b); b.setImage(image); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } -------------8<---------------------
Created attachment 17537 [details] Good and bad rendering of PNG transparency across different types of controls
Created attachment 17538 [details] The PNG icon file needed to run the test code included in this bug report
I have updated the test code, and provided a screenshot to show what happens when that new test code is run with a Windows XP manifest specifying version 6 of the common controls DLL.
Created attachment 19215 [details] Screenshot of the window produced by the new test code
Created attachment 19216 [details] Updated test code
*** This bug has been marked as a duplicate of 35040 ***