0
jsp 파일에서 업로드 된 이미지 파일에서 qrcode를 읽으려고합니다. QRcode를 읽으려면 jxing jar를 사용했습니다.zxing qrcode, 읽기 오류. com.google.zxing.NotFoundException
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Map;
import javax.imageio.ImageIO;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatReader;
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.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
public class GenerateQRCode {
public String readQRCode(String filePath, String charset)
throws FileNotFoundException, IOException, NotFoundException {
Hashtable hintMap = new Hashtable();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
new BufferedImageLuminanceSource(ImageIO.read(new FileInputStream(filePath)))));
**Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap, hintMap);**
return qrCodeResult.getText();
}
}
이에서
코드는 문자열 "결과"에하시면 자동 값을 얻으려고 노력하고있는 방법이다.
String result = rr.readQRCode(tmpFile.getCanonicalPath(), "UTF-8");
위의 굵은 체로 표시된 메소드에서 다음과 같은 오류가 발생합니다. com.google.zxing.NotFoundException
나는 이미 stackoverflow에서 같은 질문을 반복합니다.
http://stackoverflow.com/questions/27770665/error-when-decoding-qr-code
그러나 이에 대한 적절한 응답이 없습니다. 이 코드가 작동할까요? 아니면 대안을 찾아야합니까? 나는 qrcode를 생성하기위한 코드를 완성했다. 파일에서 코드를 읽는 것이 zxing의 문제입니다.
이어야합니다. 실제 예외 텍스트 (스택 추적)를 게시 할 수 있습니까? –