|
@@ -1,31 +1,33 @@
|
|
|
package cn.hnthyy.thmz.Utils;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.io.resource.ClassPathResource;
|
|
|
+import cn.hutool.core.io.resource.ResourceUtil;
|
|
|
+import com.sun.image.codec.jpeg.JPEGCodec;
|
|
|
+import com.sun.image.codec.jpeg.JPEGEncodeParam;
|
|
|
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
|
|
|
+import sun.misc.BASE64Decoder;
|
|
|
+
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import javax.imageio.stream.FileImageInputStream;
|
|
|
+import javax.swing.*;
|
|
|
import java.awt.*;
|
|
|
import java.awt.font.TextAttribute;
|
|
|
-import java.awt.image.*;
|
|
|
-import java.io.*;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URL;
|
|
|
import java.text.AttributedCharacterIterator;
|
|
|
import java.text.AttributedString;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Scanner;
|
|
|
-
|
|
|
-import javax.imageio.ImageIO;
|
|
|
-import javax.imageio.stream.FileImageInputStream;
|
|
|
-import javax.imageio.stream.FileImageOutputStream;
|
|
|
-import javax.swing.ImageIcon;
|
|
|
-
|
|
|
-import org.apache.commons.codec.binary.Base64;
|
|
|
-import org.springframework.util.ResourceUtils;
|
|
|
-import sun.misc.BASE64Decoder;
|
|
|
-import sun.misc.BASE64Encoder;
|
|
|
-
|
|
|
-import com.sun.image.codec.jpeg.JPEGCodec;
|
|
|
-import com.sun.image.codec.jpeg.JPEGEncodeParam;
|
|
|
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
|
|
|
|
|
|
public class WindowsUtil {
|
|
|
|
|
@@ -39,7 +41,7 @@ public class WindowsUtil {
|
|
|
* @author zhongweihai newwei2001@yahoo.com.cn
|
|
|
*/
|
|
|
public boolean createMark(String filePath, String outFile,
|
|
|
- List<Map<String, Object>> list, Boolean needPic) throws IOException {
|
|
|
+ List<Map<String, Object>> list, Boolean needPic,String rootFilePath) throws IOException {
|
|
|
ImageIcon imgIcon = new ImageIcon(filePath);
|
|
|
Image theImg = imgIcon.getImage();
|
|
|
int width = theImg.getWidth(null);
|
|
@@ -52,7 +54,7 @@ public class WindowsUtil {
|
|
|
add(g, bimage, list.get(i));
|
|
|
}
|
|
|
if (needPic) {
|
|
|
- BufferedImage content = ImageIO.read(new File(ResourceUtils.getFile("classpath:images") + "\\tx\\tx1.jpg"));
|
|
|
+ BufferedImage content = ImageIO.read(new File( rootFilePath+ "\\tx\\tx1.jpg"));
|
|
|
// byte[] outImage= makeColorTransparent(content, new Color(254, 254, 254));
|
|
|
g.drawImage(content.getScaledInstance(150, 180, Image.SCALE_DEFAULT), 320, 50, null);
|
|
|
}
|
|
@@ -101,7 +103,7 @@ public class WindowsUtil {
|
|
|
* @param idNum
|
|
|
* @return
|
|
|
*/
|
|
|
- public static boolean generateIdcodeZ(String name, String gender, String nation, String year, String month, String day, String address, String idNum) {
|
|
|
+ public static boolean generateIdcodeZ(String name, String gender, String nation, String year, String month, String day, String address, String idNum,String filePath) {
|
|
|
boolean bool = false;
|
|
|
try {
|
|
|
WindowsUtil wm = new WindowsUtil();
|
|
@@ -196,10 +198,10 @@ public class WindowsUtil {
|
|
|
map.put("fontType", "微软雅黑");
|
|
|
map.put("fontSize", 24);
|
|
|
list.add(map);
|
|
|
- file1 = ResourceUtils.getFile("classpath:images") + "\\sfzzm.jpg";
|
|
|
- String path = ResourceUtils.getFile("classpath:images") + "\\idcode";
|
|
|
+ file1 = filePath + "\\sfzzm.jpg";
|
|
|
+ String path = filePath + "\\idcode";
|
|
|
createDir(path);
|
|
|
- wm.createMark(file1, path + "\\idz.jpg", list, true);
|
|
|
+ wm.createMark(file1, path + "\\idz.jpg", list, true,filePath);
|
|
|
// Thread.sleep(200);
|
|
|
//bool = generateIdcodeF(wm, ResourceUtils.getFile("classpath:images") + "\\idcode\\idf.jpg", "安仁县公安局");
|
|
|
} catch (Exception e) {
|
|
@@ -217,7 +219,7 @@ public class WindowsUtil {
|
|
|
* @param ress
|
|
|
* @return
|
|
|
*/
|
|
|
- public static boolean generateIdcodeF(WindowsUtil wm, String tager, String ress) {
|
|
|
+ public static boolean generateIdcodeF(WindowsUtil wm, String tager, String ress,String filePath) {
|
|
|
boolean bool = false;
|
|
|
try {
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
@@ -238,7 +240,7 @@ public class WindowsUtil {
|
|
|
map.put("fontType", "微软雅黑");
|
|
|
map.put("fontSize", 18);
|
|
|
list.add(map);
|
|
|
- wm.createMark(file2, tager, list, false);
|
|
|
+ wm.createMark(file2, tager, list, false,filePath);
|
|
|
bool = true;
|
|
|
System.out.println("证件反面照【" + tager + "】生成成功");
|
|
|
} catch (Exception e) {
|
|
@@ -308,7 +310,7 @@ public class WindowsUtil {
|
|
|
* 将base64位的头像转为头像
|
|
|
* @param imgStr
|
|
|
*/
|
|
|
- public static void generateImage(String imgStr) {
|
|
|
+ public static void generateImage(String imgStr,String filePath) {
|
|
|
if (imgStr == null) {
|
|
|
return;
|
|
|
} // 图像数据为空
|
|
@@ -323,7 +325,8 @@ public class WindowsUtil {
|
|
|
b[i] += 256;
|
|
|
}
|
|
|
}
|
|
|
- String filePath=ResourceUtils.getFile("classpath:images") + "\\tx";
|
|
|
+ //String filePath=ResourceUtils.getFile("classpath:images") + "\\tx";
|
|
|
+ filePath = filePath+ "\\tx";
|
|
|
createDir(filePath);
|
|
|
out = new FileOutputStream(filePath + "\\tx.jpg");
|
|
|
out.write(b);
|
|
@@ -386,7 +389,4 @@ public class WindowsUtil {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|