Image with transparent background [message #448872] |
Fri, 14 January 2005 13:24 |
Stefan Pietsch Messages: 68 Registered: July 2009 |
Member |
|
|
Hi,
I call Button.setImage to set an own Image on a button. How can I get a
transparent background?
Bye Stefan
______________________________________________
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Test {
private static Display display;
private static Shell shell;
private static Image image;
public static void main(String[] args) {
display = new Display();
shell = new Shell(display);
shell.setLayout(new RowLayout());
image = getImage();
Button button = new Button(shell, SWT.PUSH);
button.setImage(image);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
image.dispose();
display.dispose();
}
private static Image getImage() {
Image image = new Image(null, 20, 20);
GC gc = new GC(image);
// gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BAC KGROUND));
// gc.fillRectangle(image.getBounds());
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.setLineWidth(3);
int[] points = new int[] {
7,2,
2,11,
11,4,
4,16,
13,8,
10,15,
15,12
};
gc.drawPolyline(points);
gc.dispose();
return image;
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.02691 seconds