突发奇想想给JAVA编些滤镜方法......就是类似PHOTOSHOP那种的,一个静态方法就能返回个滤镜处理过的bufferedImage,而且,还想要JAVA自带里没有的……
做了下实验,想实现个水波扭曲效果,结果扭曲是出来了,就是色彩全乱了
那个……有人知道WHY么?
(以下附原代码和图片,效果图……代码没注释,想一起研究的密……我可以给你讲
)
import java.awt.*;
import java.lang.*;
import java.io.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import javax.imageio.*;
import javax.swing.event.*;
public class water{
public static void main(String[] args){
JFrame frame=new waterFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class waterFrame extends JFrame{
public waterFrame(){
setSize(330,200);
gra p=new gra();
add(p);
}
}
class gra extends JPanel{
public gra(){
try{
pic1=ImageIO.read(new File("eevvaa.jpg"));
}catch(IOException e){
e.printStackTrace();
}
pic2=change(pic1);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
g.drawImage(pic1,0,0,null);
g.drawImage(pic2,165,0,null);
}
public BufferedImage change(BufferedImage pic){
Raster raster=pic.getRaster();
int x,y,t;
BufferedImage Gpic=new BufferedImage(165,165,BufferedImage.TYPE_BYTE_INDEXED);
WritableRaster GRaster=Gpic.getRaster();
for(x=0,y=0;y<165;x++){
t=y+(int)((Math.sin((double)x/4))*4);
if(t>=0&&t<=163)GRaster.setDataElements(x,y,raster.getDataElements(x,t,null));
if(x>=164){x=0;y++;}
}
return Gpic;
}
private BufferedImage pic1;
private BufferedImage pic2;
}