使用Java生成二维码

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

使用Java生成二维码

摘要:本文中代码的作用是使用Java生成二维码。

硬件环境:Windows
软件环境:jdk1.8.0.144、eclipse
所需jar包:Qrcode.jar

代码:

package com.ck.test;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.swetake.util.Qrcode;

public class Test {

    /**
     * 生成二维码图片
     * @param content 扫描二维码后显示的内容
     * @param path 生成的二维码图片保存的路径,比如 C:/img/qrcode.png
     * @throws IOException 
     */
    public static void generateQRImage(String content,String path) throws IOException{
        Qrcode x=new Qrcode();
        x.setQrcodeErrorCorrect('M');//纠错等级
        x.setQrcodeEncodeMode('B');//数据的类型
        x.setQrcodeVersion(7);//设置版本

        int width = 67 + 12 * (7 - 1);//公式:67 + 12 * (版本号 - 1)
        int height = 67 + 12 * (7 - 1);

        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);//参数是宽度,高度,颜色类型
        Graphics2D graphics2d = bufferedImage.createGraphics();//创建画图对象
        graphics2d.setColor(Color.BLACK);//设置内容颜色
        graphics2d.setBackground(Color.WHITE);//设置背景颜色
        graphics2d.clearRect(0, 0, width, height);//清除出一块矩形空间,供画图用

        byte[] d = content.getBytes("utf-8");

        if (d.length>0 && d.length <120){
            boolean[][] s = x.calQrcode(d);
            for (int i=0;i<s.length;i++){
                for (int j=0;j<s.length;j++){
                    if (s[j][i]) {
                        graphics2d.fillRect(j*3+2,i*3+2,3,3);
                    }
                }
            }
        }

        graphics2d.dispose();
        bufferedImage.flush();

        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }

        ImageIO.write(bufferedImage, "png", new File(path));
    }

    public static void main(String[] args) throws IOException {
        generateQRImage("我是大帅哥!!!", "D:/test/qrcode.png");
    }
}

运行后生成的图片:

欢迎大家看我的博客,刚开始写,以后会写的越来越好的!大家有什么问题请留言,大家共同提高!
源码包可以在我贡献的资源中下载哦~

Java二维码学习 总结Java生成二维码的方式,生成普通二维码,带logo二维码,带文字二维码,带多行文字二维码,带多行key-value形式的二维码 阅读详情

相关推荐

java 使用zxing 生成二维码

package com.lyis.core.util; 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; imp

灵魂在奔跑 1万+

java实现二维码生成功能

java实现二维码生成功能

liulangzhezhang的博客 1万+

使用zxing生成嵌图片的二维码【java】

涉及两方面的知识: 1.QR code的基础,参见大牛的作品http://coolshell.cn/articles/10590.html 2.java图形库image、Graphics2D等 基本思路是先使用zxing生成的二维码图片,然后读取图片,在其中插入图标,然后整个输出图片。 网上还看到另外一种做法,先生成二维码图片,然后把图标直接覆盖在二维码上,这样会丢失一部分数据,但

李春喜的专栏 1万+

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

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

mcband的博客 1万+

Java使用ZXing生成二维码实战教程

ZXing(Zebra Crossing)是一个开源、跨平台的条码与二维码处理工具库,广泛应用于各类Java项目中,支持二维码的生成、解析及图像处理功能。其模块化设计使得开发者可以根据需要选择核心模块或扩展模块进行集成。本章将引导你了解ZXing的核心功能,并掌握如何在Java项目中引入ZXing库,为后续生成和解析二维码打下基础。ZXing库采用模块化设计,其核心模块为core,负责二维码的编码和解码功能。除此之外,ZXing还提供了多个子模块以满足不同场景需求:模块名功能说明。

weixin_28487725的博客 1099

JAVA Swing开发二维码生成工具,exe和jar包版本,使用谷歌zxing和jdk1.8

使用谷歌zxing的core-3.3.3版本在jdk1.8环境下使用java swing开发的简单二维码生成工具,内含jar包和exe两种版本,简单实用,可以添加中间logo图片

使用JAVA代码实现生成二维码

