Java Reference
In-Depth Information
that we have an image loaded, displaying a status message, repainting the frame), whereas
the darker method in OFImage includes the actual work of making each pixel in the im-
age a bit darker.
Code 11.7
The filter method
in the ImageViewer
class
public class ImageViewer
{
// Fields, constructors and all other methods omitted.
/**
* 'Darker' function: make the picture darker.
*/
private void makeDarker()
{
if (currentImage != null ) {
currentImage.darker();
frame.repaint();
showStatus( "Applied: darker" );
}
else {
showStatus( "No image loaded." );
}
}
}
Code 11.8
Implementation of a
filter in the OFImage
class
public class OFImage extends BufferedImage
{
// Fields, constructors and all other methods omitted.
/**
* Make this image a bit darker.
*/
public void darker()
{
int height = getHeight();
int width = getWidth();
for ( int y = 0; y < height; y++) {
for ( int x = 0; x < width; x++) {
setPixel(x, y, getPixel(x, y).darker());
}
}
}
}
 
Search WWH ::




Custom Search