FileDocCategorySizeDatePackage
ImageOps.javaAPI DocExample5390Sat Jan 24 10:44:36 GMT 2004je3.graphics

ImageOps

public class ImageOps extends Object implements GraphicsExample
A demonstration of various image processing filters

Fields Summary
static final int
WIDTH
static final int
HEIGHT
Image
image
static byte[]
brightenTable
static byte[]
thresholdTable
static AffineTransform
mirrorTransform
static String[]
filterNames
static BufferedImageOp[]
filters
Constructors Summary
public ImageOps()
This constructor loads the image we will manipulate

	java.net.URL imageurl = this.getClass().getResource("cover.gif");
	image = new javax.swing.ImageIcon(imageurl).getImage();
    
Methods Summary
public voiddraw(java.awt.Graphics2D g, java.awt.Component c)
Draw the example


        
          
	// Create a BufferedImage big enough to hold the Image loaded
	// in the constructor.  Then copy that image into the new
	// BufferedImage object so that we can process it.
	BufferedImage bimage = new BufferedImage(image.getWidth(c),
						 image.getHeight(c),
						 BufferedImage.TYPE_INT_RGB);
	Graphics2D ig = bimage.createGraphics();
	ig.drawImage(image, 0, 0, c);  // copy the image

	// Set some default graphics attributes
	g.setFont(new Font("SansSerif", Font.BOLD, 12));  // 12pt bold text
	g.setColor(Color.green);                          // Draw in green
	g.translate(10, 10);                              // Set some margins

	// Loop through the filters
	for(int i = 0; i < filters.length; i++) {
	    // If the filter is null, draw the original image, otherwise,
	    // draw the image as processed by the filter
	    if (filters[i] == null) g.drawImage(bimage, 0, 0, c);
	    else g.drawImage(filters[i].filter(bimage, null), 0, 0, c);
	    g.drawString(filterNames[i], 0, 205);      // Label the image
	    g.translate(137, 0);                       // Move over
	    if (i % 4 == 3) g.translate(-137*4, 215);  // Move down after 4
	}
    
public intgetHeight()

 return HEIGHT; 
public java.lang.StringgetName()

         // Size of our example
       return "Image Processing";
public intgetWidth()

 return WIDTH;