@@ -53,8 +53,7 @@ public static void encode(String content, int width, int height, String fileType
53
53
54
54
Writer writer = new QRCodeWriter ();
55
55
BitMatrix matrix = writer .encode (data , QR_CODE , width , height );
56
- File file = new File (savePath );
57
- MatrixToImageWriter .writeToFile (matrix , fileType , file );
56
+ MatrixToImageWriter .writeToPath (matrix , fileType , Paths .get (savePath ));
58
57
}
59
58
60
59
@@ -68,10 +67,22 @@ public static void encode(String content, int width, int height, String fileType
68
67
* @param fileType 文件类型,如png
69
68
* @param savePath 保存路径
70
69
*/
71
- public static void encodeLogo (String content , int width , int height , String logoPath , String fileType , String savePath ) throws IOException {
72
- BitMatrix matrix = MatrixToImageWriterEx .createQRCode (content , width , height );
73
- MatrixToLogoImageConfig logoConfig = new MatrixToLogoImageConfig (Color .BLUE , 4 );
70
+ public static void encodeLogo (String content , int width , int height , String logoPath , String fileType , String savePath ) throws IOException , WriterException {
71
+ Charset charset = Charset .forName ("UTF-8" );
72
+ CharsetEncoder encoder = charset .newEncoder ();
73
+
74
+ byte [] b = encoder .encode (CharBuffer .wrap (content )).array ();
75
+ String data = new String (b , "iso8859-1" );
76
+
77
+ Writer writer = new QRCodeWriter ();
78
+ BitMatrix matrix = writer .encode (data , QR_CODE , width , height );
79
+ MatrixToLogoImageConfig logoConfig = new MatrixToLogoImageConfig (Color .BLACK , 10 );
74
80
MatrixToImageWriterEx .writeToFile (matrix , fileType , savePath , logoPath , logoConfig );
81
+
82
+
83
+ // BitMatrix matrix = MatrixToImageWriterEx.createQRCode(content, width, height);
84
+ // MatrixToLogoImageConfig logoConfig = new MatrixToLogoImageConfig(Color.BLUE, 4);
85
+ // MatrixToImageWriterEx.writeToFile(matrix, fileType, savePath, logoPath, logoConfig);
75
86
}
76
87
77
88
/**
0 commit comments