// Get the size of the viewport
JComponent canvas = imageDisplay.getCanvas();
Dimension size = canvas.getSize();
// Create a blank image the size of the original image
paintedImage = canvas.createImage((int) size.getWidth(), (int) size.getHeight());
// Get a Graphics object for the blank image
Graphics2D g = (Graphics2D) paintedImage.getGraphics();
g.setClip(0, 0, (int) size.getWidth(), (int) size.getHeight());