用java生成二维码,直接可用

Java生成二维码的几种实现方式(基于Spring Boot) 本文将基于Spring Boot介绍两种生成二维码的实现方式,一种是基于Google开发工具包,另一种是基于Hutool来实现; 为了方便理解二维码的实际应用场景,举一些例子! (1)进销存系统 想必大家都听说过,其系统中的商品二维码承载了许多重要、核心的关键信息,比如商品编码、商品名称、规格、型号、单位、作用/使用说明等信息;操作者可以借助硬件设备,如“扫码枪”,通过扫描该二维码后将该商品录入到商品库中; (2)再比如溯源系统中的产品,用户可以通过微信等APP中的扫一扫,扫描贴在产品上的二... 阅读详情

一步一步用java设计生成二维码

在物联网的时代,二维码是个很重要的东西了,现在无论什么东西都要搞个二维码标志,唯恐落伍,就差人没有用二维码识别了。也许有一天生分证或者户口本都会用二维码识别了。今天心血来潮,看见别人都为自己的博客添加了二维码,我也想搞一个测试一下.

主要用来实现两点:

1. 生成任意文字的二维码.

2. 在二维码的中间加入图像.

一、准备工作。

准备QR二维码3.0 版本的core包和一张jpg图片。


下载QR二维码包。

首先得下载 zxing.jar 包, 我这里用的是3.0 版本的core包

下载地址: 现在已经迁移到了github: https://github.com/zxing/zxing/wiki/Getting-Started-Developing,

当然你也可以从maven仓库下载jar 包: http://central.maven.org/maven2/com/google/zxing/core/




  二、程序设计

 1、启动eclipse,新建一个Java项目,命好项目名(本例取名为QRCodeSoft)。点下一步:

 
   2、导入zxing.jar 包, 我这里用的是3.0 版本的core包:点“添加外部JAR(X)…”。






   3、新建两个类,分别是:

BufferedImageLuminanceSource.java

QRCodeUtil.java


 

关键代码在于:BufferedImageLuminanceSource.java 和QRCodeUtil.java , 其中测试的main 方法位于QRCodeUtil.java 中。

BufferedImageLuminanceSource.java程序代码:

                                                                                                                                                                                                                   package qrcodesoft;

  1. <span style=“background-color: rgb(255, 255, 255);”>  
  2. import java.awt.Graphics2D;  
  3. import java.awt.geom.AffineTransform;  
  4. import java.awt.image.BufferedImage;  
  5.   
  6. import com.google.zxing.LuminanceSource;  
  7.   
  8. public class BufferedImageLuminanceSource extends LuminanceSource {  
  9.     private final BufferedImage image;  
  10.     private final int left;  
  11.     private final int top;  
  12.   
  13.     public BufferedImageLuminanceSource(BufferedImage image) {  
  14.         this(image, 0, 0, image.getWidth(), image.getHeight());  
  15.     }  
  16.   
  17.     public BufferedImageLuminanceSource(BufferedImage image, int left,  
  18.             int top, int width, int height) {  
  19.         super(width, height);  
  20.   
  21.         int sourceWidth = image.getWidth();  
  22.         int sourceHeight = image.getHeight();  
  23.         if (left + width > sourceWidth || top + height > sourceHeight) {  
  24.             throw new IllegalArgumentException(  
  25.                     ”Crop rectangle does not fit within image data.”);  
  26.         }  
  27.   
  28.         for (int y = top; y < top + height; y++) {  
  29.             for (int x = left; x < left + width; x++) {  
  30.                 if ((image.getRGB(x, y) & 0xFF000000) == 0) {  
  31.                     image.setRGB(x, y, 0xFFFFFFFF); // = white  
  32.                 }  
  33.             }  
  34.         }  
  35.   
  36.         this.image = new BufferedImage(sourceWidth, sourceHeight,  
  37.                 BufferedImage.TYPE_BYTE_GRAY);  
  38.         this.image.getGraphics().drawImage(image, 0, 0, null);  
  39.         this.left = left;  
  40.         this.top = top;  
  41.     }  
  42.   
  43.      
  44.     public byte[] getRow(int y, byte[] row) {  
  45.         if (y < 0 || y >= getHeight()) {  
  46.             throw new IllegalArgumentException(  
  47.                     ”Requested row is outside the image: ” + y);  
  48.         }  
  49.         int width = getWidth();  
  50.         if (row == null || row.length < width) {  
  51.             row = new byte[width];  
  52.         }  
  53.         image.getRaster().getDataElements(left, top + y, width, 1, row);  
  54.         return row;  
  55.     }  
  56.   
  57.      
  58.     public byte[] getMatrix() {  
  59.         int width = getWidth();  
  60.         int height = getHeight();  
  61.         int area = width * height;  
  62.         byte[] matrix = new byte[area];  
  63.         image.getRaster().getDataElements(left, top, width, height, matrix);  
  64.         return matrix;  
  65.     }  
  66.   
  67.      
  68.     public boolean isCropSupported() {  
  69.         return true;  
  70.     }  
  71.   
  72.      
  73.     public LuminanceSource crop(int left, int top, int width, int height) {  
  74.         return new BufferedImageLuminanceSource(image, this.left + left,  
  75.                 this.top + top, width, height);  
  76.     }  
  77.   
  78.      
  79.     public boolean isRotateSupported() {  
  80.         return true;  
  81.     }  
  82.   
  83.      
  84.     public LuminanceSource rotateCounterClockwise() {  
  85.         int sourceWidth = image.getWidth();  
  86.         int sourceHeight = image.getHeight();  
  87.         AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0,  
  88.                 0.0, 0.0, sourceWidth);  
  89.         BufferedImage rotatedImage = new BufferedImage(sourceHeight,  
  90.                 sourceWidth, BufferedImage.TYPE_BYTE_GRAY);  
  91.         Graphics2D g = rotatedImage.createGraphics();  
  92.         g.drawImage(image, transform, null);  
  93.         g.dispose();  
  94.         int width = getWidth();  
  95.         return new BufferedImageLuminanceSource(rotatedImage, top,  
  96.                 sourceWidth - (left + width), getHeight(), width);  
  97.     }  
  98. }</span>  
