Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Transparent Image as layer
Transparent Image as layer [message #479513] Tue, 11 August 2009 11:32 Go to next message
Eclipse UserFriend
Originally posted by:

Hi all,

I'm working on an application where I need to draw semi-transparent traces
of moving objects on top of a static map, but I can't figure out how to do
it in SWT.

Each screen update, which takes place several times per second, and for
each of the moving objects, I want to add a thick semi-transparent colored
line from the object's last position to its current position. This can go
on for days, which makes it impossible to store all the points and redraw
the polyline each time. Also notice that the trace must be
semi-transparent, but yet, two lines crossing each other should not
superimpose each other at the intersection.

The obvious solution would be to keep the trace as a bitmap layer, to
which I can add the new solid piece of the trace for each update, and then
paste it on top of the map with some alpha value set on the layer.
However, the only way to implement this in SWT, as far as I can see, would
to keep the trace in an Image object, and then for each update:

- Paint the next piece of the trace on the Image with a new GC.
- Get the ImageData of the Image.
- Go through the ImageData and modify the alphaData manually, so that
it's transparent wherever there is no trace, and semitransparent where
there is a trace.
- Create a new Image from the ImageData and replace the old Image with it.
- Update screen by first drawing the map and the the Image on top.

But this would be very resource consuming. Can anyone suggest a better way?
Re: Transparent Image as layer [message #480724 is a reply to message #479513] Tue, 18 August 2009 10:31 Go to previous message
Eclipse UserFriend
Originally posted by:

For future reference: In my case, the problem could be solved due to three

1. I need only one overlay layer on top of the background layer.
2. The background layer never changes.
3. The same alpha value can be used for the complete overlay.

Therefore, when I create the overlay layer, I can simply copy the
background image to the overlay layer and set an alpha value on it:

ImageData backgroundData = backgroundLayer.getImageData();
backgroundData.alpha = 100;
overlayLayer = new Image(display, backgroundData);
overlayGC = new GC(overlayLayer);

Then I can paint with solid color on the overlay layer using overlayGC and
blit the layer on top of the background:

targetGc.drawImage(backgroundLayer, 0, 0);
targetGc.drawImage(overlayLayer, 0, 0);
Previous Topic:newbie question
Next Topic:Executing programs with options
Goto Forum:

Current Time: Thu Dec 05 15:07:24 GMT 2019

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

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

Back to the top