本文整理匯總了Java中com.google.zxing.ReaderException類的典型用法代碼示例。如果您正苦於以下問題:Java ReaderException類的具體用法?Java ReaderException怎麽用?Java ReaderException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ReaderException類屬於com.google.zxing包,在下文中一共展示了ReaderException類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processImage
import com.google.zxing.ReaderException; //導入依賴的package包/類
public IAnswerData processImage(Image image)
throws ImageProcessingException {
MonochromeBitmapSource source = new LCDUIImageMonochromeBitmapSource(
image);
Reader reader = new QRCodeReader();
Hashtable hints = new Hashtable();
// hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
try {
Result result = reader.decode(source, hints);
if ((result != null) && (result.getText() != null)) {
String scannedCode = result.getText();
return new StringData(scannedCode);
} else {
throw new ImageProcessingException("Barcode scanning failed");
}
} catch (ReaderException re) {
throw new ImageProcessingException("Barcode scanning failed");
}
}
示例2: detectMulti
import com.google.zxing.ReaderException; //導入依賴的package包/類
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException {
BitMatrix image = getImage();
ResultPointCallback resultPointCallback =
hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback);
FinderPatternInfo[] infos = finder.findMulti(hints);
if (infos.length == 0) {
throw NotFoundException.getNotFoundInstance();
}
List<DetectorResult> result = new ArrayList<>();
for (FinderPatternInfo info : infos) {
try {
result.add(processFinderPatternInfo(info));
} catch (ReaderException e) {
// ignore
}
}
if (result.isEmpty()) {
return EMPTY_DETECTOR_RESULTS;
} else {
return result.toArray(new DetectorResult[result.size()]);
}
}
示例3: decodeWithZxing
import com.google.zxing.ReaderException; //導入依賴的package包/類
public String decodeWithZxing(byte[] data, int width, int height, Rect crop) {
MultiFormatReader multiFormatReader = new MultiFormatReader();
multiFormatReader.setHints(changeZXingDecodeDataMode());
Result rawResult = null;
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height,
crop.left, crop.top, crop.width(), crop.height(), false);
if (source != null) {
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
}
return rawResult != null ? rawResult.getText() : null;
}
示例4: decodeWithZxing
import com.google.zxing.ReaderException; //導入依賴的package包/類
public Result decodeWithZxing(Bitmap bitmap) {
MultiFormatReader multiFormatReader = new MultiFormatReader();
multiFormatReader.setHints(changeZXingDecodeDataMode());
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
Result rawResult = null;
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(binaryBitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
return rawResult;
}
示例5: doInBackground
import com.google.zxing.ReaderException; //導入依賴的package包/類
@Override
protected Result doInBackground(Void... params) {
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(3);
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, listener);
MultiFormatReader multiFormatReader = new MultiFormatReader();
multiFormatReader.setHints(hints);
long start = System.currentTimeMillis();
Result rawResult = null;
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
mBitmap = luminanceSource.renderCroppedGreyScaleBitmap();
long end = System.currentTimeMillis();
Log.d("DecodeThread", "Decode use " + (end - start) + "ms");
} catch (ReaderException re) {
} finally {
multiFormatReader.reset();
}
return rawResult;
}
示例6: detectMulti
import com.google.zxing.ReaderException; //導入依賴的package包/類
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException {
BitMatrix image = getImage();
ResultPointCallback resultPointCallback =
hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback);
FinderPatternInfo[] infos = finder.findMulti(hints);
if (infos.length == 0) {
throw NotFoundException.getNotFoundInstance();
}
List<DetectorResult> result = new ArrayList<DetectorResult>();
for (FinderPatternInfo info : infos) {
try {
result.add(processFinderPatternInfo(info));
} catch (ReaderException e) {
// ignore
}
}
if (result.isEmpty()) {
return EMPTY_DETECTOR_RESULTS;
} else {
return result.toArray(new DetectorResult[result.size()]);
}
}
示例7: checkFormat
import com.google.zxing.ReaderException; //導入依賴的package包/類
private void checkFormat(File file, BarcodeFormat format) throws IOException {
Reader reader = new MultiFormatReader();
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(file))));
Result result;
try {
result = reader.decode(bitmap);
} catch (ReaderException ex) {
throw new IOException(ex);
}
assertEquals(format, result.getBarcodeFormat());
}
示例8: detectMulti
import com.google.zxing.ReaderException; //導入依賴的package包/類
public DetectorResult[] detectMulti(Map<DecodeHintType, ?> hints) throws NotFoundException {
BitMatrix image = getImage();
ResultPointCallback resultPointCallback =
hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback);
FinderPatternInfo[] infos = finder.findMulti(hints);
if (infos.length == 0) {
throw NotFoundException.getNotFoundInstance();
}
List<DetectorResult> result = new ArrayList<>();
for (FinderPatternInfo info : infos) {
try {
result.add(processFinderPatternInfo(info));
} catch (ReaderException e) {
// ignore
}
}
if (result.isEmpty()) {
return EMPTY_DETECTOR_RESULTS;
} else {
return result.toArray(new DetectorResult[result.size()]);
}
}
示例9: detectMulti
import com.google.zxing.ReaderException; //導入依賴的package包/類
public DetectorResult[] detectMulti(Map<DecodeHintType, ?> hints) throws NotFoundException {
BitMatrix image = getImage();
ResultPointCallback resultPointCallback =
hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback);
FinderPatternInfo[] infos = finder.findMulti(hints);
if (infos.length == 0) {
throw NotFoundException.getNotFoundInstance();
}
List<DetectorResult> result = new ArrayList<DetectorResult>();
for (FinderPatternInfo info : infos) {
try {
result.add(processFinderPatternInfo(info));
} catch (ReaderException e) {
// ignore
}
}
if (result.isEmpty()) {
return EMPTY_DETECTOR_RESULTS;
} else {
return result.toArray(new DetectorResult[result.size()]);
}
}
示例10: decode
import com.google.zxing.ReaderException; //導入依賴的package包/類
private String decode(byte[] data, int width, int height) {
ScannerManager manager = mManager.get();
if (manager == null) {
return null;
}
Rect rect = manager.getFramingRectInPreview();
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data,
width, height, rect.left, rect.top, rect.right, rect.bottom, false);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
try {
Result result = reader.decode(bitmap, mHints);
return result.getText();
} catch (ReaderException e) {
// Ignore as we will repeatedly decode the preview frame
return null;
}
}
示例11: testFlowWithSetKeyData
import com.google.zxing.ReaderException; //導入依賴的package包/類
public void testFlowWithSetKeyData() {
for (int i = 0; i < groupKeyList.size(); i++) {
Bitmap bmp = qrReaderWriter.createQrCode(cipher, groupKeyList.get(i), Instant.now(), 200, 200);
try {
Result decoded = QRReaderWriterTests.decodePureBitmap(bmp);
String temporary = decoded.getText();
GroupQRReaderWriter.ScannedGroupKey key = qrReaderWriter.parseCode(temporary, cipher);
SecretKey result = cipher.byteArrayToSecretKey(key.getKey().getEncoded());
assertEquals("Key #" + i + " was not recognized : ", groupKeyList.get(i), result);
} catch (ReaderException e) {
Log.d("KeyToImageAndBackTests", "Key #" + i + " was ignored due to a Reader Error");
keyIgnoredCounter[i]++;
}
}
}
示例12: assertCorrectImage2binary
import com.google.zxing.ReaderException; //導入依賴的package包/類
private static void assertCorrectImage2binary(String fileName, String expected)
throws IOException, NotFoundException {
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
BufferedImage image = ImageIO.read(path.toFile());
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
List<ExpandedPair> pairs;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row);
} catch (ReaderException re) {
fail(re.toString());
return;
}
BitArray binary = BitArrayBuilder.buildBitArray(pairs);
assertEquals(expected, binary.toString());
}
示例13: assertCorrectImage2string
import com.google.zxing.ReaderException; //導入依賴的package包/類
private static void assertCorrectImage2string(String fileName, String expected)
throws IOException, NotFoundException {
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
BufferedImage image = ImageIO.read(path.toFile());
BinaryBitmap binaryMap =
new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
Result result;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
result = rssExpandedReader.decodeRow(rowNumber, row, null);
} catch (ReaderException re) {
fail(re.toString());
return;
}
assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
assertEquals(expected, result.getText());
}
示例14: assertCorrectImage2result
import com.google.zxing.ReaderException; //導入依賴的package包/類
private static void assertCorrectImage2result(String fileName, ExpandedProductParsedResult expected)
throws IOException, NotFoundException {
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
BufferedImage image = ImageIO.read(path.toFile());
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
Result theResult;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
theResult = rssExpandedReader.decodeRow(rowNumber, row, null);
} catch (ReaderException re) {
fail(re.toString());
return;
}
assertSame(BarcodeFormat.RSS_EXPANDED, theResult.getBarcodeFormat());
ParsedResult result = ResultParser.parseResult(theResult);
assertEquals(expected, result);
}