<span style="background-color: rgb(255, 255, 255);">
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;

import com.google.zxing.LuminanceSource;

public class BufferedImageLuminanceSource extends LuminanceSource {
    private final BufferedImage image;
    private final int left;
    private final int top;

    public BufferedImageLuminanceSource(BufferedImage image) {
        this(image, 0, 0, image.getWidth(), image.getHeight());
    }

    public BufferedImageLuminanceSource(BufferedImage image, int left,
            int top, int width, int height) {
        super(width, height);

        int sourceWidth = image.getWidth();
        int sourceHeight = image.getHeight();
        if (left + width > sourceWidth || top + height > sourceHeight) {
            throw new IllegalArgumentException(
                    "Crop rectangle does not fit within image data.");
        }

        for (int y = top; y < top + height; y++) {
            for (int x = left; x < left + width; x++) {
                if ((image.getRGB(x, y) & 0xFF000000) == 0) {
                    image.setRGB(x, y, 0xFFFFFFFF); // = white
                }
            }
        }

        this.image = new BufferedImage(sourceWidth, sourceHeight,
                BufferedImage.TYPE_BYTE_GRAY);
        this.image.getGraphics().drawImage(image, 0, 0, null);
        this.left = left;
        this.top = top;
    }


    public byte[] getRow(int y, byte[] row) {
        if (y < 0 || y >= getHeight()) {
            throw new IllegalArgumentException(
                    "Requested row is outside the image: " + y);
        }
        int width = getWidth();
        if (row == null || row.length < width) {
            row = new byte[width];
        }
        image.getRaster().getDataElements(left, top + y, width, 1, row);
        return row;
    }


    public byte[] getMatrix() {
        int width = getWidth();
        int height = getHeight();
        int area = width * height;
        byte[] matrix = new byte[area];
        image.getRaster().getDataElements(left, top, width, height, matrix);
        return matrix;
    }


    public boolean isCropSupported() {
        return true;
    }


    public LuminanceSource crop(int left, int top, int width, int height) {
        return new BufferedImageLuminanceSource(image, this.left + left,
                this.top + top, width, height);
    }


    public boolean isRotateSupported() {
        return true;
    }


