本文整理汇总了Java中com.google.zxing.MultiFormatReader.decode方法的典型用法代码示例。如果您正苦于以下问题:Java MultiFormatReader.decode方法的具体用法?Java MultiFormatReader.decode怎么用?Java MultiFormatReader.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.zxing.MultiFormatReader
的用法示例。
在下文中一共展示了MultiFormatReader.decode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
public static String convert(Bitmap bitmap) {
try {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
RGBLuminanceSource rgbLuminanceSource = new RGBLuminanceSource(
width, height, pixels);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
rgbLuminanceSource));
HashMap<DecodeHintType, Object> hints = new HashMap<DecodeHintType, Object>();
hints.put(DecodeHintType.CHARACTER_SET, DEFAULT_CHARSET);
MultiFormatReader multiFormatReader = new MultiFormatReader();
Result result = multiFormatReader.decode(binaryBitmap, hints);
return result.getText();
} catch (Exception e) {
return null;
}
}
示例2: readImage
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
/**
* Reads the message from a code.
*/
private String readImage(final Exchange exchange, final InputStream stream) throws Exception {
final MultiFormatReader reader = new MultiFormatReader();
final BufferedInputStream in = exchange.getContext()
.getTypeConverter()
.mandatoryConvertTo(BufferedInputStream.class, stream);
final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(in))));
final Result result = reader.decode(bitmap, readerHintMap);
// write the found barcode format into the header
exchange.getOut().setHeader(Barcode.BARCODE_FORMAT, result.getBarcodeFormat());
return result.getText();
}
示例3: text
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
@Test
public void text() throws WriterException, IOException, NotFoundException {
QRCode code = LQRT.qr(TEXT, ErrorCorrectionLevel.L, null);
ImageQRPainter iqrp = new ImageQRPainter();
iqrp.paint(code);
BinaryBitmap bb = imageToBitmap(iqrp.getImage());
MultiFormatReader mfr = new MultiFormatReader();
Result res = mfr.decode(bb);
assertEquals(TEXT, res.getText());
assertEquals(BarcodeFormat.QR_CODE, res.getBarcodeFormat());
}