圖像像素基本操作——自然系列濾鏡
主要代碼如下:
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...");
}
}}
}
測試代碼同上
圖像像素基本操作——自然系列濾鏡