精华内容
下载资源
问答
  • java 二维码相关Jar

    2017-10-13 11:10:09
    java 二维码相关Jarjava 二维码相关Jarjava 二维码相关Jarjava 二维码相关Jarjava 二维码相关Jarjava 二维码相关Jarjava 二维码相关Jarjava 二维码相关Jarjava 二维码相关Jarjava 二维码相关Jarjava 二维码相关Jar...
  • 该资源为java生成二维码,可调整二维码大小,排版,密度,设置图片头像
  • QRCodeUtils使用文档详见博客https://blog.csdn.net/qq_24091555/article/details/81263472
  • java二维码

    2017-08-04 15:17:24
    完整的二维码生成Java工程,包含所需要的jar包,说明等,收集了QRcode和Zxing两种方法
  • java 二维码图片生成+图片转换字符图片。 效果: https://blog.csdn.net/qq_37902949/article/details/81228320 https://blog.csdn.net/qq_37902949/article/details/81228566
  • JS 和 java二维码生成

    2017-06-08 14:35:34
    很好用的二维码生成工具类,共享一起用(前后台都有得例子)
  • java 二维码

    2019-04-01 01:03:28
    NULL 博文链接:https://chun521521.iteye.com/blog/1401603
  • 文件上传、有、无图标二维码生成显示网页
  • java生成二维码的工具类,内含有边框的二维码生成方式和没有边框的生成方式,还可选择底部是否加文字,内已经包含生成二维码的jar包,把相对应的文件放到相对应的位置就可以使用
  • java生成二维码功能代码,可生成带logo图片的二维码,可自定义二维码和logo图片的参数等功能。
  • java二维码jar包

    2018-10-08 14:28:43
    ZXing是一个开放源码的,用Java实现的多种格式的1D/2D条码图像处理库,它包含了联系到其他语言的端口。Zxing可以实现使用手机的内置的摄像头完成条形码的扫描及解码,可进行二维码开发。
  • 近年来,二维码的使用越来越风生水起,本篇文章主要介绍了Java二维码登录流程实现代码,其中包含短地址生成,有兴趣的可以了解一下。
  • java二维码生成工具类

    2019-08-06 01:27:36
    NULL 博文链接:https://softlife.iteye.com/blog/2087441
  • java二维码Demo 支付Demo

    2018-09-06 09:52:49
    里面是支付生成二维码的demo,也有需要的jar包,大家要用的直接拿去用即可
  • java 二维码带图片生成,有解析二维码和生成二维码的代码,可以直接使用,很方便
  • 一个简单的Java二维码的生成与解析实现的小程序。想学习怎么样生成二维码的同学可以学习一下。仅供参考 谢谢
  • java二维码生插件

    2018-06-29 08:59:05
    java生成二维码jar包,好用快捷方便易用,百度很多教学
  • java二维码生成器

    2014-02-16 18:29:21
    java 二维码生成器; 在使用二维码生成器时,系统默认会将生成的二维码图片放在D盘。
  • java二维码的生成工具

    千次阅读 2019-04-26 15:06:08
    java二维码的生成工具 1.导入jar包,我是用的是一个谷歌提供的 <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> <version>3.3.0</...

    java二维码的生成工具
    1.导入jar包,我是用的是一个谷歌提供的

    <dependency>
        <groupId>com.google.zxing</groupId>
        <artifactId>core</artifactId>
        <version>3.3.0</version>
    </dependency>
    

    2.新建一个帮助类,这是谷歌提供的

    import java.awt.Graphics2D;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import com.google.zxing.LuminanceSource;
    
    /**
     * @author bl
     * @date 2019-4-26
     */
    public class BufferedImageLuminanceSource extends LuminanceSource {
    
        private final BufferedImage image;
        private final int left;
        private final int top;
    
        BufferedImageLuminanceSource(BufferedImage image) {
            this(image, 0, 0, image.getWidth(), image.getHeight());
        }
    
        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) {
                        // = white
                        image.setRGB(x, y, 0xFFFFFFFF);
                    }
                }
            }
    
            this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY);
            this.image.getGraphics().drawImage(image, 0, 0, null);
            this.left = left;
            this.top = top;
        }
    
        @Override
        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;
        }
    
        @Override
        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;
        }
    
        @Override
        public boolean isCropSupported() {
            return true;
        }
    
        @Override
        public LuminanceSource crop(int left, int top, int width, int height) {
            return new BufferedImageLuminanceSource(image, this.left + left, this.top + top, width, height);
        }
    
        @Override
        public boolean isRotateSupported() {
            return true;
        }
    
        @Override
        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);
        }
    }
    

    3.工具类:
    编码和解码方法都有多个重载方法,根据参数列表的不同,选择不同的方法执行。其中生成的二维码的图片的名字可以随机命名,也可以自己给定。我把随机命名的方法注释了,用的是给定图片名称。

    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 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;
    
    /**
     * @author bl
     * @date 2018/4/26
     */
    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);
            // 压缩LOGO
            if (needCompress) {
                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));
            ImageIO.write(image, FORMAT_NAME, new File(destPath));
        }
    
        public static BufferedImage encode(String content, String imgPath, boolean needCompress) throws Exception {
            BufferedImage image = QRCodeUtil.createImage(content, imgPath, needCompress);
            return image;
        }
    
        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));
        }
    
    }
    

    4.测试:

    @Test
    public void contextLoads() {
    		// 存放在二维码中的内容
            String text = “i am blblbl”;
            // 嵌入二维码的图片路径 
            String imgPath = "E:\\WorkSpace\\Idea\\pt-ticket\\src\\main\\resources\\static\\admin\\images\\favicon.ico";
            // 生成的二维码的路径及名称
            String destPath = "E:/WorkSpace/Idea/pt-ticket/src/main/resources/static/admin/images/qr.jpg";
            try {
                //生成二维码
                QRCodeUtil.encode(text, imgPath, destPath, true);
            } catch (Exception e) {
                System.out.println("生成二维码异常");
                e.printStackTrace();
            }
            // 解析二维码,这里只是将上面的text解析出来了,所以扫描结果就是一串字符串
            String str = null;
            try {
                str = QRCodeUtil.decode(destPath);
            } catch (Exception e) {
                System.out.println("解析二维码异常");
                e.printStackTrace();
            }
            // 打印出解析出的内容
            System.out.println(str);
    }
    

    5.总的来说,就是加jar,加帮助类,加工具类,根据需求生成和解析二维码即可!
    emmmm.使用起来是不是很简单,当然这是站在大佬的肩膀上,底层还是很复杂的,学无止境!可以多分析分析,工具类,多测试,多想想底层!

    展开全文
  • 很好的java生成二维码,并压缩成压缩包工具类,请多多下载!
  • 基于java二维码生成,添加了中间logo与图片压缩功能。有Zxing与QRCode两种方式生成。
  • https://blog.csdn.net/LiQiangQiangIT/article/details/104547253?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-...
    	<!--生成二维码-->
        <dependency>
             <groupId>com.google.zxing</groupId>
             <artifactId>core</artifactId>
             <version>3.3.0</version>
        </dependency>
    
    
    package com.ws.demo.QRCodeUtil;
    
    import com.google.zxing.LuminanceSource;
    
    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    
    /**
     * 谷歌提供的帮助类
     */
    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);
        }
    
    }
    
    
    package com.ws.demo.QRCodeUtil;
    
    import com.google.zxing.*;
    import com.google.zxing.common.BitMatrix;
    import com.google.zxing.common.HybridBinarizer;
    import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
    
    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.awt.geom.RoundRectangle2D;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.OutputStream;
    import java.util.Hashtable;
    
    /**
     * 二维码生成工具
     */
    public class QRUtil {
        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;
            }
            // 插入图片
            QRUtil.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 = QRUtil.createImage(content, imgPath, needCompress);
            mkdirs(destPath);
            // String file = new Random().nextInt(99999999)+".jpg";
            // ImageIO.write(image, FORMAT_NAME, new File(destPath+"/"+file));
            ImageIO.write(image, FORMAT_NAME, new File(destPath));
        }
    
        public static BufferedImage encode(String content, String imgPath, boolean needCompress) throws Exception {
            BufferedImage image = QRUtil.createImage(content, imgPath, needCompress);
            return image;
        }
    
        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 {
            QRUtil.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 {
            QRUtil.encode(content, null, destPath, false);
        }
    
        public static void encode(String content, String imgPath, OutputStream output, boolean needCompress)
                throws Exception {
            BufferedImage image = QRUtil.createImage(content, imgPath, needCompress);
            ImageIO.write(image, FORMAT_NAME, output);
        }
    
        public static void encode(String content, OutputStream output) throws Exception {
            QRUtil.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 QRUtil.decode(new File(path));
        }
    
    }
    
    
    

    https://blog.csdn.net/LiQiangQiangIT/article/details/104547253?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control

    展开全文
  • 主要介绍了JAVA实现二维码生成加背景图代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
  • Java二维码

    2017-05-14 11:30:59
    Java封装生成带有logo的二维码
  • 简单的基于java二维码生成原理,所用到的知识有输入输出流也就是IO,还有用到关键的一个二维码jar包QRCode.jar,
  • JAVA二维码算法实现

    2016-01-26 01:10:47
    简单的二维码JAVA开发程序,并带了两个所需的插件

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 85,221
精华内容 34,088
关键字:

java二维码

java 订阅