首页 > 代码库 > 双缓存

双缓存

1 private Image offImage = new BufferedImage(800, 700, BufferedImage.TYPE_INT_RGB);//在内存中new一张图片出来
 1 public void paint(Graphics g) { 2         Graphics offG = offImage.getGraphics();//得到内存图片的画笔 3         super.paint(offG); 4         for (Shape shape : shapes) { 5             if (shape != null) { 6                 shape.draw(offG);//把图形画到内存图片上 7             } 8         } 9         g.drawImage(offImage,0,0, null);//把内存中的图片画到屏幕上10     }

 

双缓存