Results 1 to 3 of 3

Thread: Double Buffered

  1. #1
    hqt
    hqt is offline Member
    Join Date
    Nov 2011
    Posts
    27
    Rep Power
    0

    Question Double Buffered

    To speed up image manipulation, we use double buffered processing. In Java there is a class which name is BUfferedImages for this purpose. But, I have read on other source and there is another example not use bufferdImages. And I don't know what different about this two solution:
    solution 1:
    Java Code:
    Graphics bufferGraphics;
    Image offScreen;
    public void init(){
       bufferGraphics=offScreen.getGraphics();
    }
    public void paint(g){ //paint Event
    {
         bufferGraphics.setClor(Color.red);
         //other stuff here  to draw on bufferGraphics
         g.drawImage(offScreen,0,0,this);
    }
    and this is second solution: use BufferedImage
    Java Code:
    Graphics2D g2d;
    BufferedImage backbuffer;
    public void init(){
        g2d=backbuffer.createGraphics();
     }
    public voi paint(g){
        g2d.setColor(Color.red);
        //other stuff here to draw on backbuffer
        g.drawImage(backbuffer,0,0,this);
    }
    Above code is just a bone code. (no really class, no constructor object,...) but maybe my idea is clearly. I don't know what difference is between those solution. So, who can tell me,please.
    thanks :)

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

    Default Re: Double Buffered

    Swing already has - by default - double buffering support: Painting in AWT and Swing Any reason you want to reinvent the wheel? If your drawing to the image takes a while, use a SwingWorker or a separate thread to draw then use the paintComponent to solely draw the image

  3. #3
    hqt
    hqt is offline Member
    Join Date
    Nov 2011
    Posts
    27
    Rep Power
    0

    Question Re: Double Buffered

    Many examples on the internet I see that use my example 2. I have not tried your idea yet. (I have read your command source but don't understand too much)
    But above examples, do you know what difference is, or they are same ?
    thanks :)

Similar Threads

  1. Buffered Images
    By sgthale in forum New To Java
    Replies: 2
    Last Post: 08-01-2011, 07:15 AM
  2. double a * double b = weird output
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-26-2010, 10:40 AM
  3. Buffered Reader
    By ilovepolluting in forum New To Java
    Replies: 2
    Last Post: 02-04-2010, 09:16 AM
  4. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 08:39 AM

Posting Permissions

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