DataMatrixImageBuilder.java
2.2 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.pmp.datamatrixpmp;
import com.adobe.xfa.pmp.datamatrixpmp.DataMatrixEncoderErrorCode;
import com.adobe.xfa.pmp.datamatrixpmp.DataMatrixEncoderException;
import com.adobe.xfa.pmp.datamatrixpmp.DataMatrixMatrix;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
class DataMatrixImageBuilder {
DataMatrixImageBuilder() {
}
private static Color getColor(int color) {
if (color == 0) {
return Color.BLACK;
}
return Color.WHITE;
}
static BufferedImage buildImage(DataMatrixMatrix matrix, int imageCols, int imageRows, int xDimension) throws DataMatrixEncoderException {
int cols = matrix.getCols();
int rows = matrix.getRows();
if (imageCols <= 0) {
imageCols = (cols + 2) * xDimension;
}
if (imageRows <= 0) {
imageRows = (rows + 2) * xDimension;
}
int colOffset = (imageCols - cols * xDimension) / 2;
int rowOffset = (imageRows - rows * xDimension) / 2;
if (colOffset < xDimension || rowOffset < xDimension) {
throw new DataMatrixEncoderException(DataMatrixEncoderErrorCode.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);
int color = 0;
int i = 0;
int imageRow = rowOffset;
while (i < rows) {
int j = 0;
int imageCol = colOffset;
while (j < cols) {
color = matrix.get(j, i) != 0 ? 0 : 255;
graphicsBarcodeImage.setColor(DataMatrixImageBuilder.getColor(color));
graphicsBarcodeImage.fillRect(imageCol, imageRow, imageCol + xDimension, imageRow + xDimension);
++j;
imageCol += xDimension;
}
++i;
imageRow += xDimension;
}
return image;
}
}