QRコード生成QRコードピクチャ
2540 ワード
public static void toBmp(String str,String transactionID){
BASE64Decoder decoder = new Decoder.BASE64Decoder();
byte[] bytes1;
try {
bytes1 = decoder.decodeBuffer(str);
byte[] datas = ZoomWbmp(bytes1, str.length(), 3);
ByteArrayInputStream bais = new ByteArrayInputStream(datas);
BufferedImage bi1 = ImageIO.read(bais);
String path = AppKeys.UPLOAD_FILE_PATH + File.separator + "tdcode" + File.separator;
File w2 = new File(path +transactionID+".bmp");// jpg,png,gif
ImageIO.write(bi1, "jpg", w2);
} catch (IOException e) {
AppLogger.getInstance().debugLog(" !", e);
}
}
private static byte[] ZoomWbmp(byte[] Wbmp, int len, int multiple) {
byte[] ResultWbmp, RowData, multiplePointData;
byte[] PointData = new byte[8];
int width = 0;
int height = 0;
int step = 0;
int i, j, k, l;
width = (int) Wbmp[2];
height = (int) Wbmp[3];
step = width / 8;
ResultWbmp = new byte[(len - 4) * multiple * multiple + 4];
RowData = new byte[step * multiple];
multiplePointData = new byte[multiple];
ResultWbmp[0] = 0x00;
ResultWbmp[1] = 0x00;
ResultWbmp[2] = (byte) (width * multiple);
ResultWbmp[3] = (byte) (height * multiple);
for (i = 0; i < height; i++) {
for (j = 0; j < step; j++) {
PointData[0] = (byte) ((Wbmp[i * step + j + 4] & 0x80) >> 7);
PointData[1] = (byte) ((Wbmp[i * step + j + 4] & 0x40) >> 6);
PointData[2] = (byte) ((Wbmp[i * step + j + 4] & 0x20) >> 5);
PointData[3] = (byte) ((Wbmp[i * step + j + 4] & 0x10) >> 4);
PointData[4] = (byte) ((Wbmp[i * step + j + 4] & 0x08) >> 3);
PointData[5] = (byte) ((Wbmp[i * step + j + 4] & 0x04) >> 2);
PointData[6] = (byte) ((Wbmp[i * step + j + 4] & 0x02) >> 1);
PointData[7] = (byte) ((Wbmp[i * step + j + 4] & 0x01));
/* multiplePointData */
for (int x = 0; x < multiple; x++) {
multiplePointData[x] = 0;
}
/* */
for (k = 0; k < 8 * multiple; k++) {
multiplePointData[(k - k % 8) / 8] |= ((byte) ((PointData[k
/ multiple]) << ((byte) (7 - (k % 8)))));
}
/* */
for (int x = 0; x < multiple; x++) {
RowData[j * multiple + x] = multiplePointData[x];
}
}
for (l = 0; l < multiple; l++) {
for (int x = 0; x < step * multiple; x++) {
ResultWbmp[4 + (i * multiple + l) * (step * multiple) + x] = RowData[x];
}
}
}
return ResultWbmp;
}