in netbeans.apache.org/src/old_content/content/tutorials/74/images/paintapp_70_PaintCanvas.java [71:93]
public BufferedImage getImage() {
int width = Math.min(getWidth(), 1600);
int height = Math.min(getHeight(), 1200);
if (backingImage == null || backingImage.getWidth() != width || backingImage.getHeight() != height) {
int newWidth = backingImage == null ? width : Math.max(width, backingImage.getWidth());
int newHeight = backingImage == null ? height : Math.max(height, backingImage.getHeight());
if (newHeight > height && newWidth > width && backingImage != null) {
return backingImage;
}
BufferedImage old = backingImage;
backingImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB_PRE);
Graphics2D g = backingImage.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
if (old != null) {
g.drawRenderedImage(old,
AffineTransform.getTranslateInstance(0, 0));
}
g.dispose();
setPreferredSize(new Dimension (newWidth, newHeight));
}
return backingImage;
}