admin
2020-02-28 1d9eef9a4ba7caebf73b483e0062f9259dbf22a0
Merge remote-tracking branch 'origin/div' into div
3个文件已修改
90 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/service/impl/user/QrCodeServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/src/main/java/org/yeshi/utils/QRCodeUtil.java 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/QrCodeServiceImpl.java
@@ -290,7 +290,7 @@
        // 二维码流
        InputStream erCodeStream = null;
        try {
            erCodeStream = QRCodeUtil.getInstance(250).encode(erCodeUrl);
            erCodeStream = QRCodeUtil.getInstance(250).encodeDeleteWhite(erCodeUrl);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
@@ -421,9 +421,9 @@
            g2d.drawImage(ImageIO.read(codeFrame), spacing + 405, y + 200, 200, 203, null);
            
            // 画二维码
            int codeSize = 190;
            int pX =  spacing + 411;
            int pY =  y + 207;
            int codeSize = 170;
            int pX =  spacing + 422;
            int pY =  y + 217;
            g2d.drawImage(ImageIO.read(qrcode), pX, pY, codeSize, codeSize, null);
            int portraitSize = 200 * 5 / 23;
utils/src/main/java/org/yeshi/utils/QRCodeUtil.java
@@ -88,6 +88,50 @@
        hints.put(EncodeHintType.MARGIN, 1);
        BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE,
                hints);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
            }
        }
        if (logoImg == null) {
            return image;
        }
        // 插入图片
        insertImage(image, logoImg, needCompress);
        return image;
    }
    /**
     * user: Rex date: 2016年12月29日 上午12:31:29
     *
     * @param content
     *            二维码内容
     * @param logoImgPath
     *            Logo
     * @param needCompress
     *            是否压缩Logo
     * @return 返回二维码图片
     * @throws WriterException
     * @throws IOException
     *             BufferedImage TODO 创建二维码图片
     */
    private BufferedImage createImageDeleteWhite(String content, InputStream logoImg, boolean needCompress)
            throws WriterException, IOException {
        Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
        hints.put(EncodeHintType.MARGIN, 1);
        BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE,
                hints);
        //调用去除白边方法
        bitMatrix = deleteWhite(bitMatrix);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
@@ -188,6 +232,14 @@
        return new ByteArrayInputStream(out.toByteArray());
    }
    public InputStream encodeDeleteWhite(String content) throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        encodeDeleteWhite(content, null, out, false);
        return new ByteArrayInputStream(out.toByteArray());
    }
    /**
     * user: Rex date: 2016年12月29日 上午12:36:58
     * 
@@ -220,6 +272,21 @@
    public void encode(String content, InputStream logoImg, ByteArrayOutputStream output, boolean needCompress)
            throws Exception {
        BufferedImage image = createImage(content, logoImg, needCompress);
        ImageIO.write(image, FORMAT_NAME, output);
    }
    /**
     *
     * @param content
     * @param logoImg
     * @param output
     *            二进制输出流
     * @param needCompress
     * @throws Exception
     */
    public void encodeDeleteWhite(String content, InputStream logoImg, ByteArrayOutputStream output, boolean needCompress)
            throws Exception {
        BufferedImage image = createImageDeleteWhite(content, logoImg, needCompress);
        ImageIO.write(image, FORMAT_NAME, output);
    }
@@ -275,4 +342,19 @@
        return decode(new File(path));
    }
     private static BitMatrix deleteWhite(BitMatrix matrix) {
        int[] rec = matrix.getEnclosingRectangle();
        int resWidth = rec[2] + 1;
        int resHeight = rec[3] + 1;
        BitMatrix resMatrix = new BitMatrix(resWidth, resHeight);
        resMatrix.clear();
        for (int i = 0; i < resWidth; i++) {
            for (int j = 0; j < resHeight; j++) {
                if (matrix.get(i + rec[0], j + rec[1]))
                    resMatrix.set(i, j);
            }
        }
        return resMatrix;
    }
}