import java.awt.List;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class PicEcryption {
public static void main(String[] args) throws IOException {
new Showpic();
BufferedInputStream bis=new BufferedInputStream(new FileInputStream("IMG.jpg"));
ArrayList<Integer> list =new ArrayList<Integer>();//定义集合<字节>用来存储数据
int len; //定义变量,用来存储数据
while((len=bis.read()) !=-1) //循环读取,直到读取到末尾为止
list.add(len+1);//从文件中逐个字节读取数据,异或密码,存入集合
bis.close(); //关闭输入流
BufferedOutputStream bos =new BufferedOutputStream(new FileOutputStream("IMG.jpg"));
for(Integer i:list)//遍历集合,将所有数据写回文件
bos.write(i);
bos.close(); //关闭输出流
new Showpic();
}
}
class Showpic extends JFrame{
private static final long serialVersionUID = 1L;
JPanel jpa = new JPanel();
JLabel jla = new JLabel();
public Showpic(){
ImageIcon image = new ImageIcon("IMG.jpg");
jla.setIcon(image);
jpa.add(jla);
this.add(jpa);
this.setSize(400,300);
this.setVisible(true);
}
}
小白笔记------图片加密
最新推荐文章于 2024-06-28 11:02:43 发布