Andy
Andy

Reputation: 1043

Java: gc.drawimage and transparency

I am creating custom SWT widget but I have got problem with transparency. My class extends canvas, I have got png with alpha image in my resources, when I simply write:

this.setBackgroundImage(Colors.getMenuButton()); //getMenuButton returns Image object

everything works ok (with transparency), but my object has to be resizeable so I decided to create funcion:

protected Image BGHelper(Image src) {
    Image i2 = new Image(Display.getDefault(),2,26);
    GC gc2 = new GC(i2);

    Image image = new Image(Display.getDefault(),this.getBounds().width,26);
    GC gc = new GC(image);
    gc.drawImage(src, 0, 0, 3, 25, 0, 0, 3, 26);
    gc2.drawImage(src, 3, 0, 2, 25, 0, 0, 2, 26);
    gc.drawImage(i2, 0, 0, 2, 25, 3, 0, this.getBounds().width-6, 26);
    gc.drawImage(src,53, 0, 3, 26, this.getBounds().width-3, 0, 3, 26);
    gc.dispose();
    gc2.dispose();
    return image;   
}

it cuts left border from source and paste into result, cut center from source, resize and paste into result, cut right border from source and paste into result. Resizing works but there is no transparency (white pixel). Why?

Upvotes: 1

Views: 1546

Answers (1)

sambi reddy
sambi reddy

Reputation: 3085

please look at following doc.It might help you to solve your issue.

http://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html#Transparency

Upvotes: 1

Related Questions