| | |
| | | package com.yami.trading.service.user.impl; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | int width = 260; |
| | | int height = 260; |
| | | String format = "png"; |
| | | Map hints = new HashMap(); |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); |
| | | try { |
| | | BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | writeQrImageToFile(bitMatrix, format, file); |
| | | } catch (Exception e) { |
| | | log.error("write to image error:", e); |
| | | } |
| | |
| | | int width = 260; |
| | | int height = 260; |
| | | String format = "png"; |
| | | Map hints = new HashMap(); |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); |
| | | try { |
| | | BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | writeQrImageToFile(bitMatrix, format, file); |
| | | } catch (Exception e) { |
| | | log.error("write to image error:", e); |
| | | } |
| | |
| | | int width = 185; |
| | | int height = 185; |
| | | String format = "png"; |
| | | Map hints = new HashMap(); |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); |
| | | hints.put(EncodeHintType.MARGIN, 1);// 二维码空白区域,最小为0也有白边,只是很小,最小是6像素左右 |
| | | |
| | | try { |
| | | BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | writeQrImageToFile(bitMatrix, format, file); |
| | | } catch (Exception e) { |
| | | log.error("write to image error:", e); |
| | | } |
| | |
| | | public String generateWithdraw(String content, String address) { |
| | | String image_name = "/qr/" + content + ".png"; |
| | | String filepath = Constants.IMAGES_DIR + image_name; |
| | | File file=new File( Constants.IMAGES_DIR); |
| | | if (!file.isDirectory()){ |
| | | file.mkdirs(); |
| | | } |
| | | file = new File(filepath); |
| | | File file = new File(filepath); |
| | | int width = 260; |
| | | int height = 260; |
| | | String format = "png"; |
| | | Map hints = new HashMap(); |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); |
| | | try { |
| | | BitMatrix bitMatrix = new MultiFormatWriter().encode(address, BarcodeFormat.QR_CODE, width, height, hints); |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | writeQrImageToFile(bitMatrix, format, file); |
| | | } catch (Exception e) { |
| | | log.error("write to image error:", e); |
| | | } |
| | |
| | | |
| | | return list_image; |
| | | } |
| | | |
| | | private void writeQrImageToFile(BitMatrix bitMatrix, String format, File file) throws IOException { |
| | | if (bitMatrix == null) { |
| | | throw new IOException("bitMatrix is null"); |
| | | } |
| | | if (file == null) { |
| | | throw new IOException("target file is null"); |
| | | } |
| | | File parent = file.getParentFile(); |
| | | if (parent != null && !parent.exists() && !parent.mkdirs()) { |
| | | throw new IOException("failed to create qr image directory: " + parent.getAbsolutePath()); |
| | | } |
| | | MatrixToImageWriter.writeToFile(bitMatrix, format, file); |
| | | } |
| | | } |