    public LuminanceSource rotateCounterClockwise() {
        int sourceWidth = image.getWidth();
        int sourceHeight = image.getHeight();
        AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0,
                0.0, 0.0, sourceWidth);
        BufferedImage rotatedImage = new BufferedImage(sourceHeight,
                sourceWidth, BufferedImage.TYPE_BYTE_GRAY);
        Graphics2D g = rotatedImage.createGraphics();
        g.drawImage(image, transform, null);
        g.dispose();
        int width = getWidth();
        return new BufferedImageLuminanceSource(rotatedImage, top,
                sourceWidth - (left + width), getHeight(), width);
    }
}</span>

QRCodeUtil.java的程序代码:

                                                                                                                                                                                                                         

  1. <span style=“background-color: rgb(255, 255, 255);”>package qrcodesoft;  
  2.   
  3.   
  4. import java.awt.BasicStroke;  
  5. import java.awt.Graphics;  
  6. import java.awt.Graphics2D;  
  7. import java.awt.Image;  
  8. import java.awt.Shape;  
  9. import java.awt.geom.RoundRectangle2D;  
  10. import java.awt.image.BufferedImage;  
  11. import java.io.File;  
  12. import java.io.OutputStream;  
  13. import java.util.Hashtable;  
  14. import java.util.Random;  
  15.   
  16. import javax.imageio.ImageIO;  
  17.   
  18. import com.google.zxing.BarcodeFormat;  
  19. import com.google.zxing.BinaryBitmap;  
  20. import com.google.zxing.DecodeHintType;  
  21. import com.google.zxing.EncodeHintType;  
  22. import com.google.zxing.MultiFormatReader;  
  23. import com.google.zxing.MultiFormatWriter;  
  24. import com.google.zxing.Result;  
  25. import com.google.zxing.common.BitMatrix;  
  26. import com.google.zxing.common.HybridBinarizer;  
  27. import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;  
  28.   
  29.   
  30. public class QRCodeUtil {  
  31.   
  32.     private static final String CHARSET = “utf-8”;  
  33.     private static final String FORMAT_NAME = “JPG”;  
  34.     // 二维码尺寸  
  35.     private static final int QRCODE_SIZE = 300;  
  36.     // LOGO宽度  
  37.     private static final int WIDTH = 60;  
  38.     // LOGO高度  
  39.     private static final int HEIGHT = 60;  
  40.   
  41.     private static BufferedImage createImage(String content, String imgPath,  
  42.             boolean needCompress) throws Exception {  
  43.         Hashtable hints = new Hashtable();  
  44.         hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);  
  45.         hints.put(EncodeHintType.CHARACTER_SET, CHARSET);  
  46.         hints.put(EncodeHintType.MARGIN, 1);  
  47.         BitMatrix bitMatrix = new MultiFormatWriter().encode(content,  
  48.                 BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);  
  49.         int width = bitMatrix.getWidth();  
  50.         int height = bitMatrix.getHeight();  
  51.         BufferedImage image = new BufferedImage(width, height,  
  52.                 BufferedImage.TYPE_INT_RGB);  
  53.         for (int x = 0; x < width; x++) {  
  54.             for (int y = 0; y < height; y++) {  
  55.                 image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000  
  56.                         : 0xFFFFFFFF);  
  57.             }  
  58.         }  
  59.         if (imgPath == null || “”.equals(imgPath)) {  
  60.             return image;  
  61.         }  
  62.         // 插入图片  
  63.         QRCodeUtil.insertImage(image, imgPath, needCompress);  
  64.         return image;  
  65.     }  
  66.   
  67.      
  68.     private static void insertImage(BufferedImage source, String imgPath,  
  69.             boolean needCompress) throws Exception {  
  70.         File file = new File(imgPath);  
  71.         if (!file.exists()) {  
  72.             System.err.println(”“+imgPath+“   该文件不存在!”);  
  73.             return;  
  74.         }  
  75.         Image src = ImageIO.read(new File(imgPath));  
  76.         int width = src.getWidth(null);  
  77.         int height = src.getHeight(null);  
  78.         if (needCompress) { // 压缩LOGO  
  79.             if (width > WIDTH) {  
  80.                 width = WIDTH;  
  81.             }  
  82.             if (height > HEIGHT) {  
  83.                 height = HEIGHT;  
  84.             }  
  85.             Image image = src.getScaledInstance(width, height,  
  86.                     Image.SCALE_SMOOTH);  
  87.             BufferedImage tag = new BufferedImage(width, height,  
  88.                     BufferedImage.TYPE_INT_RGB);  
  89.             Graphics g = tag.getGraphics();  
  90.             g.drawImage(image, 0, 0, null); // 绘制缩小后的图  
  91.             g.dispose();  
  92.             src = image;  
  93.         }  
  94.         // 插入LOGO  
  95.         Graphics2D graph = source.createGraphics();  
  96.         int x = (QRCODE_SIZE - width) / 2;  
  97.         int y = (QRCODE_SIZE - height) / 2;  
  98.         graph.drawImage(src, x, y, width, height, null);  
  99.         Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);  
  100.         graph.setStroke(new BasicStroke(3f));  
  101.         graph.draw(shape);  
  102.         graph.dispose();  
  103.     }  
  104.   
  105.      
  106.     public static void encode(String content, String imgPath, String destPath,  
  107.             boolean needCompress) throws Exception {  
  108.         BufferedImage image = QRCodeUtil.createImage(content, imgPath,  
  109.                 needCompress);  
  110.         mkdirs(destPath);  
  111.         String file = new Random().nextInt(99999999)+“.jpg”;  
  112.         ImageIO.write(image, FORMAT_NAME, new File(destPath+“/”+file));  
  113.     }  
  114.   
  115.      
  116.     public static void mkdirs(String destPath) {  
  117.         File file =new File(destPath);     
  118.         //当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)  
  119.         if (!file.exists() && !file.isDirectory()) {  
  120.             file.mkdirs();  
  121.         }  
  122.     }  
  123.   
  124.      
  125.     public static void encode(String content, String imgPath, String destPath)  
  126.             throws Exception {  
  127.         QRCodeUtil.encode(content, imgPath, destPath, false);  
  128.     }  
  129.   
  130.      
  131.     public static void encode(String content, String destPath,  
  132.             boolean needCompress) throws Exception {  
  133.         QRCodeUtil.encode(content, null, destPath, needCompress);  
  134.     }  
  135.   
  136.      
  137.     public static void encode(String content, String destPath) throws Exception {  
  138.         QRCodeUtil.encode(content, null, destPath, false);  
  139.     }  
  140.   
  141.      
  142.     public static void encode(String content, String imgPath,  
  143.             OutputStream output, boolean needCompress) throws Exception {  
  144.         BufferedImage image = QRCodeUtil.createImage(content, imgPath,  
  145.                 needCompress);  
  146.         ImageIO.write(image, FORMAT_NAME, output);  
  147.     }  
  148.   
  149.      
  150.     public static void encode(String content, OutputStream output)  
  151.             throws Exception {  
  152.         QRCodeUtil.encode(content, null, output, false);  
  153.     }  
  154.   
  155.      
  156.     public static String decode(File file) throws Exception {  
  157.         BufferedImage image;  
  158.         image = ImageIO.read(file);  
  159.         if (image == null) {  
  160.             return null;  
  161.         }  
  162.         BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(  
  163.                 image);  
  164.         BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));  
  165.         Result result;  
  166.         Hashtable hints = new Hashtable();  
  167.         hints.put(DecodeHintType.CHARACTER_SET, CHARSET);  
  168.         result = new MultiFormatReader().decode(bitmap, hints);  
  169.         String resultStr = result.getText();  
  170.         return resultStr;  
  171.     }  
  172.   
  173.      
  174.     public static String decode(String path) throws Exception {  
  175.         return QRCodeUtil.decode(new File(path));  
  176.     }  
  177.      
  178.      
  179.     public static void main(String[] args) throws Exception {  
  180.         String text = ”http://www.dans88.com.cn”;  
  181.         QRCodeUtil.encode(text, ”d:/MyWorkDoc/my180.jpg”, “d:/MyWorkDoc”, true);  
  182.     }  
  183.      
  184. }  
  185. </span>  