在我们日常生活中,随处可见的二维码。在我们点餐时、购物时或是加好友时都会出现二维码,我们只需扫描二维码,就可以直接跳转到对应的小程序或者支付窗口。这是如何实现的呢?对我们软件、计算专业的同学来说,如何使用编程去实现二维码是非常必要的!!!

心态的博客 1万+

10xGenomics官方可视化工具——Loupe Browser

Loupe Browser是⼀款10xGenomics开发的交互式桌⾯应⽤程序,⽤于探索10x单细胞数据,可以用来找出感兴趣的细胞、找出显著差异表达的基因、鉴定细胞类型、探索细胞亚类和数据共享。

weixin_47195452的博客 3361

java之生成二维码以及使用

一、背景 1.今天做了一个二维码的生成以及简单的跳转应用,结下来我们来演示下吧。 二、项目结构 1.项目图片 三、项目详解 1.pom.xml <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> ...

码农小默 497

一文读懂水利无人机AI识别算法,概念、需求、解决方案

复亚智能的水利无人机AI识别算法通过先进的技术手段,为水利管理提供了高效、精准的解决方案。随着技术的不断进步和应用的深入,复亚智能的解决方案将在更多水利场景中发挥重要作用,助力智慧水利管理的全面升级。该系统通过搭载在无人机上的传感器和摄像头,结合先进的AI识别算法,实现对河道淤积、漂浮物、船只和水质污染等问题的自动检测和监控。基于大量实飞采集的数据,复亚智能的算法经过严格的训练,能够准确识别各种水利问题。复亚智能的系统具有高度的开放性和兼容性,能够与第三方平台和算法无缝对接,满足不同客户的多样化需求。

foiadrone的博客 1198

【视频讲解】Python量子计算聚类Q-means:量子k-means算法分析电路数据实现可视化...

全文链接:https://tecdat.cn/?p=37821分析师:Yifan Zhang量子计算在近期已然成为一个频繁出现的热门概念。尽管它在大众认知以及互联网社区中备受瞩目,热度极高,然而就其实际能力而言,当前仍然存在诸多局限(点击文末“阅读原文”获取完整代码数据)。量子计算作为一个全新的领域,带来了相较于传统经典计算模式的重大范式转变。在量子计算的体系中,传统的 0 或 1 的经典比特被一...

拓端研究室TRL 1456

使用java生成、解析二维码

一、导入jar包(在工程中可以导入依赖) 在一个普通的java项目中,我们需要导入相关的jar包来生成和解析二维码,但是在一个maven工程等等的web项目中,我们可以通过带入相关依赖来实现。 jar包链接: https://pan.baidu.com/s/1Vk6QnyFWQuMxm85RsMOrAg 提取码:9nbk 如果添加依赖的话,可以导入下面的Zxing依赖: <dependen...

╱/.独﹄無㈡oоΟ的博客 6011

桁架 拓扑优化 matlab程序_拓扑优化在结构轻量化及板壳加筋肋最优布置的应用...

1 拓扑优化简介材料的有效利用一直都是人类追求的目标,也是许多研究领域不变的话题,并伴随着结构优化理论和方法的产生而发展。结构优化设计通常分为三个层次:(1)拓扑优化:在一个确定的连续区域内寻求结构内部非实体区域位置和数量的最佳配置,寻求结构中的构件布局及节点联结方式最优化,使结构能在满足应力、位移等约束条件下,将外载荷传递到结构支撑位置,同时使结构的某种性态指标达到最优;(2)形状优化:指在保持...

weixin_39525355的博客 1878

java使用zxing生成和解析二维码

什么是zxing? ZXing是一个开放源码的,用Java实现的多种格式的1D/2D条码图像处理库,它包含了联系到其他语言的端口。Zxing可以实现使用手机的内置的摄像头完成条形码的扫描及解码。 导入maven依赖 注意:jdk不能低于8 <!-- 导入zxing的依赖 --> <dependency> <groupId>...

gy 1539

k最近邻算法——电影分类及案例详解

