June 2005
Beginner to intermediate
336 pages
6h 29m
English
If the user clicks the Reduce button, the image is reduced by a factor of two in each dimension, as you can see in Figure 3.8.

This one works by using the BufferedImage class's getScaledInstance method, which it inherits from the Image class. This method changes the size of an image, but it returns an Image object, so it takes a little work to get back to a BufferedImage object:
if(event.getSource() == button5){
bufferedImageBackup = bufferedImage;
image = bufferedImage.getScaledInstance
(bufferedImage.getWidth()/2, bufferedImage.getHeight()/2, 0);
bufferedImage = new BufferedImage (
bufferedImage.getWidth()/2, ...Read now
Unlock full access