Image Processing

Both Java 1.0 and 1.1 included a complex API for filtering images on the fly as they were downloaded over a network connection. Although this API is still available in later versions of Java, it is not commonly used, nor is it demonstrated in this book. Java 2D defines a simpler API based on the BufferedImageOp interface of the java.awt.image package. This package also includes several versatile implementations of the interface that can generate the image-processing effects illustrated in Figure 12-11. Example 12-13 shows the code used to produce Figure 12-11. The code is straightforward: to process a BufferedImage, simply pass it to the filter( ) method of a BufferedImageOp.

Image processing with BufferedImageOp

Figure 12-11. Image processing with BufferedImageOp

Example 12-13. ImageOps.java

package je3.graphics; import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import java.awt.color.*; /** A demonstration of various image processing filters */ public class ImageOps implements GraphicsExample { static final int WIDTH = 600, HEIGHT = 675; // Size of our example public String getName( ) {return "Image Processing";}// From GraphicsExample public int getWidth( ) { return WIDTH; } // From GraphicsExample public int getHeight( ) { return HEIGHT; } // From GraphicsExample Image image; /** This constructor loads the image we will manipulate */ public ImageOps( ) { java.net.URL imageurl = this.getClass( ...

Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.