如图3-7所示,若将国际象棋棋盘放在二维直角坐标系中,格子的边长定义为1,坐标的x轴及y轴和棋盘方格平行,原点恰落在某一格的中心点,则王从一个位置走到其他位置需要的步数恰为二个位置的切比雪夫距离,因此切比雪夫距离也称为棋盘距离。关于这里的距离度量,这个电影分类的例子有2个特征,也就是2维的,可以使用我们高中学过的两点距离公式(两点距离公式其实就是欧氏距离在二维空间上的公式,也就是欧氏距离n的值为2的情况,欧氏距离也称为欧几里德距离)来计算距离,如图3-3所示。对数据进行归一化,避免量纲对计算距离的影响。

ZhShy 4560

[VT虚拟化驱动]利用EPT实现无痕HOOK

本章利用讲EPT无痕HOOK

吾无法无天的博客 1万+

【Java,二维码】Java 使用 swetake 生成二维码图片

重要声明:本文章仅仅代表了作者个人对此观点的理解和表述。读者请查阅时持自己的意见进行讨论。 本文原文地址:【Java,二维码】Java 使用 swetake 生成二维码图片,本文更新不及时,建议到原文地址浏览。 二维码又称二维条码,是1994年由日本DW公司发明。常见的二维码为QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar ...

MicroAnswer的博客 2479

AWR1843+DCA1000通过mmwave studio采集数据遇到的问题及解决方法

确保DCA1000的拨钮拨在了RADAR_5V_IN一边,这代表DCA1000通过与其相连的雷达板子供电,如果拨到了DC_JACK5V_IN一边,表示DCA1000用单独的电源供电。

qq_50974341的博客 4165

Java使用QRGen类库生成二维码

最近项目上需要用到通过扫描二维码来获取网页地址,在这个扫扫更健康的年代,不会使用二维码你就out啦!QRGen类库生成二维码真的很 So Easy,一睹为快。

墨尔本_晴的博客 3091

在 SAP 中启用应收/应付“代扣税(Withholding Tax)”功能,本质上是激活并配置“扩展代扣税(Extended Withholding Tax)”模型

摘要:SAP中启用应收/应付代扣税功能需完成3个层级12个核心步骤:1)全局激活公司代码代扣税功能;2)配置代扣税规则、税率和科目,包括定义税种类型、代码、总账科目等;3)在供应商/客户主数据中关联代扣税设置。完成后系统可在发票或付款环节自动计算并过账代扣税,支持多税种并行计算和税率年度调整,最终生成税务报表。常见问题排查需检查公司代码激活状态和主数据配置。(149字)

金牌架构师 836

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

如何使用 Java 生成二维码并返回图片

通过上述步骤,你可以使用 Java 和 ZXing 库快速生成二维码并将其以图片形式返回给客户端。这样做的好处是避免了 Base64 编码带来的复杂性,直接以图片的形式返回,更加方便用户查看和下载二维码。我们将编写一个 Spring Boot 控制器,提供一个 API 接口,通过这个接口可以生成二维码,并将其返回为图片。此方法不仅适用于网站 URL,也可以应用于各种场景,例如生成动态二维码、生成带有不同信息的二维码等。通过访问上述链接,浏览器会返回一个二维码图片,二维码内容为。方法来生成二维码矩阵。

qq_45973421的博客 980

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

java使用jar包生成二维码

使用java进行二维码的生成与读取使用到了谷歌的zxing.jar 第一步 导入,maven依赖或者下载指定jar包 <!-- https://mvnrepository.com/artifact/com.google.zxing/javase --> <dependency> <groupId>com.google.zxing</groupId> <artifactId>javase</artifactId>

jiandanyou的博客 1797

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

如何使用 Java 生成二维码

如何使用 Java 生成二维码 步骤 下载jar包(QRCode.jar) maven项目手动引入jar包 编写实体类实现二维码的生成 controller调用 下载jar包(QRCode.jar) 下载网址如下:  QRCode生成二维码网址:http://swetake.com/qrcode/index-e.html maven项目手动引入...

happypX的博客 283

使用java读取生成二维码

使用java进行二维码的生成与读取使用到了谷歌的zxing.jar 第一步 导入,maven依赖或者下载指定jar包 第二步 书写二维码生成器的工具类 import java.awt.Color; import java.io.File; import java.util.Hashtable; import com.google.zxing.EncodeHintType; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; /** *

weixin_51405539的博客 493
下一篇: Java读取配置文件(Properties类)
小狐狸218
博客等级 码龄11年 4粉丝 4原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值