You can refer to http://www.java2s.com/Code/Jar/z/Downloadzxingcore20jar.htm to download zxing-core-2.0.jar first.
then create java file
MatrixToImageWriter.java
package com.syc.util.qrcode; import com.google.zxing.common.BitMatrix; import javax.imageio.ImageIO; import java.io.File; import java.io.OutputStream; import java.io.IOException; import java.awt.image.BufferedImage; public final class MatrixToImageWriter { private static final int BLACK = 0xFF000000; private static final int WHITE = 0xFFFFFFFF; private MatrixToImageWriter() {} public static BufferedImage toBufferedImage(BitMatrix matrix) { int width = matrix.getWidth(); int height = matrix.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, matrix.get(x, y) ? BLACK : WHITE); } } return image; } public static void writeToFile(BitMatrix matrix, String format, File file) throws IOException { BufferedImage image = toBufferedImage(matrix); if (!ImageIO.write(image, format, file)) { throw new IOException("Could not write an image of format " + format + " to " + file); } } public static void writeToStream(BitMatrix matrix, String format, OutputStream stream) throws IOException { BufferedImage image = toBufferedImage(matrix); if (!ImageIO.write(image, format, stream)) { throw new IOException("Could not write an image of format " + format); } } }
and create test java
Test.java
package com.syc.util.qrcode; import java.io.File; import java.util.Hashtable; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatWriter; import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; public class Test { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { String text = "http://www.baidu.com"; int width = 300; int height = 300; //二维码的图片格式 String format = "gif"; Hashtable hints = new Hashtable(); //内容所使用编码 hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height, hints); //生成二维码 File outputFile = new File("d:"+File.separator+"new.gif"); MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile); } }
then everything is ok, you can run Test.java to check the result.
Good luck for you~
--------------
相关推荐
最新功能支持导入码内容文件批量生成二维码,支持生成带中国二维码注册解析中心(IDcode)认证的二维码。 运行方式:1、在项目上右击 运行java程序,入口在com.fiwan.qrgenerator.GeneratorForm 2、打jar包 java -...
java生成二维码源码+QR code所需jar包
生成QR CODE的二维码JAVA源程序,包含2个文件压缩包
用Java生产二维码超简单~~~ Qrcode qrcode=new Qrcode();qrcode.setQrcodeVersion(8);//0~40 qrcode.setQrcodeEncodeMode('B'); qrcode.setQrcodeErrorCorrect('H');//L M Q H
从QR Code码的英文名称Quick Response Code可以看出,超高速识读特点是QR Code码区别于四一七条码、Data Matrix等二维码的主要特性。由于在用CCD识读QR Code码时,整个QR Code码符号中信息的读取是通过QR Code码...
Java实现生成和解析二维码...二维码又称二维条码,常见的二维码为QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更多的数据类型。
QR code比其他二维码相比,具有识读速度快,数据密度大,占用空间小的优势。 QR Code是有日本Demso公司于1994年研制的一种矩阵二维码符号码 纠错能力: L级:约可纠错7%的数据码字 M级:约可纠错15%的数据码字 Q级...
最新功能支持导入码内容文件批量生成二维码,支持生成带中国二维码注册解析中心(IDcode)认证的二维码。 运行方式:1、在项目上右击 运行java程序,入口在com.fiwan.qrgenerator.GeneratorForm 2、打jar包 java -...
【java】将图片转化为QR code二维码
先介绍一下项目场景,主要是通过微信小程序二维码裂变分享,每个账号有专属邀请二维码,分享...官方地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html
web版本的QR二维码生成器,可生成QR图片,同时支持网页内嵌URL在线生成显示QR图片。源码请见本人的博客。
QR(Quick Response)是一种二维码,此资源是QR的java源代码,包含了QR的解码
Java生成二维码 Hashtable, Object> hints = new Hashtable, Object>(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); BitMatrix byteMatrix; try { byteMatrix = new ...
A QR code generator which gives ASCII Art output image. A java version of QArt with enhancement. All credit goes to Russ Cox. Sample output: How to generate a runnable jar QArt4j is a maven project, ...
这个压缩包是有关于如何用java来完成二维码制作的教学视频
Java的Aspose.BarCode的QR Code生成器是一个Web应用程序,可使用Java的Aspose.BarCode生成各种类型的QR代码。 http://goo.gl/GqUMog
本程序写的是一个可双击运行的java程序,无需安装环境,下载即可用,本实例是根据自己需要在文件夹下生成一个二维码,如果各位朋友有其它需求可以给我留言。
Introduction to Java 123 (QR code Edition). PDF Tsinghua University Press 2015
QR Generator 应用程序完全使用模型视图控制器方法构建在用于后端的 Java SE 和用于 UI 的 Java Swing 中。 它依赖XZing Library构建二维码,生成二维码图像,可以导出到本地文件系统。 要读取二维码图像,您需要...
A productive QR code toolkit with efficiency and elegance, just feeling it on the fly. More than a QR code generator. 快码二维,疾行如风。可能是最好用最具生产力的二维码工具。 Quico 快码 次世代生产力...