- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章基于google zxing的Java二维码生成与解码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了Java二维码生成与解码的具体代码,供大家参考,具体内容如下 。
1、添加Maven依赖(解码时需要上传二维码图片,所以需要依赖文件上传包) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<!-- google二维码工具 -->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>
3.1
.
0
</version>
</dependency>
<!-- 文件上传 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>
1.3
.
1
</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>
2.4
</version>
</dependency>
|
2、创建生成二维码接口(接口参数为二维码内容,通常是URL) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/**
* 生成二维码
* google zxing 实现
* @param text
* @return
*/
@RequestMapping
(value =
"/qrcode/encode"
, method = RequestMethod.POST)
public
void
encodeQrCode(String text, HttpServletResponse response) {
try
{
// 设置二维码参数
Map<EncodeHintType, Object> hints =
new
HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET,
"UTF-8"
);
BitMatrix bitMatrix =
new
MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE,
150
,
150
, hints);
//返回二维码
MatrixToImageWriter.writeToStream(bitMatrix,
"jpg"
, response.getOutputStream());
}
catch
(Exception e) {
e.printStackTrace();
}
}
|
3、创建二维码解码接口(直接返回解码后的二维码内容) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
/**
* 二维码图片解码
* google zxing 实现
* @param qrImg
* @return
*/
@RequestMapping
(value =
"/qrcode/decode"
, method = RequestMethod.POST)
public
String decodeQrCode(MultipartFile qrImg) {
if
(!qrImg.isEmpty()) {
try
{
BufferedImage image = ImageIO.read(qrImg.getInputStream());
BinaryBitmap binaryBitmap =
new
BinaryBitmap(
new
HybridBinarizer(
new
BufferedImageLuminanceSource(image)));
// 定义二维码的参数:
HashMap<DecodeHintType, Object> hints =
new
HashMap<>();
// 定义字符集
hints.put(DecodeHintType.CHARACTER_SET,
"utf-8"
);
Result result =
new
MultiFormatReader().decode(binaryBitmap, hints);
return
result.getText();
}
catch
(Exception e) {
e.printStackTrace();
}
}
return
null
;
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
最后此篇关于基于google zxing的Java二维码生成与解码的文章就讲到这里了,如果你想了解更多关于基于google zxing的Java二维码生成与解码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我正在为我的移动应用程序项目使用 worklight。我的问题是,我不知道在哪里可以找到这些文件(zxing-all-in-one.cpp 和 zxing-all-in-one.h),用于在 Xcod
我在 .NET 上使用 zxing 取得了巨大成功,并试图获得解码 QR 条码的最佳速度(我有很多事情要做——1.8M)。我正在使用的代码(它的一部分): // Create Barcode deco
我使用 com.google.zxing.qrcode.QRCodeWriter 对数据进行编码,并使用 com.google.zxing.client.j2se.MatrixToImageWrite
我项目的包名是 com.mohit.verma 我不想在外部安装 zxing 条码扫描仪应用程序。 我只想使用库文件。 那么我应该在哪里更改包名称? 任何帮助,将不胜感激... 我的代码如下: ba
我正在尝试使用说明 here 构建 Zxing android 应用程序(不是库) .我能够构建 jar 但无法构建应用程序本身。当我运行 mvn package android:apk 时,出现以下
本文整理了Java中jsc.kit.zxing.zxing.ui.ZXingFragment类的一些代码示例,展示了ZXingFragment类的具体用法。这些代码示例主要来源于Github/Stac
我正在开发一个通过 ZXing 在 Android 上扫描条形码的应用程序。我关注这个tutorial . 但是当我运行我的应用程序时,出现 NoClassDefFoundError 并且应用程序已完
我已经下载了适用于 Android 的 Zxing Barcode Scanner 代码,但我在源代码中找不到软件包 com.google.zxing。我认为该项目缺少库或 JAR 文件。谁能帮我找到
我正在尝试做一个应用程序来为多个条形码的信息创建一个最终的二维码我扫描过的。我想知道您如何将 ZXing 库导入您的代码?假设用户已经在他们的手机中安装了 ZXing 扫描仪,我是否可以只连接应用程序
我正在尝试使用 ZXing 2.1 库获得成功的结果。我在 Mac OS X 10.7.5 上使用 Java 1.6。我能够编码文本但不能解码任何图像。相反,我得到的只是 com.google.zxi
我正在使用 ZXing.Net 0.16.4.0 解码保存在 中的二维码文件'wwwroot/qrr' 文件夹,但我收到编译时错误: Cannot convert from 'System.Drawi
我已经将 Zxing 作为库集成并在我的应用程序中使用。我调用 Intent intent = new Intent("com.google.zxing.client.android.SCAN");
我正在尝试将 zxing 扫描仪合并到我的 Angular 应用程序中,在按照在线指南进行操作后,它出现了以下我似乎无法解决的错误, 'zxing-scanner' 不是已知元素: 如果“zxing-
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我想实现来自 https://github.com/dm77/barcodescanner 的条码扫描器库.像这样运行项目后出现错误 java.lang.NoSuchFieldError: No st
我使用此代码生成我的二维码 ZXing.Net ( http://zxingnet.codeplex.com/ ) IBarcodeWriter writer = new BarcodeWriter
我想使用 ZXing 库制作一个二维码扫描器。在我的 build.gradle 中,我添加了以下代码: repositories { mavenCentral() maven {
我正在试验 ResultPoints,它返回与图像中条形码相关的点。 对于二维码,ResultPoints 返回一组 4 个点,它们是二维码每个角的四个框的坐标。 当我对条码进行同样的实验时,它返回两
我正在开发一个 android 应用程序,在其中我生成数据矩阵并允许用户使用 zxing 输入它们来扫描它们。 但是,出现了一个许可证问题,询问 zxing 扫描的所有格式是否都可用开源。 这与应用程
我将 ZXing.Net.Mobile 用于这样的表单 var scanPage = new ZXingScannerPage();
我是一名优秀的程序员,十分优秀!