-
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:
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
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 :)
-
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
-
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 :)