使用Zxing编码解码

更新时间:2023-06-15 00:43:31 阅读: 评论:0

使用ZXing 编码和解码
GoogleJavaJ2SE
MyTestDecode

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;

import javax.imageio.ImageIO;
妻子你辛苦了
le.zxing.BinaryBitmap;
le.zxing.DecodeHintType;
le.zxing.EncodeHintType;
le.zxing.LuminanceSource;
le.zxing.MultiFormatReader;
le.zxing.Reader;
le.zxing.ReaderException;
le.zxing.Result;
le.zxing.client.j2.BufferedImageLuminanceSource;
HybridBinarizer;

public class MyTestDecode {
择天记莫雨/**
* @paramargs
* @throws ReaderException
* @throws InterruptedException
*/
public static void main(String[] args) throws ReaderException,
InterruptedException {
Reader reader = new MultiFormatReader();
String imgPath = "D:\\QRCodeTest\\TestQRCode1.png";
File file = new File(imgPath);

BufferedImage image;
try {
劳动日记500字image = ad(file);
if (image == null) {
System.out.println("Could not decode image");
}
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result;
Hashtable hints= new Hashtable();
hints.put(DecodeHintType.CHARACTER_SET, "GBK");
result = new MultiFormatReader().decode(bitmap,hints);
String resultStr = Text();
System.out.println(resultStr);

} catch (IOExceptionioe) {
System.out.String());
} catch (ReaderException re) {
System.out.String());
盛湾镇}
}

}

MyTestEncode


import java.io.File;
import java.io.IOException;
班务工作总结import java.io.UnsupportedEncodingException;
import java.util.Hashtable;

le.zxing.BarcodeFormat;
le.zxing.EncodeHintType;
le.zxing.MultiFormatWriter_ED;
le.zxing.WriterException;
le.zxing.client.j2.MatrixToImageWriter;
ByteMatrix;

public class MyTestEncode {
public static void main(String[] args) throws Exception {
try {
String str = "CN:男;COP:公司;ZW:职务";// 二维码内容
String path = "D:\\QRCodeTest\\TestQRCode1.png";
Hashtable hints= new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, "GBK"); 运动项目英语
ByteMatrixbyteMatrix;

byteMatrix = new MultiFormatWriter_ED().encode(str,
BarcodeFormat.QR_CODE, 200, 200,hints);

珍惜的诗句File file = new File(path);
MatrixToImageWriter.writeToFile(byteMatrix, "png", file);
} catch (IOException e) {
e.printStackTrace();
} catch (WriterException e1) {
赞美大草原的诗句
e1.printStackTrace();
}
}

}

本文发布于:2023-06-15 00:43:31,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1038845.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:编码   班务   赞美   日记
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图