<span style="background-color: rgb(255, 255, 255);">package qrcodesoft;


import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.OutputStream;
import java.util.Hashtable;
import java.util.Random;

import javax.imageio.ImageIO;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.Result;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;


public class QRCodeUtil {

    private static final String CHARSET = "utf-8";
    private static final String FORMAT_NAME = "JPG";
    // 二维码尺寸
    private static final int QRCODE_SIZE = 300;
    // LOGO宽度
    private static final int WIDTH = 60;
    // LOGO高度
    private static final int HEIGHT = 60;

    private static BufferedImage createImage(String content, String imgPath,
            boolean needCompress) throws Exception {
        Hashtable hints = new Hashtable();
        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);
        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 (imgPath == null || "".equals(imgPath)) {
            return image;
        }
        // 插入图片
        QRCodeUtil.insertImage(image, imgPath, needCompress);
        return image;
    }


    private static void insertImage(BufferedImage source, String imgPath,
            boolean needCompress) throws Exception {
        File file = new File(imgPath);
        if (!file.exists()) {
            System.err.println(""+imgPath+"   该文件不存在!");
            return;
        }
        Image src = ImageIO.read(new File(imgPath));
        int width = src.getWidth(null);
        int height = src.getHeight(null);
        if (needCompress) { // 压缩LOGO
            if (width > WIDTH) {
                width = WIDTH;
            }
            if (height > HEIGHT) {
                height = HEIGHT;
            }
            Image image = src.getScaledInstance(width, height,
                    Image.SCALE_SMOOTH);
            BufferedImage tag = new BufferedImage(width, height,
                    BufferedImage.TYPE_INT_RGB);
            Graphics g = tag.getGraphics();
            g.drawImage(image, 0, 0, null); // 绘制缩小后的图
            g.dispose();
            src = image;
        }
        // 插入LOGO
        Graphics2D graph = source.createGraphics();
        int x = (QRCODE_SIZE - width) / 2;
        int y = (QRCODE_SIZE - height) / 2;
        graph.drawImage(src, x, y, width, height, null);
        Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
        graph.setStroke(new BasicStroke(3f));
        graph.draw(shape);
        graph.dispose();
    }


    public static void encode(String content, String imgPath, String destPath,
            boolean needCompress) throws Exception {
        BufferedImage image = QRCodeUtil.createImage(content, imgPath,
                needCompress);
        mkdirs(destPath);
        String file = new Random().nextInt(99999999)+".jpg";
        ImageIO.write(image, FORMAT_NAME, new File(destPath+"/"+file));
    }


    public static void mkdirs(String destPath) {
        File file =new File(destPath);   
        //当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
        if (!file.exists() && !file.isDirectory()) {
            file.mkdirs();
        }
    }


    public static void encode(String content, String imgPath, String destPath)
            throws Exception {
        QRCodeUtil.encode(content, imgPath, destPath, false);
    }


    public static void encode(String content, String destPath,
            boolean needCompress) throws Exception {
        QRCodeUtil.encode(content, null, destPath, needCompress);
    }


    public static void encode(String content, String destPath) throws Exception {
        QRCodeUtil.encode(content, null, destPath, false);
    }


    public static void encode(String content, String imgPath,
            OutputStream output, boolean needCompress) throws Exception {
        BufferedImage image = QRCodeUtil.createImage(content, imgPath,
                needCompress);
        ImageIO.write(image, FORMAT_NAME, output);
    }


    public static void encode(String content, OutputStream output)
            throws Exception {
        QRCodeUtil.encode(content, null, output, false);
    }


    public static String decode(File file) throws Exception {
        BufferedImage image;
        image = ImageIO.read(file);
        if (image == null) {
            return null;
        }
        BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(
                image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        Result result;
        Hashtable hints = new Hashtable();
        hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
        result = new MultiFormatReader().decode(bitmap, hints);
        String resultStr = result.getText();
        return resultStr;
    }


    public static String decode(String path) throws Exception {
        return QRCodeUtil.decode(new File(path));
    }


    public static void main(String[] args) throws Exception {
        String text = "http://www.dans88.com.cn";
        QRCodeUtil.encode(text, "d:/MyWorkDoc/my180.jpg", "d:/MyWorkDoc", true);
    }

}
</span>


