×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Mar 2003
    Location
    IL/USA
    Posts
    341

    Question REPOST: eSWT -- Rendering Images with Transparent Background

    *PS: Sorry for Repost but I think this one is more descriptive and less vague than other*

    Hi, I have images with transparent background but when they are drawn a background is always drawn. I am using a canvas to draw Images and file formats are png and jpeg. That I want to do is layer one control over another and have the background of control below come through.

    Code:
    public class Picture extends Canvas implements PaintListener
    {
        private Image image;
    
        public Picture(Composite aParent, Image aImage)
        {
            super(aParent, SWT.NONE);
            addPaintListener(this);
            this.image = aImage;
        }
    
        public void paintControl(PaintEvent e)
        {
            if (getVisible())
            {
                //Rectangle rect = getBounds();
                //e.gc.fillRectangle(0, 0, rect.width, rect.height);
                if (image != null)
                {
                    e.gc.drawImage(image, 0, 0);
                }
            }
        }
    
        protected void checkSubclass()
        {
        }
    }
    I am using Nokia S60 5th Edition type device(5800). Any ideas what I am doing wrong?
    Erica A Ramsey / Mobile Apps Developer /
    Resume ~ http://home.comcast.net/~erica.ramsey/CV
    Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/CV/screens.html

  2. #2
    Registered User
    Join Date
    Nov 2007
    Posts
    8

    Re: REPOST: eSWT -- Rendering Images with Transparent Background

    If you want a Canvas that does not draw a background construct it with SWT.NO_BACKGROUND
    http://library.forum.nokia.com/topic...Composite.html

    Code:
    public class Picture extends Canvas implements PaintListener
    {
        private Image image;
    
        public Picture(Composite aParent, Image aImage)
        {
    //        super(aParent, SWT.NONE);
            super(aParent, SWT.NO_BACKGROUND);
            addPaintListener(this);
            this.image = aImage;
        }
    
        public void paintControl(PaintEvent e)
        {
    //        if (getVisible()) // This check is not needed as you will not get a paint event for invisible controls...
            {
                //Rectangle rect = getBounds();
                //e.gc.fillRectangle(0, 0, rect.width, rect.height);
                if (image != null)
                {
                    e.gc.drawImage(image, 0, 0);
                }
            }
        }
    
        protected void checkSubclass()
        {
        }
    }

  3. #3
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: REPOST: eSWT -- Rendering Images with Transparent Background

    Quote Originally Posted by earamsey View Post
    *PS: Sorry for Repost but I think this one is more descriptive and less vague than other*
    You can edit your posts in any way you like using that grey "Edit/Delete Message" button at the bottom of the post. No need to make an entirely new thread Anyway, I locked the other thread to avoid the discussion going on in two places.

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Location
    IL/USA
    Posts
    341

    Re: REPOST: eSWT -- Rendering Images with Transparent Background

    The code, super(aParent, SWT.NO_BACKGROUND);, does not work, It is still being drawn but this time the background is black instead of white.

    Quote Originally Posted by Petru.Motrescu View Post
    If you want a Canvas that does not draw a background construct it with SWT.NO_BACKGROUND
    http://library.forum.nokia.com/topic...Composite.html

    Code:
    public class Picture extends Canvas implements PaintListener
    {
        private Image image;
    
        public Picture(Composite aParent, Image aImage)
        {
    //        super(aParent, SWT.NONE);
            super(aParent, SWT.NO_BACKGROUND);
            addPaintListener(this);
            this.image = aImage;
        }
    
        public void paintControl(PaintEvent e)
        {
    //        if (getVisible()) // This check is not needed as you will not get a paint event for invisible controls...
            {
                //Rectangle rect = getBounds();
                //e.gc.fillRectangle(0, 0, rect.width, rect.height);
                if (image != null)
                {
                    e.gc.drawImage(image, 0, 0);
                }
            }
        }
    
        protected void checkSubclass()
        {
        }
    }
    Erica A Ramsey / Mobile Apps Developer /
    Resume ~ http://home.comcast.net/~erica.ramsey/CV
    Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/CV/screens.html

  5. #5
    Regular Contributor
    Join Date
    Mar 2003
    Location
    IL/USA
    Posts
    341

    Thumbs down eSWT -- Trying to Complicate My Life

    With J2ME straight canvas drawing images with transparences was so straight forward simple and easy. But with eSWT i am having a hard time!! Why? What is the problem? Is it good software design to make simple stuff hard? What am I missing here? I coded everything to spec and it still fails! Is it suppose to be HARD and difficult to make it work properly, when or if it does?

    Is taking something rather simple and making it arcane and difficult the mark of a good SDK?
    Erica A Ramsey / Mobile Apps Developer /
    Resume ~ http://home.comcast.net/~erica.ramsey/CV
    Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/CV/screens.html

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    8

    Re: REPOST: eSWT -- Rendering Images with Transparent Background

    Hi,

    I am sorry for misleading You with my previous reply. I think I now understand what You were trying to achieve. I am afraid 100% background transparency is not yet possible in eSWT. The Controls must draw their background one way or another: natively or with a PaintListener. NO_BACKGROUND is implemented only as far as notifying the Control that the application takes full responsibility of filling the background in a PaintListener.

    Petru

  7. #7
    Regular Contributor
    Join Date
    Mar 2003
    Location
    IL/USA
    Posts
    341

    Re: REPOST: eSWT -- Rendering Images with Transparent Background

    Well, I need transparency? how do I achive this? I have a button ontop of a image and it looks ugly!!!!
    Erica A Ramsey / Mobile Apps Developer /
    Resume ~ http://home.comcast.net/~erica.ramsey/CV
    Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/CV/screens.html

  8. #8
    Regular Contributor
    Join Date
    Mar 2003
    Location
    IL/USA
    Posts
    341

    Re: REPOST: eSWT -- Rendering Images with Transparent Background

    Quote Originally Posted by Petru.Motrescu View Post
    Hi,
    NO_BACKGROUND is implemented only as far as notifying the Control that the application takes full responsibility of filling the background in a PaintListener.

    Petru
    Hmm, if you look at my source, I do tell it NO_BACKGROUND and assume responsibility for drawing background; eSWT -- Rendering Images with Transparent Background; please note that "super(aParent, SWT.NONE);" was changed to "super(aParent, SWT.NO_BACKGROUND);" to indicate that the my class will handle drawing of background in which I do not draw any.

    What I want is given; and I want to draw .

    Correct me if I am wrong, but this was WORKING in j2me was it not? If so why break this?
    Erica A Ramsey / Mobile Apps Developer /
    Resume ~ http://home.comcast.net/~erica.ramsey/CV
    Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/CV/screens.html

  9. #9
    Nokia Developer Expert
    Join Date
    Nov 2008
    Posts
    72

    Re: REPOST: eSWT -- Rendering Images with Transparent Background

    I was under the impression that you are trying to draw a background image to the Canvas and and add eSWT Controls to it. But from your images I got the impression that you are trying to create an image out of two images (decorate one image with the other).. Perhaps you can just draw the second image to the first one by creating a GC for image one and calling gc.drawImage(ImageTwo). Then you can pass this to a button or Label.

    Is this what you are trying to do?

    --
    Gorkem

  10. #10
    Regular Contributor
    Join Date
    Mar 2003
    Location
    IL/USA
    Posts
    341

    Re: REPOST: eSWT -- Rendering Images with Transparent Background

    Quote Originally Posted by gorkem.ercan View Post
    I was under the impression that you are trying to draw a background image to the Canvas and and add eSWT Controls to it. But from your images I got the impression that you are trying to create an image out of two images (decorate one image with the other).. Perhaps you can just draw the second image to the first one by creating a GC for image one and calling gc.drawImage(ImageTwo). Then you can pass this to a button or Label.

    Is this what you are trying to do?

    --
    Gorkem
    I have the background image and a control on top of it. the control is an image button derived from canvas.
    Erica A Ramsey / Mobile Apps Developer /
    Resume ~ http://home.comcast.net/~erica.ramsey/CV
    Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/CV/screens.html

  11. #11
    Registered User
    Join Date
    Mar 2009
    Location
    João Pessoa, Brazil
    Posts
    26

    Re: REPOST: eSWT -- Rendering Images with Transparent Background

    Use ".gif" images that drawImage method will draw with transparency.

Similar Threads

  1. phonecamera images for background
    By morphed in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2005-05-17, 16:28
  2. Replies: 2
    Last Post: 2005-01-07, 03:38
  3. Background transparent
    By lilingphilip in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-10-17, 10:28
  4. creating transparent images at runtime
    By gpinkett in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2003-05-07, 11:22
  5. transparent images
    By funworld_0815 in forum Mobile Java General
    Replies: 0
    Last Post: 2002-12-09, 11:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •