使用Zxing编码解码

更新时间:2023-07-01 15:54:45 阅读: 评论: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;
tidehunter
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;
afford的用法try {
image = ad(file); parachute什么意思
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());
}
}

}

turnoverMyTestEncode


import java.io.File;
stylishimport java.io.IOException;
refurbishedimport java.io.UnsupportedEncodingException;
mi man chi什么意思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) { ext
e1.printStackTrace();
}
}

}

本文发布于:2023-07-01 15:54:45,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/163805.html

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

标签:编码   天涯   碧草   结婚   职务   内容   作战   公司
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图