import java.applet.*;
import java.awt.*;
import java.awt.image.*;
public class ReplicateScaleFilterTestApplet extends Applet
{
Image img = null ;
Image img2 = null ;
public void init()
{
MediaTracker mt = new MediaTracker(this) ;
try {
img = Toolkit.getDefaultToolkit().getImage("poor.gif") ;
mt.addImage(img, 0) ;
mt.waitForID(0) ;
}
catch (Exception e) {
e.printStackTrace() ;
}
int imgWidth = img.getWidth(this) ;
int imgHeight = img.getHeight(this) ;
// 给出新的图象大小,以下定义为原始图象的两倍
ImageFilter imgFilter = new ReplicateScaleFilter( imgWidth * 2, imgHeight * 2) ;
// 通过过滤器类产生ImageSource图象生产者
FilteredImageSource fImgSource = new FilteredImageSource(img.getSource(), imgFilter) ;
// 创建新的图象
img2 = this.createImage(fImgSource) ;
}
public void paint(Graphics g)
{
g.drawImage(img, 0, 0, this) ;
g.drawImage(img2, img.getWidth(this), 0, this) ;
}
}