导航:首页 > 编程语言 > java生成qrcode

java生成qrcode

发布时间:2022-08-21 09:47:49

java怎么生成二维码

1: 使用SwetakeQRCode在Java项目中生成二维码
这个是日本人写的,生成的是我们常见的方形的二维码
可以用中文

2: 使用BarCode4j生成条形码和二维码
barcode4j是使用datamatrix的二维码生成算法,为支持qr的算法
datamatrix是欧美的标准,qr为日本的标准,
barcode4j一般生成出来是长方形的
3:zxing
zxing 这个是google的

⑵ 怎么用java代码把一个链接生成二维码

参考代码
import java.io.*;
import java.util.Date;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
public class QRCodeEncoderTest
{
/** Creates a new instance of QRCodeEncoderTest */
public QRCodeEncoderTest()
{
}
public static void create_image(String sms_info)throws Exception{
try{
qrcode testQrcode =new qrcode();
testQrcode.setQrcodeErrorCorrect('M');
testQrcode.setQrcodeEncodeMode('B');
testQrcode.setQrcodeVersion(7);
String testString = sms_info;
byte[] d = testString.getBytes("gbk");
System.out.println(d.length);
//BufferedImage bi = new BufferedImage(98, 98, BufferedImage.TYPE_INT_RGB);
BufferedImage bi = new BufferedImage(98, 98,

⑶ java哪种方式生成二维码比较好

最简单的方式使用jQuery的qrCode插件

[html] view plain
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>使用JQueryQrCode生成二维码</title>
<script type="text/javascript" src="./js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="./js/qrcode.js"></script>
</head>
<body>
<div id="qrcode"></div>

<script type="text/javascript">
//参数1表示图像大小,取值范围1-10;参数2表示质量,取值范围'L','M','Q','H'
var content = "使用JQueryQrCode生成二维码"
var qr = qrcode(8, 'M');
qr.addData(content);
qr.make();
/* var dom=document.createElement('DIV');
dom.innerHTML = qr.createImgTag();
var element=document.getElementById("qrcode");
element.appendChild(dom); */
$("#qrcode").html(qr.createImgTag());

</script>
</body>
</html>

⑷ 我已经用java生成了一个二维码了,怎样让扫描二维码后,读取到一个word文档,大神。

不用这么麻烦,直接使用二维码生成器就行了,只要上传文档,自动直接生成二维码。方便有快捷。

推荐一款目前市面上比较不错的二维码生成工具。

上传完成后保存即可生成二维码,并且生成的二维码内容支持随时修改,原码不变!

希望对你有帮助!

⑸ java中怎样用代码生成二维码

参考代码

import java.io.*;
import java.util.Date;

import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;

public class QRCodeEncoderTest
{

/** Creates a new instance of QRCodeEncoderTest */
public QRCodeEncoderTest()
{
}

public static void create_image(String sms_info)throws Exception{
try{
qrcode testQrcode =new qrcode();
testQrcode.setQrcodeErrorCorrect('M');
testQrcode.setQrcodeEncodeMode('B');
testQrcode.setQrcodeVersion(7);
String testString = sms_info;
byte[] d = testString.getBytes("gbk");
System.out.println(d.length);
//BufferedImage bi = new BufferedImage(98, 98, BufferedImage.TYPE_INT_RGB);
BufferedImage bi = new BufferedImage(98, 98, BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g = bi.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, 98, 98);
g.setColor(Color.BLACK);

// 限制最大字节数为120
if (d.length>0 && d.length <120){
boolean[][] s = testQrcode.calQrcode(d);
for (int i=0;i<s.length;i++){
for (int j=0;j<s.length;j++){
if (s[j][i]) {
g.fillRect(j*2+3,i*2+3,2,2);
}
}
}
}
g.dispose();
bi.flush();
File f = new File("D:\\QRCodeTest\\"+sms_info+".jpg");
if(!f.exists()){
f.createNewFile();
}
//创建图片
ImageIO.write(bi, "jpg", f);

} // end try
catch (Exception e) {
e.printStackTrace();
} // end catch
}

public static void main(String[] args) throws Exception {
System.out.println(new Date());
for(int i =1; i < 100000; i ++){
QRCodeEncoderTest.create_image(i+"");
}
System.out.println(new Date());
} // end main
}

⑹ java 如何完成二维码的制作

参考以下代码:

//创建BarcodeSettings实例
BarcodeSettingssettings=newBarcodeSettings();
//设置条码类型为QR二维码
settings.setType(BarCodeType.QR_Code);
//设置二维码数据
settings.setData("Hello123456789");
//设置二维码显示数据
settings.setData2D("Hello123456789");
//设置数据类型
settings.setQRCodeDataMode(QRCodeDataMode.Alpha_Number);
//设置二维码模型宽度
settings.setX(1.0f);
//设置二维码纠错级别
settings.setQRCodeECL(QRCodeECL.H);
//创建BarCodeGenerator实例
=newBarCodeGenerator(settings);
//根据settings生成图像数据,保存至BufferedImage实例
BufferedImagebufferedImage=barCodeGenerator.generateImage();
//保存为PNG图片
ImageIO.write(bufferedImage,"png",newFile("QRCode.png"));
System.out.println("Complete!");

需要引用Spire.Barcode for java

原文:Java 生成二维码

⑺ Java如何用代码生成二维码

引用spire.barcode.jar包

//创建BarcodeSettings对象
BarcodeSettingssettings=newBarcodeSettings();
//设置条码类型为
QR二维码settings.setType(BarCodeType.QR_Code);
//设置二维码数据
settings.setData("Hello123456789");
//设置二维码显示数据
settings.setData2D("Hello123456789");
//设置数据类型
settings.setQRCodeDataMode(QRCodeDataMode.Alpha_Number);
//设置二维码模型宽度
settings.setX(1.0f);
//设置二维码纠错级别settings.setQRCodeECL(QRCodeECL.H);
//创建BarCodeGenerator实例
=newBarCodeGenerator(settings);
//根据settings生成图像数据,保存至BufferedImage
BufferedImagebufferedImage=barCodeGenerator.generateImage();
//将图片数据保存为PNG格式
ImageIO.write(bufferedImage,"png",newFile("QRCode.png"));

⑻ 如何用java生成二维码

packagecommon;

importjava.awt.Color;
importjava.awt.Graphics2D;
importjava.awt.Image;
importjava.awt.image.BufferedImage;
importjava.io.File;
importjava.io.IOException;
importjava.util.HashMap;
importjava.util.Map;

importjavax.imageio.ImageIO;

importjp.sourceforge.qrcode.QRCodeDecoder;
importjp.sourceforge.qrcode.exception.DecodingFailedException;

importcom.google.zxing.BarcodeFormat;
importcom.google.zxing.Binarizer;
importcom.google.zxing.BinaryBitmap;
importcom.google.zxing.EncodeHintType;
importcom.google.zxing.LuminanceSource;
importcom.google.zxing.MultiFormatReader;
importcom.google.zxing.MultiFormatWriter;
importcom.google.zxing.NotFoundException;
importcom.google.zxing.WriterException;
importcom.google.zxing.common.BitMatrix;
importcom.google.zxing.common.HybridBinarizer;
importcom.swetake.util.Qrcode;

/**
*二维码生成工具类
*@authorCloud
*@data2016-12-15
*QRCode
*/

publicclassQRCodeUtil{

//二维码颜色
privatestaticfinalintBLACK=0xFF000000;
//二维码颜色
privatestaticfinalintWHITE=0xFFFFFFFF;

/**
*<spanstyle="font-size:18px;font-weight:blod;">ZXing方式生成二维码</span>
*@paramtext<ahref="javascript:void();">二维码内容</a>
*@paramwidth二维码宽
*@paramheight二维码高
*@paramoutPutPath二维码生成保存路径
*@paramimageType二维码生成格式
*/
(Stringtext,intwidth,intheight,StringoutPutPath,StringimageType){
Map<EncodeHintType,String>his=newHashMap<EncodeHintType,String>();
//设置编码字符集
his.put(EncodeHintType.CHARACTER_SET,"utf-8");
try{
//1、生成二维码
BitMatrixencode=newMultiFormatWriter().encode(text,BarcodeFormat.QR_CODE,width,height,his);

//2、获取二维码宽高
intcodeWidth=encode.getWidth();
intcodeHeight=encode.getHeight();

//3、将二维码放入缓冲流
BufferedImageimage=newBufferedImage(codeWidth,codeHeight,BufferedImage.TYPE_INT_RGB);
for(inti=0;i<codeWidth;i++){
for(intj=0;j<codeHeight;j++){
//4、循环将二维码内容定入图片
image.setRGB(i,j,encode.get(i,j)?BLACK:WHITE);
}
}
FileoutPutImage=newFile(outPutPath);
//如果图片不存在创建图片
if(!outPutImage.exists())
outPutImage.createNewFile();
//5、将二维码写入图片
ImageIO.write(image,imageType,outPutImage);
}catch(WriterExceptione){
e.printStackTrace();
System.out.println("二维码生成失败");
}catch(IOExceptione){
e.printStackTrace();
System.out.println("生成二维码图片失败");
}
}

/**
*<spanstyle="font-size:18px;font-weight:blod;">二维码解析</span>
*@paramanalyzePath二维码路径
*@return
*@throwsIOException
*/
@SuppressWarnings({"rawtypes","unchecked"})
(StringanalyzePath)throwsException{
MultiFormatReaderformatReader=newMultiFormatReader();
Objectresult=null;
try{
Filefile=newFile(analyzePath);
if(!file.exists())
{
return"二维码不存在";
}
BufferedImageimage=ImageIO.read(file);
LuminanceSourcesource=newLuminanceSourceUtil(image);
Binarizerbinarizer=newHybridBinarizer(source);
BinaryBitmapbinaryBitmap=newBinaryBitmap(binarizer);
Maphints=newHashMap();
hints.put(EncodeHintType.CHARACTER_SET,"UTF-8");
result=formatReader.decode(binaryBitmap,hints);
}catch(NotFoundExceptione){
e.printStackTrace();
}
returnresult;
}

/**
*<spanstyle="font-size:18px;font-weight:blod;">QRCode方式生成二维码</span>
*@paramcontent二维码内容
*@paramimgPath二维码生成路径
*@paramversion二维码版本
*@paramisFlag是否生成Logo图片为NULL不生成
*/
publicstaticvoidQRCodeCreate(Stringcontent,StringimgPath,intversion,StringlogoPath){
try{
QrcodeqrcodeHandler=newQrcode();
//设置二维码排错率,可选L(7%)M(15%)Q(25%)H(30%),排错率越高可存储的信息越少,但对二维码清晰度的要求越小
qrcodeHandler.setQrcodeErrorCorrect('M');
//N代表数字,A代表字符a-Z,B代表其他字符
qrcodeHandler.setQrcodeEncodeMode('B');
//版本1为21*21矩阵,版本每增1,二维码的两个边长都增4;所以版本7为45*45的矩阵;最高版本为是40,是177*177的矩阵
qrcodeHandler.setQrcodeVersion(version);
//根据版本计算尺寸
intimgSize=67+12*(version-1);
byte[]contentBytes=content.getBytes("gb2312");
BufferedImagebufImg=newBufferedImage(imgSize,imgSize,BufferedImage.TYPE_INT_RGB);
Graphics2Dgs=bufImg.createGraphics();
gs.setBackground(Color.WHITE);
gs.clearRect(0,0,imgSize,imgSize);
//设定图像颜色>BLACK
gs.setColor(Color.BLACK);
//设置偏移量不设置可能导致解析出错
intpixoff=2;
//输出内容>二维码
if(contentBytes.length>0&&contentBytes.length<130){
boolean[][]codeOut=qrcodeHandler.calQrcode(contentBytes);
for(inti=0;i<codeOut.length;i++){
for(intj=0;j<codeOut.length;j++){
if(codeOut[j][i]){
gs.fillRect(j*3+pixoff,i*3+pixoff,3,3);
}
}
}
}else{
System.err.println("QRCodecontentbyteslength="+contentBytes.length+"notin[0,130].");
}
/*判断是否需要添加logo图片*/
if(logoPath!=null){
Fileicon=newFile(logoPath);
if(icon.exists()){
intwidth_4=imgSize/4;
intwidth_8=width_4/2;
intheight_4=imgSize/4;
intheight_8=height_4/2;
Imageimg=ImageIO.read(icon);
gs.drawImage(img,width_4+width_8,height_4+height_8,width_4,height_4,null);
gs.dispose();
bufImg.flush();
}else{
System.out.println("Error:login图片还在在!");
}

}


gs.dispose();
bufImg.flush();
//创建二维码文件
FileimgFile=newFile(imgPath);
if(!imgFile.exists())
imgFile.createNewFile();
//根据生成图片获取图片
StringimgType=imgPath.substring(imgPath.lastIndexOf(".")+1,imgPath.length());
//生成二维码QRCode图片
ImageIO.write(bufImg,imgType,imgFile);
}catch(Exceptione){
e.printStackTrace();
}
}

/**
*<spanstyle="font-size:18px;font-weight:blod;">QRCode二维码解析</span>
*@paramcodePath二维码路径
*@return解析结果
*/
(StringcodePath){
FileimageFile=newFile(codePath);
BufferedImagebufImg=null;
StringdecodedData=null;
try{
if(!imageFile.exists())
return"二维码不存在";
bufImg=ImageIO.read(imageFile);

QRCodeDecoderdecoder=newQRCodeDecoder();
decodedData=newString(decoder.decode(newImageUtil(bufImg)),"gb2312");
}catch(IOExceptione){
System.out.println("Error:"+e.getMessage());
e.printStackTrace();
}catch(DecodingFailedExceptiondfe){
System.out.println("Error:"+dfe.getMessage());
dfe.printStackTrace();
}
returndecodedData;
}

}


3、最后贴测试代码:

packagetest;

importjava.awt.image.BufferedImage;
importjava.io.InputStream;
importjava.net.URL;

importjavax.imageio.ImageIO;

importcommon.ImageUtil;
importcommon.QRCodeUtil;

importjp.sourceforge.qrcode.QRCodeDecoder;

/**
*二维码生成测试类
*@authorCloud
*@data2016-11-21
*QRCodeTest
*/

publicclassQRCodeTest{

publicstaticvoidmain(String[]args)throwsException{
/**
*QRcode二维码生成测试
*QRCodeUtil.QRCodeCreate("http://blog.csdn.net/u014266877","E://qrcode.jpg",15,"E://icon.png");
*/
/**
*QRcode二维码解析测试
*StringqrcodeAnalyze=QRCodeUtil.QRCodeAnalyze("E://qrcode.jpg");
*/
/**
*ZXingCode二维码生成测试
*QRCodeUtil.zxingCodeCreate("http://blog.csdn.net/u014266877",300,300,"E://zxingcode.jpg","jpg");
*/
/**
*ZxingCode二维码解析
*StringzxingAnalyze=QRCodeUtil.zxingCodeAnalyze("E://zxingcode.jpg").toString();
*/
System.out.println("success");
}
}

阅读全文

与java生成qrcode相关的资料

热点内容
爱上北斗星男友在哪个app上看 浏览:413
主力散户派发源码 浏览:663
linux如何修复服务器时间 浏览:55
荣县优途网约车app叫什么 浏览:472
百姓网app截图是什么意思 浏览:222
php如何嵌入html 浏览:809
解压专家怎么传输 浏览:743
如何共享服务器的网络连接 浏览:132
程序员简易表白代码 浏览:166
什么是无线加密狗 浏览:62
国家反诈中心app为什么会弹出 浏览:67
cad压缩图打印 浏览:102
网页打开速度与服务器有什么关系 浏览:863
android开发技术文档 浏览:65
32单片机写程序 浏览:50
三星双清无命令 浏览:838
汉寿小程序源码 浏览:344
易助erp云服务器 浏览:532
修改本地账户管理员文件夹 浏览:419
python爬虫工程师招聘 浏览:285