主要代码如下:
package chapter5;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
/**
Created by LENOVO on 18-1-30.
*/
public class LvJingFilter extends AbstractBufferedImageOp {
int[] fogLookUp = new int[257];//雾化风格颜色查找表
int[] rainbowLookup ;
public LvJingFilter(){}
public BufferedImage filter(BufferedImage src,BufferedImage dest){
int width = src.getWidth();
int height = src.getHeight();
if(dest == null){
dest = creatCompatibleDestImage(src,null);
}
int inpixels[] = new int[width*height];
int outpixels[] = new int[width*height];
getRGB(src,0,0,width,height,inpixels);
int index = 0;
for(int row=0;row<height;row++){
int ta = 0,tr = 0,tg = 0,tb = 0;
for(int col=0;colreturn dest;
}
//雾风格颜色查找表//40,41,42,.....127,127,127,....127,128,129,...,255
public void buildFogLookupTable(){
//颜色查找表
int fogLimit = 40;
for(int i=0; i}
}
//彩虹风格颜色查找表
public void buildRainBowLookupTable(){
java.net.URL imageURL = this.getClass().getResource("rainbow.jpg");
if(imageURL !=null){
try {
BufferedImage image = ImageIO.read(imageURL);
int width = image.getWidth();
int height = image.getHeight();
rainbowLookup = new int[width];
int[] inPixels = new int[width*height];
getRGB(image,0,0,width,height,inPixels);
for(int col=0;col<width;col++){
rainbowLookup[col] = inPixels[col];
}
} catch (IOException e) {
// e.printStackTrace();
System.out.println("An error occured when loading the image icon...");
}
}}
}
测试代码同上