Results 1 to 4 of 4
  1. #1
    zirbinator is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default Filling with transparency

    Hello,

    What is the fastest way to fill a rectangle with a transparent color?
    Simply using java.awt.Graphics and java.awt.Color like this is not fast enough:

    Graphics g;
    g.setColor(new Color(100, 100, 100, 100));
    g.fillRect(new Rectangle(0, 0, 100, 100));


    Is there a faster way to do this?

    Thanks.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    Why would you want something faster? The above should be lightning fast. If you are having problems with painting slowing down things, I'd suggest profiling your code a bit to determine the bottleneck (I somewhat doubt the above is - and if it is recommend you post an SSCCE demonstrating the problem)

  3. #3
    zirbinator is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default

    Why would you want something faster? The above should be lightning fast. If you are having problems with painting slowing down things, I'd suggest profiling your code a bit to determine the bottleneck (I somewhat doubt the above is - and if it is recommend you post an SSCCE demonstrating the problem)
    I'm trying to fill the entire screen with this transparent color, and so it takes about 10 milliseconds every draw loop, which, while it may not seem like much, is far too long and creates major lag. To find this time I simply used something like the following:

    Graphics g;
    g.setColor(new Color(0, 0, 0, 100));
    long before = System.nanoTime();
    g.fillRect(0, 0, 1600, 900);
    System.out.println((System.nanoTime() - before)/1000000);


    And this gives me 10 or 11.
    Last edited by zirbinator; 02-09-2011 at 02:34 AM.

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    Well, its not that much, which again makes me wonder if this is indeed the bottleneck. Again, its hard to give detailed advice without detailed context.

Similar Threads

  1. Serializing BufferedImage with keeping transparency
    By Spitfire777 in forum Java 2D
    Replies: 2
    Last Post: 12-15-2010, 08:49 PM
  2. Alternating Transparency Based on Double Variable
    By YellowPainting in forum Java 2D
    Replies: 2
    Last Post: 11-05-2010, 09:59 PM
  3. ImageIcon Transparency
    By Lingerz in forum New To Java
    Replies: 2
    Last Post: 06-04-2010, 03:53 PM
  4. Setting an image's transparency?
    By aaroffl in forum AWT / Swing
    Replies: 1
    Last Post: 12-03-2008, 01:01 PM
  5. Replies: 0
    Last Post: 07-25-2008, 03:26 PM

Tags for this Thread

Posting Permissions

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