生成不带logo 的二维码

程序代码

 

  1. <span style=“background-color: rgb(255, 255, 255);”>public static void main(String[] args) throws Exception {  
  2.         String text = ”http://www.dans88.com.cn”;  
  3.         QRCodeUtil.encode(text,”“,“d:/MyWorkDoc”,true);</span>  
<span style="background-color: rgb(255, 255, 255);">public static void main(String[] args) throws Exception {
        String text = "http://www.dans88.com.cn";
        QRCodeUtil.encode(text,"","d:/MyWorkDoc",true);</span>

 

运行这个测试方法,生成的二维码不带 logo , 样式如下:







有兴趣可以用手机扫描一下

生成带logo 的二维码 
logo 可以用自己的头像,或者自己喜欢的一个图片都可以 , 采用如下代码

程序代码

 

  1. <span style=“background-color: rgb(255, 255, 255);”>public static void main(String[] args) throws Exception {  
  2.         String text = ”http://www.dans88.com.cn”;  
  3.         QRCodeUtil.encode(text, ”d:/MyWorkDoc/my180.jpg”, “d:/MyWorkDoc”, true);  
  4.     }</span>  
<span style="background-color: rgb(255, 255, 255);">public static void main(String[] args) throws Exception {
        String text = "http://www.dans88.com.cn";
        QRCodeUtil.encode(text, "d:/MyWorkDoc/my180.jpg", "d:/MyWorkDoc", true);
    }</span>

唯一的区别是,在前面的基础上指定了logo 的地址,这里测试都用了c盘的图片文件





用手机扫描,能出现要出现的文字,点击就进入自己的网站,看起来还不错, 整个源代码,提供在下载测试:

java barcode sample

本文转载于:http://blog.sina.com.cn/s/blog_5a6efa330102v1lb.html

 

Java 实现 生成二维码并添加到导出PDF上 5.前端选中要生成二维码的行信息时,触发点击事件调用生成二维码接口,将二维码路径存入redis。将pdf字节码上传redis服务器供下载 实现图1效果。返回加工插入二维码后的字节码数组,4.将生成的二维码插入PDF的实现方法。6.点击导出生成PDF的字节码数组,1.导入修改pdf的依赖工具类。2.导入生成二维码的依赖工具类。3.生成二维码的实现方法。 阅读详情

相关推荐

在java中生成二维码,并直接输出到jsp页面

在java中生成的二维码不存到磁盘里要直接输出到页面上,这就需要把生成的二维码直接以流的形式输出到页面上,我用的是myeclipse 和 tomcat 它的原理是:在加载页面时,根据img的src(code.jspx)找到对应的servlet(CodeServlet),在servlet中编辑二维码中的内容,调用生成二维码的类EncoderHandler中的encoderQRcoder方法

huakaihualuo1223的专栏 7万+

Java生成二维码的几种实现方式

本文将基于Spring Boot介绍两种生成二维码的实现方式,一种是基于Google开发工具包,另一种是基于Hutool来实现;下面我们将基于Spring Boot,并采用两种方式实现二维码的生成,对于每一种方式还提供两种类型的二维码返回形式,即:物理文件 和 图片响应流。

mcband的博客 1万+

Java通过QRCode生成二维码

本文从基础到高级再到实战,由浅入深,把MySQL讲的清清楚楚,明明白白,这应该是我目前为止看到过最好的有关MySQL的学习笔记了,我相信如果你把这份笔记认真看完后,无论是工作中碰到的问题还是被面试官问到的问题都能迎刃而解!MySQL50道高频面试题整理:《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门即可获取!的有关MySQL的学习笔记了,我相信如果你把这份笔记认真看完后,无论是工作中碰到的问题还是被面试官问到的问题都能迎刃而解!

2301_76278775的博客 1438

java实现二维码生成功能

java实现二维码生成功能

liulangzhezhang的博客 1万+

生成二维码并直接上传到七牛上

生成二维码

leapping的博客 2549

基于OpenSSL的CA建立及证书签发(签发多域名/IP)

自签SSL证书(多域名/IP) 本文基于以下环境: 内核信息:Linux zabbix 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux 系统版本:CentOS Linux release 7.6.1810 (Core) OpenSSL版本:OpenSSL 1.0.2k-fips 26 Jan 2017 【前言】 在基于OpenSSL的CA建立及证书签发一文中(后面统.

hobby云说 4654

在Mac上用Java玩转二维码:当极客遇到‘码’路奇缘

使用github开源项目qrcode

玦尘的博客 839

华为EC6110系列(3798mv310芯片)强刷固件全解析:从准备到实战

本文详细解析了华为EC6110系列(3798mv310芯片)强刷固件的全过程,从准备工作到实战步骤,包括固件特点、刷机工具准备、详细刷机步骤及常见问题解决方案。适合想要提升盒子性能的用户参考,特别强调了刷机过程中的注意事项和实用技巧。

rock5的博客 757

java生成中间带图片的二维码。

我不喜欢费话,直接上代码!这是一个工具类。 直接烤到项目中就可以用。生成二维码的图片后,就可以直接放到项目中去使用。 方便,简单。  //第一个类 import java.awt.Color; import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; import

柳承皓 2156

摩擦纳米发电机测试系统全解析:从硬件配置到软件控制

本文全面解析摩擦纳米发电机(TENG)测试系统,涵盖硬件配置、软件控制及系统集成。详细介绍NI USB-6003等采集卡的选择与使用,以及一体化控制软件的功能与优势,帮助研究人员高效评估纳米材料发电性能。系统支持自动测试与数据分析,显著提升测试效率与准确性。

weixin_28720767的博客 470

dify进阶:使用 FastAPI 的 StreamingResponse 实现高效的数据流传输

在 FastAPI 框架中,是一个非常有用的工具,它允许你以流的方式发送数据给客户端,而不是一次性加载所有内容到内存中再发送。这对于处理大型文件下载、视频流或者任何需要长时间处理的任务特别有用。

xiezhipu的博客 1442

Java后台直接生成二维码介绍

Java后台直接生成二维码 1、其实jquery也可以直接生成二维码的,但我测试的时候,二维码生成后太模糊,难以识别。所以在这里介绍在后来生成二维码的方式。 2、不善于文字描述,直接上代码了。 import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.image.Bu

星河漫步的专栏 1万+

无人机导航中的坐标系统详解与转换实现

本文系统介绍了无人机导航中常用的坐标系及其转换方法。主要内容包括:1) 四种关键坐标系(大地坐标系ECEF、经纬度LLA、北东天坐标系NED、机体坐标系)的定义和特点;2) 坐标系间的转换原理与实现,重点讲解LLA与ECEF的互转公式及ECEF与NED的转换方法;3) 提供可直接使用的C++实现代码,包括基于WGS84椭球模型的精确转换算法。这些内容为无人机导航系统开发提供了实用的坐标系处理方案,能够有效解决多源数据在不同坐标系下的统一表示问题。

