-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateQRCode.java
More file actions
69 lines (55 loc) · 1.83 KB
/
GenerateQRCode.java
File metadata and controls
69 lines (55 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package sharefiles;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import javax.swing.filechooser.FileSystemView;
public class GenerateQRCode {
String str, path;
int height, width;
String charset = "UTF-8";
public GenerateQRCode(String text, int height, int width) {
this.str = text;
this.path = FileSystemView.getFileSystemView().getHomeDirectory() + "/Quote.png";
this.height = height;
this.width = width;
}
public boolean generateQRcode() throws WriterException, IOException {
Map<EncodeHintType, ErrorCorrectionLevel> hashMap = new HashMap<>();
hashMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
BitMatrix matrix = new MultiFormatWriter().encode(new String(str.getBytes(charset), charset), BarcodeFormat.QR_CODE, width, height);
MatrixToImageWriter.writeToFile(matrix, path.substring(path.lastIndexOf('.') + 1), new File(path));
return matrix != null;
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
}