Bug 83892 - PNG images rendered without transparency in some controls
Summary: PNG images rendered without transparency in some controls
Status: RESOLVED DUPLICATE of bug 35040
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-27 18:32 EST by Rod Bailey CLA
Modified: 2005-04-29 14:59 EDT (History)
0 users

See Also:


Attachments
Good and bad rendering of PNG transparency across different types of controls (13.57 KB, image/jpeg)
2005-01-27 18:33 EST, Rod Bailey CLA
no flags Details
The PNG icon file needed to run the test code included in this bug report (3.16 KB, image/png)
2005-01-27 18:34 EST, Rod Bailey CLA
no flags Details
Screenshot of the window produced by the new test code (87.40 KB, image/jpeg)
2005-03-27 08:52 EST, Rod Bailey CLA
no flags Details
Updated test code (4.80 KB, image/jpeg)
2005-03-27 08:52 EST, Rod Bailey CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rod Bailey CLA 2005-01-27 18:32:35 EST
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<---------------------
Comment 1 Rod Bailey CLA 2005-01-27 18:33:31 EST
Created attachment 17537 [details]
Good and bad rendering of PNG transparency across different types of controls
Comment 2 Rod Bailey CLA 2005-01-27 18:34:16 EST
Created attachment 17538 [details]
The PNG icon file needed to run the test code included in this bug report
Comment 3 Rod Bailey CLA 2005-03-27 08:49:51 EST
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.
Comment 4 Rod Bailey CLA 2005-03-27 08:52:06 EST
Created attachment 19215 [details]
Screenshot of the window produced by the new test code
Comment 5 Rod Bailey CLA 2005-03-27 08:52:39 EST
Created attachment 19216 [details]
Updated test code
Comment 6 Felipe Heidrich CLA 2005-04-29 14:59:50 EDT

*** This bug has been marked as a duplicate of 35040 ***