java改写

csdn_zpc 2016-04-18 07:11:03
public void actionPerformed(ActionEvent evt)
{
Graphics graph = getGraphics();

if (evt.getSource() == openItem)
{
//文件选择对话框
JFileChooser chooser = new JFileChooser();
common.chooseFile(chooser, "D:/testphotos", 0);//设置默认目录,过滤文件
int r = chooser.showOpenDialog(null);

MediaTracker tracker = new MediaTracker(this);

if(r == JFileChooser.APPROVE_OPTION)
{
//路径与文件全名
String name = chooser.getSelectedFile().getAbsolutePath();

//取文件名及其长度
String fname = chooser.getSelectedFile().getName();
int len = fname.length();

//取出文件名imn和加密标识imh
imn = fname.substring(0, len-4);
imh = fname.substring(0, 2);

if(runflag)
{
loadflag = false;
runflag = false;
}

if(!loadflag)
{
//装载图像
iImage = common.openImage(name, tracker);
//取载入图像的宽和高
iw = iImage.getWidth(null);
ih = iImage.getHeight(null);
repaint();
loadflag = true;
}
}
}
else if (evt.getSource() == arnoldItem)
{
if(loadflag)
{
setTitle("毕业设计加密算法");
if(iw != ih)
{
JOptionPane.showMessageDialog(null, "仅适用于宽高相等图像!");
loadflag = false;
return;
}
pixels = common.grabber(iImage, iw, ih);

//设定密钥
int key = common.getParam("输入密钥(000000-999999)","123456");
pixels = cipher.arnold_mtr(pixels, iw, key, 1);
oImage = showPix(graph, pixels, "加密图像");
//存储JPEG图像
File file = new File("D:/testphotos/c_"+imn+".jpg");
bImage = (BufferedImage)this.createImage(iw, ih);
bImage.createGraphics().drawImage(oImage, 0, 0, this);
common.saveImageAsJPEG(bImage, file);
JOptionPane.showMessageDialog(null, "在目录D:/testphotos\n"
+"c_"+imn+".jpg加密图像成功!");
}
}
else if (evt.getSource() == iarnoldItem)
{
if(loadflag)
{
if(!imh.equals("c_")) //未受JPEG攻击
{
cphpix = pixels;
//设定密钥
int key = common.getParam("输入密钥(000000-99999)","123456");
pixels = cipher.arnold_mtr(cphpix, iw, key, -1);
showPix(graph, pixels, "解密图像");
}
else //受JPEG攻击
{
cphpix = common.grabber(iImage, iw, ih);
//设定密钥
int key = common.getParam("输入密钥(000000-999999)","123456");
pixels = cipher.arnold_mtr(cphpix, iw, key, -1);
showPix(graph, pixels, "解密攻击图");
}
}
else
JOptionPane.showMessageDialog(null, "请先打开图像!");
}
}
怎么将打开一张图片进行arnold变换 更改为从键盘输入一个矩阵然后调用cipher.arnold_mtr(pixels, iw, key, 1);这一部分实现矩阵的变换,然后输出一个矩阵
!!感谢!!
...全文
59 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