QRCodeImageBuilder.java
2.01 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.pmp.qrcodepmp;
import com.adobe.xfa.pmp.qrcodepmp.QRCodeEncoderErrorCode;
import com.adobe.xfa.pmp.qrcodepmp.QRCodeEncoderException;
import com.adobe.xfa.pmp.qrcodepmp.denso.QRC;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
class QRCodeImageBuilder {
private QRC qrc;
QRCodeImageBuilder() {
}
BufferedImage buildImage(int imageCols, int imageRows, int xDimension) throws QRCodeEncoderException {
if (imageCols <= 0) {
imageCols = (this.qrc.Csize + 8) * xDimension;
}
if (imageRows <= 0) {
imageRows = (this.qrc.Csize + 8) * xDimension;
}
int colOffset = (imageCols - this.qrc.Csize * xDimension) / 2;
int rowOffset = (imageRows - this.qrc.Csize * xDimension) / 2;
if (colOffset < 4 * xDimension || rowOffset < 4 * xDimension) {
throw new QRCodeEncoderException(QRCodeEncoderErrorCode.IMAGE_TOO_SMALL);
}
BufferedImage image = new BufferedImage(imageCols, imageRows, 10);
Graphics2D graphicsBarcodeImage = image.createGraphics();
graphicsBarcodeImage.setColor(Color.WHITE);
graphicsBarcodeImage.fillRect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
graphicsBarcodeImage.clipRect(0, 0, imageCols - colOffset, imageRows - rowOffset);
Color color = Color.BLACK;
int i = 0;
int row = rowOffset;
while (i < this.qrc.Csize) {
int j = 0;
int col = colOffset;
while (j < this.qrc.Csize) {
color = this.qrc.mtstcell(j, i) != 0 ? Color.BLACK : Color.WHITE;
graphicsBarcodeImage.setColor(color);
graphicsBarcodeImage.fillRect(col, row, col + xDimension, row + xDimension);
++j;
col += xDimension;
}
++i;
row += xDimension;
}
return image;
}
public void setQrc(QRC qrc) {
this.qrc = qrc;
}
}