Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: how do I undo an AlphaComposite?

  1. #1
    Member
    Join Date
    Oct 2010
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default how do I undo an AlphaComposite?

    In my code I have this:

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));

    I'm using this to make a few elements of geometry half-transparent (or whatever alpha so happens to be at the time). When I'm done with the transparency, however, I'd like to go back to normal opaque drawing. But I don't know how to undo the AlphaComposite changes I made.

    I tried this:

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));

    but that doesn't seem to work.

    Any other suggestions?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,294
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: how do I undo an AlphaComposite?

    Haven't worked with composites much so to me this seems like a logical shot in the dark, but try storing the previous Composite by calling getComposite, and use this to set it afterwords
    Composite c = g2d.getComposite();
    //set the composite and do drawing
    g2d.setComposite(c);//reset the composite
    Last edited by copeg; October 20th, 2010 at 10:42 PM.

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    490
    Thanks
    8
    Thanked 46 Times in 44 Posts

    Default Re: how do I undo an AlphaComposite?

    If copeg's suggestion doesn't do the trick, I suggest you create another Graphics reference for the composited painting. Don't forget to release associated native resources with dispose()
    Graphics2D gg = g2d.create(); // cast if necessary -- ! haven't looked at the API for some time
    gg.setComposite(....);
    :
    :
    gg.dispose();
    db

  4. #4
    Member
    Join Date
    Oct 2010
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: how do I undo an AlphaComposite?

    That did the trick. Thanks both.