50,503
社区成员
发帖
与我相关
我的任务
分享
public void fibonacciyDncode(String filePath){
int iw;
int ih;
int R = 0;
int G = 0;
int B = 0;
int yR=0;
int yG=0;
int yB=0;
int RGB = 0;
//int RGB1=0;
int x,y,z;
x = 7;y = 33;//初始值(密钥)
try {
BufferedImage bi = ImageIO.read(new File(filePath));//读取图片
iw = bi.getWidth();
ih = bi.getHeight();
BufferedImage bi1 = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
for(int j = 0;j < ih ;j++){
for(int i = 0;i < iw ;i++){
z = ( x + y ) % 255;//Fibobacciy变换
x = y;
y = z;
//RGB1 = bi.getRGB(i, j);
Object data = bi.getRaster().getDataElements(i, j, null);//获取该点像素,并以object类型表示
R = bi.getColorModel().getRed(data);
G = bi.getColorModel().getGreen(data);
B = bi.getColorModel().getBlue(data);
yR = z^R;
yG = z^G;
yB = z^B;
RGB = (yR*256+yG)*256+yB;//R、G、B三个分量转换为RGB
if(RGB>8388608)RGB-=16777216;
bi1.setRGB(i, j, RGB);
}
}
ImageIO.write(bi1, "jpg", new File("E://dncode.jpg"));
} catch (Exception e) {
}
}
public void testWrite(String filePath){
try {
BufferedImage bi = ImageIO.read(new File(filePath));
ImageIO.write(bi, "jpg", new File("E://test1.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}