QR code generation image

Source: Internet
Author: User

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; }

QR code generation image

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.