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; }
时间: 2024-11-02 15:25:42