找不到实体类啊
我表示找不到这个类 MatrixToImageWritoter 我的jar包里没有?还是要单独导入一个实体类?网上的实体类又没有topath的方法...... 求助
我表示找不到这个类 MatrixToImageWritoter 我的jar包里没有?还是要单独导入一个实体类?网上的实体类又没有topath的方法...... 求助
2016-08-23
你是jar包没有导入成功吧 我按着老师做的 没有问题
这个是我写的 你可以看看是不是这样
package com.imooc.zxing;
import com.google.zxing.*;
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;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.nio.file.Path;
import java.util.HashMap;
/**
* 生成二维码
*/
public class CreateQRCode {
public static void main(String[] args) {
createQRCode();
// readQRCode();
}
private static void readQRCode() {
try {
MultiFormatReader formatReader = new MultiFormatReader();
File file = new File("e:/image.png");
BufferedImage image = null;
image = ImageIO.read(file);
HashMap hashMap = new HashMap();
hashMap.put(EncodeHintType.CHARACTER_SET, "utf-8");
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
Result result = formatReader.decode(binaryBitmap, hashMap);
System.out.println("解析结果:"+result.toString());
System.out.println("二维码格式类型:"+result.getBarcodeFormat());
System.out.println("二维码文本:"+result.getText());
} catch (Exception e) {
e.printStackTrace();
}
}
private static void createQRCode() {
int width = 300;
int height = 300;
String format = "png";
String content = "www.baidu.com";
//定义二维码的参数
HashMap hashMap = new HashMap();
hashMap.put(EncodeHintType.CHARACTER_SET, "utf-8");
hashMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
hashMap.put(EncodeHintType.MARGIN, 5);
try {
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height);
Path file = new File("e:/img.png").toPath();
MatrixToImageWriter.writeToPath(bitMatrix, format, file);
} catch (Exception e) {
e.printStackTrace();
}
}
}举报