! - PNG , . ( : " " ), . Image, , . , , - setRegion, , (, ) , .
ImageData id = new ImageData("basket.png");
Image image = new Image (display, id, id);
Canvas c = new Canvas (shell, SWT.TRANSPARENT);
c.addPaintListener(
new PaintListener(){
public void paintControl(PaintEvent e)
{
e.gc.drawImage(image, 0, 0);
}
}
);
Region region = new Region();
Rectangle pixel = new Rectangle(0, 0, 1, 1);
for (int y = 0; y < id.height; y++)
{
for (int x = 0; x < id.width; x++)
{
if (id.getAlpha(x,y) > 0)
{
pixel.x = id.x + x;
pixel.y = id.y + y;
region.add(pixel);
}
}
}
c.setRegion(region);
user1439790