电脑管家 386

Java后端生成二维码,Base64后,前端直接使用

后端生成二维码,Base64后,前端直接使用 开放中,可能会遇到生成二维码的时候,这个时候,可以前端生成,也可以后端生成。 这时候,就可以看,把压力放在哪比较好。 当二维码信息比较小,或者前端迭代比较困难的时候(APP发布),就可以选择后端生成二维码。 二维码这种图片,一般比较小,可直接生成,要是再放到文件服务器,未免有些多余,不如直接返回给前端。 但是,如果返回文件流的话,前后端都不太好操作...

LitongZero的博客 7173

YOLO骨干网络改进-第1篇:深度解析YOLOv8的C2f模块原理与实现

首先,需要将自定义的C2f模块注册到Ultralytics的模块字典中。# 注册自定义模块"""自定义的C2f模块。"""# 自定义YOLOv8s配置文件:yolov8s_custom.yamlscales:# Backbonebackbone:# Headhead:# 加载自定义模型# 训练模型imgsz=640,batch=16,device=0,workers=8,设计理念:C2f模块是C3模块的演进,通过增加梯度分支来丰富梯度流,提升特征表示能力。结构原理。

2201_76125393的博客 119

11. 使用 HTTP PUT, PATCH 以及 MERGE 请求消费 SAP ABAP OData 服务修改操作的实现及其区别

