Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Creating a transparent image in Mac OS X
Creating a transparent image in Mac OS X [message #452296] Thu, 17 March 2005 07:09
Steve Cohen is currently offline Steve CohenFriend
Messages: 1
Registered: July 2009
Junior Member
Hi all, I'm writing a program that needs to draw partially transparent
overlay over images. So far, it works in Linux and windows, but the
overlays aren't transparent in OS X. I have some sample code that
illustrates the problem, does anyone know what I'm doing wrong?



import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
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.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ImageTest {
private static Image fullImage;

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
ImageData imageData;//= new ImageData("C:/temp/Idea_PureWhite.jpg");
fullImage = new Image(display, ImageTest.class.getClassLoader()
.getResourceAsStream("org/scohen/juploadr/resources/logo.png "));

imageData = fullImage.getImageData();

imageData.alpha = 128;

Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
String displayText = "transparent label";
ImageData imageData;
Point stringWidth = e.gc.stringExtent(displayText);
ImageData labelData = new ImageData(stringWidth.x + 5 ,
stringWidth.y + 5, 32,
new PaletteData(0xFF, 0xFF00, 0xFF0000));

labelData.alpha = 64;
Image label = new Image(e.display, labelData);
GC gc = new GC(label);
gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLUE));
gc.setForeground(e.display.getSystemColor(SWT.COLOR_WHITE));
gc.fillRectangle(0, 0, labelData.width, labelData.height);

gc.drawString(displayText, 0, 0, true);
labelData = label.getImageData();
labelData.alpha = 64;
e.gc.drawImage(fullImage, 0, 0);
e.gc.drawImage(label, 140, 0);
gc.dispose();
label.dispose();

}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
Previous Topic:IProject instance for plugin is not getting created.
Next Topic:Dynamic Tree Label changing
Goto Forum:
  


Current Time: Wed Apr 24 18:15:37 GMT 2024

Powered by FUDForum. Page generated in 0.02961 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top