Skip to content

Commit

Permalink
优化代码,增加应用icon
Browse files Browse the repository at this point in the history
  • Loading branch information
iminto committed Sep 11, 2019
1 parent 203c0b9 commit 0c75d59
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 33 deletions.
53 changes: 29 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
图片隐写,将要隐藏的文字写入图片中,理论上最大可支持几十M文本。
原理比较简单,可见代码注释。

经过处理的图片和原图在肉眼上几乎没有区别,并且在体积上不会造成明显膨胀。
(处理后的体积可能略微膨胀,甚至会变小)

运行方式
```
java -jar hideImage-1.0-SNAPSHOT.jar
```
原图:

![原图][1]

处理后图片:

![处理后图片][2]

隐藏文字:组织上已经决定了,今天的垃圾都归你
------

[1]: ./static/yaofan.png
[2]: ./static/yaofan_hide.png

图片隐写,将要隐藏的文字写入图片中,理论上最大可支持几十M文本。
原理比较简单,可见代码注释。

经过处理的图片和原图在肉眼上几乎没有区别,并且在体积上不会造成明显膨胀。
(处理后的体积可能略微膨胀,甚至会变小)

运行方式
```
java -jar -Dfile.encoding=UTF-8 target/hideImage-1.0-SNAPSHOT.jar
```
APP截图:

![APP截图][3]

原图:

![原图][1]

处理后图片:

![处理后图片][2]

隐藏文字:组织上已经决定了,今天的垃圾都归你
------

[1]: ./static/yaofan.png
[2]: ./static/yaofan_hide.png
[3]: ./static/hide.png

3 changes: 3 additions & 0 deletions src/main/java/tony/AboutFrame.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tony;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class AboutFrame extends javax.swing.JFrame {
Expand Down Expand Up @@ -49,6 +50,8 @@ public void run() {
aboutFrame.setVisible(true);
aboutFrame.setTitle("关于");
aboutFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
ImageIcon icon = new ImageIcon("static/icon.png");
aboutFrame.setIconImage(icon.getImage());
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tony/HiJFrame.form
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="&#x6587;&#x672c;&#x5149;&#x6807;"/>
<Color id="&#x9ed8;&#x8ba4;&#x5149;&#x6807;"/>
</Property>
<Property name="iconImages" type="java.util.List" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="null"/>
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/tony/HiJFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
public class HiJFrame extends javax.swing.JFrame {

private String imagePath;
private ImageHide rc;

public HiJFrame() {
initComponents();
rc = new ImageHide();
}

@SuppressWarnings("unchecked")
Expand All @@ -40,7 +42,7 @@ private void initComponents() {
aboutMenuItem = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setIconImages(null);

hideText.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
Expand Down Expand Up @@ -181,9 +183,15 @@ private void imgOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
if (returnVal == pngChooser.APPROVE_OPTION) {
File file = pngChooser.getSelectedFile();
imagePath = file.getPath();
imgShowLabel.setIcon(new ImageIcon(file.getPath()));
long size = file.length();
statusLabel.setText("图片大小:" + size);
try {
rc.addPng(imagePath);
imgShowLabel.setIcon(new ImageIcon(file.getPath()));
long size = file.length();
int enable=rc.getEnabled();
statusLabel.setText("图片大小:" + size+",可隐写字节数:"+enable+"(1中文=3字节)");
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage(), "错误 ", 0);
}
}
}//GEN-LAST:event_imgOpenActionPerformed

Expand All @@ -199,9 +207,7 @@ private void hideBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
if (!ImageUtil.isNotEmpty(hideText.getText()) || !ImageUtil.isNotEmpty(imagePath)) {
JOptionPane.showMessageDialog(this, "图片和文字不可为空!", "错误 ", 0);
} else {
ImageHide rc = new ImageHide();
try {
rc.addPng(imagePath);
rc.addText(hideText.getText());
rc.Hide();
JOptionPane.showMessageDialog(this, "隐写图片已生成至原目录中!", "成功 ", 1);
Expand All @@ -215,7 +221,6 @@ private void recBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:
if (!ImageUtil.isNotEmpty(imagePath)) {
JOptionPane.showMessageDialog(this, "要提取的图片不可为空!", "错误 ", 0);
} else {
ImageHide rc = new ImageHide();
try {
String extractStr = rc.ImageExtract(imagePath);
hideText.setText(extractStr);
Expand All @@ -231,9 +236,11 @@ public static void main(String args[]) {
public void run() {
HiJFrame jframe = new HiJFrame();
jframe.setVisible(true);
jframe.setTitle("Hide Image");
jframe.setTitle("图片隐写助手");
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setLocationRelativeTo(null);
ImageIcon icon = new ImageIcon("static/icon.png");
jframe.setIconImage(icon.getImage());
}
});
}
Expand Down
Binary file added static/hide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0c75d59

Please sign in to comment.