SWTResourceManager.decorateImage looses transparency

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

SWTResourceManager.decorateImage looses transparency

Postby dfayerma » Fri Feb 16, 2007 6:35 am

The SWTResourceManger.decorateImage is not preserving image transparency. (The transparent part of the base image becomes white.)

Here is the version that fixes the problem:

Code: Select all

    /**

     * Returns an image composed of a base image decorated by another image

     * @param baseImage Image The base image that should be decorated

     * @param decorator Image The image to decorate the base image

     * @param corner The corner to place decorator image

     * @return Image The resulting decorated image

     */

    public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {

        HashMap decoratedMap = (HashMap) m_ImageToDecoratorMap.get(baseImage);

        if (decoratedMap == null) {

            decoratedMap = new HashMap();

            m_ImageToDecoratorMap.put(baseImage, decoratedMap);

        }

        Image result = (Image) decoratedMap.get(decorator);

        if (result == null) {

            final Rectangle bid = baseImage.getBounds();

            final Rectangle did = decorator.getBounds();

            final Point baseImageSize = new Point(bid.width, bid.height);

           

            CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() {



                protected void drawCompositeImage(int width, int height) {

                    drawImage(baseImage.getImageData(), 0, 0);

                    if (corner == TOP_LEFT) {

                        drawImage(decorator.getImageData(), 0, 0);

                    } else if (corner == TOP_RIGHT) {

                        drawImage(decorator.getImageData(), bid.width - did.width - 1, 0);

                    } else if (corner == BOTTOM_LEFT) {

                        drawImage(decorator.getImageData(), 0, bid.height - did.height - 1);

                    } else if (corner == BOTTOM_RIGHT) {

                        drawImage(decorator.getImageData(), bid.width - did.width - 1, bid.height - did.height - 1);

                    }

                }



                protected Point getSize() {

                    return baseImageSize;

                }

               

            };

           

            result = compositImageDesc.createImage();

            decoratedMap.put(decorator, result);

        }

        return result;

    }




I'm using CompositeImageDescriptor to let it deal with the transparency.
dfayerma
 
Posts: 30
Joined: Mon Sep 20, 2004 10:51 am
Location: Boston, USA

Re: SWTResourceManager.decorateImage looses transparency

Postby Eric Clayberg » Fri Feb 16, 2007 2:36 pm

Thanks for the code. It looks good.

We'll include it in our next build.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests