public void paint(Graphics g) {
g.drawImage(img,0,0,this);//画出图片
}
}
class myImage extends RGBImageFilter {
int width=0;
int height=0;
public myImage(int width,int height) {
this.canFilterIndexColorModel=true;
this.width=width;
this.height=height;
}
public int filterRGB(int x,int y,int rgb) {
DirectColorModel dcm=(DirectColorModel)ColorModel.getRGBdefault();
int red=dcm.getRed(rgb);
int green=dcm.getGreen(rgb);
int blue=dcm.getBlue(rgb);
int alpha=dcm.getAlpha(rgb);
if(red==255&&green==255&&blue==255)//如果像素为白色,则让它透明,可以自己根据情况处理,如:让red==255就是红色的像素透明
alpha=0;
return alpha<<24|red<<16|green<<8|blue;
}
}