[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: SWT image transparency conversion

Hi,

This is done by setting the transparentPixel in an Image's ImageData, as
demonstrated below:

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setBounds(10,10,200,200);
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
    final Image image = new Image(display, "marbles.gif"); // your initial
image
    ImageData data = image.getImageData();
    int pixel = data.getPixel(50, 50);
    data.transparentPixel = pixel;
    final Image newImage = new Image(display, data);
    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            // event.gc.drawImage(image, 10, 10);
            event.gc.drawImage(newImage, 10, 10);
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) display.sleep();
    }
    image.dispose();
    newImage.dispose();
    display.dispose();
}

Grant


"shahbaz" <shahbaz.atta@xxxxxxxxx> wrote in message
news:80bfc45fd88e7facdffbc27b1f06ed1a$1@xxxxxxxxxxxxxxxxxx
> Hi,
> Anyone tell me how to transparent a SWT image for a specific color.
> for example, i want to transparent white color instances of an image into
> transparent.
>
>