909422229_java后台与jquer qrcode前台生成二维码教程

google 二维码生成:

、什么是二维码:

二维码就是一个存储、传递信息的一个矩形条码。

二维条码具有储存量大、保密性高、追踪性高、抗损性强、备援性大、成本便宜等特性,

这些特性特别适用于表单、安全保密、追踪、证照、存货盘点、资料备援等方面。

、二维码作用:

1、传递信息。如个人名片、产品介绍、质量跟踪等;

2、电商平台入口。顾客线下扫描商品广告的二维码,然后在线购物;

3、移动支付。顾客扫描二维码进入支付平台,使用手机进行支付;

4、凭证。比如团购的消费凭证,会议的入场凭证等。

 

、二维码的优点:

)数据容量更大

)超越了字母数字的限制

)条形码相对尺寸小

)具有抗损毁能力

四、Java生成二维码:

1.利用google ZXing生成二维码:导入google Zxing jar

/**

 * 生成二维码

 * google ZXing

 * @throws WriterException

 * @throws IOException

 */

public static void testEncode()throws WriterException, IOException {

String filePath ="D://";

String fileName ="zxing.png";

String content = "测试zxing生成二维码";

int width = 300; // 图像宽度

int height = 300; // 图像高度

String format = "png";//图像类型

Map<EncodeHintType, Object>hints = new HashMap<EncodeHintType, Object>();

hints.put(EncodeHintType.CHARACTER_SET,"UTF-8");

BitMatrix bitMatrix = newMultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,hints);// 生成矩阵

Path path =FileSystems.getDefault().getPath(filePath, fileName);

MatrixToImageWriter.writeToPath(bitMatrix,format, path);// 输出图像

System.out.println("输出成功.");

}

五、解析二维码:

/**

 * 解析二维码

 */

public static void testDecode() {

String filePath ="D://1515470883.png";

BufferedImage image;

try {

image = ImageIO.read(newFile(filePath));

LuminanceSource source = newBufferedImageLuminanceSource(image);

Binarizer binarizer = newHybridBinarizer(source);

BinaryBitmap binaryBitmap = newBinaryBitmap(binarizer);

Map<DecodeHintType, Object>hints = new HashMap<DecodeHintType, Object>();

hints.put(DecodeHintType.CHARACTER_SET,"UTF-8");

Result result = newMultiFormatReader().decode(binaryBitmap, hints);// 对图像进行解码

System.out.println("图片中内容:  ");

System.out.println("author " +result.getText());

System.out.println("图片中格式:  ");

System.out.println("encode " +result.getBarcodeFormat());

} catch (IOException e) {

e.printStackTrace();

} catch (NotFoundException e) {

e.printStackTrace();

}

}


;使用jquery qrcode生成

<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/jquery.qrcode.min.js"></script>
<title>Insert title here</title>
<script type="text/javascript">
//可以指定使用table 与canvas 生成二维码
jQuery(function() {
//jQuery('#output').qrcode("http://www.jq22.com");//简单的版本
//详细设置
jQuery('#output').qrcode({
render : "canvas", //也可以替换为table
//render: "table",
width : 100, //指定二维码宽度
height : 100, //指定二维码高度
foreground : "#C00",//指定颜色
background : "#FFF",//颜色
text : "http://www.jq22.com" 指定二维码内容
//encodeURI("http://中文中文")   使用中文生成,防止乱码。使用encodeURI包裹
});
})
</script>
</head>
<body>
<div id="output"></div>
</body>
</html>

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

75888丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值