使用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();
}
}
}