problems with drawing image with transparent background [message #461827] |
Sat, 01 October 2005 04:47  |
Eclipse User |
|
|
|
In my application, I want to construct my icons by overlaying different
..gif/jpg/etc files to create a single icon.
The only way I could find to do this was to use an AWT BufferedImage and
convert it to an SWT image as described in a paper (that I lost the
reference to). This works fine for the normal images. However, I
wonder if there is an easier way to do this. Is there a way in SWT
where a graphic can be on top of a transparent background which can be
used to construct an image?
The other problem I have is that I want to increase the brightness of
the image (to make an icon that appears lighter), and I do this with the
AWT image with the following code:
float scaleFactor = 1.8f;
RescaleOp op = new RescaleOp(scaleFactor, 0, null);
offscreen = op.filter(offscreen, null);
And then I convert the image to SWT using the same mechanism as above.
This does not work correctly, the image shows the color that is used to
indicate transparency.
Here is a link to a file that contains a snippet that demonstrates both
of these (and it contains two .gif files which must be in the current
directory when the snippet is executed):
http://www.francisupton.com/IconTest.zip
Thanks,
Francis
|
|
|
Re: problems with drawing image with transparent background [message #461828 is a reply to message #461827] |
Sat, 01 October 2005 09:58  |
Eclipse User |
|
|
|
It's a long shot, but if you get hold of each Image's ImageData, you might be able to find a way to overlay one set of data with another. But I'm not sure how you'd do this easily (whilst obeying alpha transparency etc.) You could also play around with ImageData to get hold of the individual pixel values and create your own new image data to make it happen.
http://help.eclipse.org/help30/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/api/org/eclipse/swt/graphics/Imag eData.html
However, this is essentially doing software blending, which won't necessarily be performant for large numbers of images.
In terms of increasing brightnes in an image, all you need to do is increase the individual red, green and blue pixels by a constant factor to see the increase in brightness. You obviously need to check that they don't go above the largest value for the image depth that you're working with (e.g. 255 for each colour in a 32-bit image).
JFace also has mechanisms to create 'decorator' images which are automatically overlaid in resource trees, but this will not be of use if you're just using plain SWT.
|
|
|
Powered by
FUDForum. Page generated in 0.03229 seconds