QRCode.jar和google的zxing.jar有什么区别
1个回答
展开全部
二维码与解析种途径我选择用品牌googlezxing
gitHub链接(我用3.0.0已经nio)
Java代码 收藏代码
// 其输图像读取图像类core包
MultiFormatReader
MultiFormatWriter
// 矩阵类javase包
MatrixToImageWriter
pom.xml配置
Xml代码 收藏代码
<project xmlns="" xmlns:xsi=""
xsi:schemaLocation=" ">
4.0.0
com.shihy
qrcode
0.0.1-SNAPSHOT
jar
qrcode
UTF-8
com.google.zxing
core
3.0.0
com.google.zxing
javase
3.0.0
junit
junit
4.10
com.alibaba
fastjson
1.1.29
图像与解析图像测试工具类:
Java代码 收藏代码
package com.polysaas.edu.qrcode;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import org.junit.Test;
import com.alibaba.fastjson.JSONObject;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Binarizer;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.EncodeHintType;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
public class QRCodeTest {
/**
* 图像
*
* @throws WriterException
* @throws IOException
*/
@Test
public void testEncode() throws WriterException, IOException {
String filePath = "D://";
String fileName = "zxing.png";
JSONObject json = new JSONObject();
json.put(
"zxing",
"/javase/src/main/java/com/google/zxing");
json.put("author", "shihy");
String content = json.toJSONString();// 内容
int width = 200; // 图像宽度
int height = 200; // 图像高度
String format = "png";// 图像类型
Map hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
BarcodeFormat.QR_CODE, width, height, hints);// 矩阵
Path path = FileSystems.getDefault().getPath(filePath, fileName);
MatrixToImageWriter.writeToPath(bitMatrix, format, path);// 输图像
System.out.println("输功.");
}
/**
* 解析图像
*/
@Test
public void testDecode() {
String filePath = "D://zxing.png";
BufferedImage image;
try {
image = ImageIO.read(new File(filePath));
LuminanceSource source = new BufferedImageLuminanceSource(image);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Map hints = new HashMap();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
Result result = new MultiFormatReader().decode(binaryBitmap, hints);// 图像进行解码
JSONObject content = JSONObject.parseObject(result.getText());
System.out.println("图片内容: ");
System.out.println("author: " + content.getString("author"));
System.out.println("zxing: " + content.getString("zxing"));
System.out.println("图片格式: ");
System.out.println("encode: " + result.getBarcodeFormat());
} catch (IOException e) {
e.printStackTrace();
} catch (NotFoundException e) {
e.printStackTrace();
}
}
}
gitHub链接(我用3.0.0已经nio)
Java代码 收藏代码
// 其输图像读取图像类core包
MultiFormatReader
MultiFormatWriter
// 矩阵类javase包
MatrixToImageWriter
pom.xml配置
Xml代码 收藏代码
<project xmlns="" xmlns:xsi=""
xsi:schemaLocation=" ">
4.0.0
com.shihy
qrcode
0.0.1-SNAPSHOT
jar
qrcode
UTF-8
com.google.zxing
core
3.0.0
com.google.zxing
javase
3.0.0
junit
junit
4.10
com.alibaba
fastjson
1.1.29
图像与解析图像测试工具类:
Java代码 收藏代码
package com.polysaas.edu.qrcode;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import org.junit.Test;
import com.alibaba.fastjson.JSONObject;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Binarizer;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.EncodeHintType;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
public class QRCodeTest {
/**
* 图像
*
* @throws WriterException
* @throws IOException
*/
@Test
public void testEncode() throws WriterException, IOException {
String filePath = "D://";
String fileName = "zxing.png";
JSONObject json = new JSONObject();
json.put(
"zxing",
"/javase/src/main/java/com/google/zxing");
json.put("author", "shihy");
String content = json.toJSONString();// 内容
int width = 200; // 图像宽度
int height = 200; // 图像高度
String format = "png";// 图像类型
Map hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
BarcodeFormat.QR_CODE, width, height, hints);// 矩阵
Path path = FileSystems.getDefault().getPath(filePath, fileName);
MatrixToImageWriter.writeToPath(bitMatrix, format, path);// 输图像
System.out.println("输功.");
}
/**
* 解析图像
*/
@Test
public void testDecode() {
String filePath = "D://zxing.png";
BufferedImage image;
try {
image = ImageIO.read(new File(filePath));
LuminanceSource source = new BufferedImageLuminanceSource(image);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Map hints = new HashMap();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
Result result = new MultiFormatReader().decode(binaryBitmap, hints);// 图像进行解码
JSONObject content = JSONObject.parseObject(result.getText());
System.out.println("图片内容: ");
System.out.println("author: " + content.getString("author"));
System.out.println("zxing: " + content.getString("zxing"));
System.out.println("图片格式: ");
System.out.println("encode: " + result.getBarcodeFormat());
} catch (IOException e) {
e.printStackTrace();
} catch (NotFoundException e) {
e.printStackTrace();
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询