小白笔记------图片加密

本文介绍了一个简单的图片加密程序,该程序使用Java实现,通过读取图片文件并对其进行字节级别的异或操作来加密图片,然后将加密后的图片显示在GUI界面上。程序包括两个主要部分:加密过程和图片展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值