使用 SAP ABAP SEGW 事物码实现 OData 服务的修改操作时,对于消费端通过 PATCH/MERGE 和 PUT 这三种不同类型的 HTTP 请求触发的场景,我们应该在 UPDATE_ENTITY 方法里用 IF 分支分别进行处理,原因就在于 GET_ENTITY 方法是否在修改处理逻辑的过程中被触发。......

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2486

Java生成直接页面输出二维码,但不保存二维码图片

在Java中生成的二维码不存到磁盘里要直接输出到页面上,这就需要把生成的二维码直接以流的形式输出到页面上 原理:在加载页面时,根据img的src(code.jspx)找到对应的servlet(CodeServlet),在servlet中编辑二维码中的内容,调用生成二维码的类EncoderHandler中的encoderQRcoder方法 1.首先要导入jar包(将jar包放到lib目录

kimiHuanCSDN的博客 6756

用 MATLAB 实现鼻子和嘴的检测

为了方便起见,这里我们使用了 CascadeObjectDetector 中自带的 haarcascade_frontalface_alt2.xml 文件,该文件包含了多个包含鼻子和嘴的样本图像。其中 bbox 变量表示检测到的所有鼻子和嘴的边界框信息。在图像处理中,鼻子和嘴的检测是十分重要的一项任务。本文将介绍如何使用 MATLAB 实现鼻子和嘴的检测,并提供相应的源代码。然后,我们可以调用之前创建的 detector 对象来进行鼻子和嘴的检测。综上所述,我们可以使用以上代码实现鼻子和嘴的检测。

qq_39605374的博客 260

java生成二维码

是表示二维码矩阵的数据结构,由 0 和 1 构成的二维数组,用于存储二维码的编码信息。就是一个这么简单的二维码 我们需要去设置的东西有很多很多 那么有没有什么方法可以快速的开发呢?需要注意的是zxing是依赖commons-lang的所以我们也要加上去。是一个便捷的二维码生成类,可以生成多种格式的二维码,包括。这是一个简单的示例,当请求地址的时候 就会返回对应的url。这里直接用的最新的springboot3.3来做的演示。生成的时候我们要知道他的一些常用的参数 API。这个只是一个普通的二维码。

m0_48069349的博客 1543

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

java后台生成动态二维码

关于java后台生成动态二维码最近为了满足项目经理无理的要求,写了一个生成动态二维码的功能,感觉比较实用,特地拿来与各位头发不多的同胞一起分享,话不多说,直接上菜!!!再往下就是一个专门用于生成二维码的工具类,里面的方法亲测可以直接调用,里面有两个方法。第一个方法是可以设置二维码背景图片的,参数里面提供了四个主要参数第二个方法则是没有背景图片的,效果比较low,不过跟第一个方法的效果是一样的下面则...

光头强的博客 9638

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Java生成二维码

利用谷歌 zxing 技术生成二维码 引用pom依赖 &lt;!-- zxing --&gt; &lt;dependency&gt; &lt;groupId&gt;com.google.zxing&lt;/groupId&gt; &lt;artifactId&gt;core&lt;/artifactId&gt; &lt;version&gt;3.2

蜗牛学习笔记 5884

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Java后端生成二维码

Java后端生成二维码 pom.xml文件需要添加依赖jar包: <dependency> <groupId>com.google.zxing</groupId> <artifactId>javase</artifactId> <version>3.3.1</version> <...

命中的缘分的博客 2971

java生成圆形二维码logo

自定义生成二维码,可以根据自己的喜欢在二维码中添加图片。有些代码是参考网上某位大神的,如有相同之处,请给我留言,我加上您的名字或者不让参考发表,则可删除。 jar提取地址: 链接: https://pan.baidu.com/s/1nXiTbQXvNQUUYXsvLbSeyg 提取码: pdnd import com.swetake.util.Qrcode; import javax.imag...

wjs040的博客 5886

【Java生成二维码】java生成和解析二维码,只用一个jar包,QRCODE,可复制粘贴直接用

之前看了zxing的几个demo,发现封装的比较严重,因某些需要就没用它,只用了QRCODE这个jar,百度一下,轻松找到 纯Java项目结构如下 说明 :测试main方法有两块,一块是生成二维码,此代码里写的是放在d盘根目录,第二块是解析二维码,运行mian方法时,注释掉其中一个,如果要生成,就注释掉解析,反之,亦然。解析的代码片段里"File file = new File("D:/201

capricornce的博客 1861

java二维码生成技术

** java二维码生成技术 **   自从微信扫描出世,二维码扫描逐渐已经成为一种主流的信息传递和交换方式。下面就介绍一下我学习到的这种二维码生成方式。预计再过不久身份证户口本等都会使用二维码识别了,今天就做一个实验案例; 二维码主要实现这两点: 1.生成任意的二维码。 2.在二维码的中间加入图像。 一、准备工作。 准备QR二维码3.0 版本的core包和一张jpg图片。 下载QR二维码包。 ...

歲月的孤獨 1922
上一篇: Cookie(一)
下一篇: JAVA服务端用友盟给APP(android和IOS)推送消息--转自Carrot_lin
Tracyclock
博客等级 码龄10年 14粉丝 41原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址