The Blue Filter Example

To use the blue image filter, you create a FilteredImageSource object.

For example,

Image src = getImage(getDocumentBase(), filename);
picture = createImage(new FilteredImageSource(src.getSource(), 
 new BlueFilter()));
The getSource() method returns a reference to the ImageProducer which produced this Image.

Here's a simple applet that loads an image specified in a PARAM tag, and uses the blue filter on it.

Note: Netscape 3.0.1 for the Mac and possibly other versions has trouble with this applet.


import java.awt.*;
import java.awt.image.*;
import java.applet.*;


public class BlueImage extends Applet {

  private Image picture;

  public void init() {
  
    String filename = this.getParameter("imagefile");
    if (filename != null) {
      Image src = this.getImage(getDocumentBase(), filename);
      this.picture =  this.createImage(
       new FilteredImageSource(src.getSource(), new BlueFilter()));
    }
  
  }
  
  public void paint (Graphics g) {
   
    if (this.picture != null) {
      g.drawImage(this.picture, 0, 0, this);
    }
    else {
      g.drawString("Missing Picture", 20, 20);
    }
    
  }

}

Previous | Next | Top
Last Modified March 16, 2000
Copyright 1997, 1998, 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu