本文整理汇总了Java中com.google.zxing.common.HybridBinarizer类的典型用法代码示例。如果您正苦于以下问题:Java HybridBinarizer类的具体用法?Java HybridBinarizer怎么用?Java HybridBinarizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HybridBinarizer类属于com.google.zxing.common包,在下文中一共展示了HybridBinarizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: multiple
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
/**
* Decode all barcodes in the image
*/
private String multiple(BufferedImage img) throws NotFoundException, ChecksumException, FormatException {
long begin = System.currentTimeMillis();
LuminanceSource source = new BufferedImageLuminanceSource(img);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
com.google.zxing.Reader reader = new MultiFormatReader();
MultipleBarcodeReader bcReader = new GenericMultipleBarcodeReader(reader);
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
StringBuilder sb = new StringBuilder();
for (Result result : bcReader.decodeMultiple(bitmap, hints)) {
sb.append(result.getText()).append(" ");
}
SystemProfiling.log(null, System.currentTimeMillis() - begin);
log.trace("multiple.Time: {}", System.currentTimeMillis() - begin);
return sb.toString();
}
示例2: convert
import com.google.zxing.common.HybridBinarizer; //导入依赖的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;
}
}
示例3: onPreviewFrame
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
int previewWidth = camera.getParameters().getPreviewSize().width;
int previewHeight = camera.getParameters().getPreviewSize().height;
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(
data, previewWidth, previewHeight, 0, 0, previewWidth,
previewHeight, false);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Reader reader = new QRCodeReader();
try {
Result result = reader.decode(bitmap);
String text = result.getText();
Intent intent = new Intent();
intent.setData(Uri.parse(text));
setResult(RESULT_OK, intent);
finish();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Not Found",
Toast.LENGTH_SHORT).show();
}
}
开发者ID:android-opensource-library-56,项目名称:android-opensource-library-56,代码行数:27,代码来源:BarcodeScanCameraActivity.java
示例4: decode
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
/**
* @param srcImgFilePath
* 要解码的图片地址
* @return {Result}
*/
@SuppressWarnings("finally")
public static Result decode(String srcImgFilePath) {
Result result = null;
BufferedImage image;
try {
File srcFile = new File(srcImgFilePath);
image = ImageIO.read(srcFile);
if (null != image) {
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
result = new MultiFormatReader().decode(bitmap, hints);
} else {
throw new IllegalArgumentException ("Could not decode image.");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return result;
}
}
示例5: decode
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
/**
* 条形码解码
*/
public static String decode(BufferedImage image) {
Result result = null;
try {
if (image == null) {
System.out.println("the decode image may be not exit.");
}
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
result = new MultiFormatReader().decode(bitmap, null);
return result.getText();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例6: decode
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
/**
* 解析二维码
*
* @param file 二维码图片
* @return
* @throws Exception
*/
public static String decode(File file) throws Exception {
BufferedImage image;
image = ImageIO.read(file);
if (image == null) {
return null;
}
BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result;
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
result = new MultiFormatReader().decode(bitmap, hints);
String resultStr = result.getText();
return resultStr;
}
示例7: getRawResult
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
/**
* 获取解码结果
*
* @param bitmap
* @return
*/
public Result getRawResult(Bitmap bitmap) {
if (bitmap == null) {
return null;
}
try {
return multiFormatReader.decodeWithState(new BinaryBitmap(
new HybridBinarizer(new BitmapLuminanceSource(bitmap))));
}
catch (NotFoundException e) {
e.printStackTrace();
}
return null;
}
示例8: decodeQr
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
public static String decodeQr(String filePath) {
String retStr = "";
if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
return "图片路径为空!";
}
try {
BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap bitmap = new BinaryBitmap(binarizer);
HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
retStr = result.getText();
} catch (Exception e) {
logger.error("", e);
}
return retStr;
}
示例9: syncDecodeQRCode
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
/**
* 同步解析bitmap二维码。该方法是耗时操作,请在子线程中调用。
*
* @param bitmap 要解析的二维码图片
* @return 返回二维码图片里的内容 或 null
*/
public static String syncDecodeQRCode(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 source = new RGBLuminanceSource(width, height, pixels);
Result result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source)), HINTS);
return result.getText();
} catch (Exception e) {
return null;
}
}
示例10: decodeQr
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
public static String decodeQr(String filePath) {
String retStr = "";
if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
return "图片路径为空!";
}
try {
BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap bitmap = new BinaryBitmap(binarizer);
HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
retStr = result.getText();
} catch (Exception e) {
e.printStackTrace();
}
return retStr;
}
示例11: decodeWithZxing
import com.google.zxing.common.HybridBinarizer; //导入依赖的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;
}
示例12: analyzeBitmap
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
/**
* 解析二维码图片工具类
*
* @param bitmap
*/
public static String analyzeBitmap(Bitmap bitmap) {
MultiFormatReader multiFormatReader = new MultiFormatReader();
// 解码的参数
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(2);
// 可以解析的编码类型
Vector<BarcodeFormat> decodeFormats = new Vector<BarcodeFormat>();
if (decodeFormats == null || decodeFormats.isEmpty()) {
decodeFormats = new Vector<BarcodeFormat>();
// 这里设置可扫描的类型,我这里选择了都支持
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
// 设置继续的字符编码格式为UTF8
hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
// 设置解析配置参数
multiFormatReader.setHints(hints);
// 开始对图像资源解码
Result rawResult = null;
try {
rawResult = multiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(bitmap))));
} catch (Exception e) {
e.printStackTrace();
}
if (rawResult != null) {
return rawResult.getText();
} else {
return "Failed";
}
}
示例13: scanningImage
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
protected Result scanningImage(Uri path) {
if (path == null || path.equals("")) {
return null;
}
// DecodeHintType 和EncodeHintType
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 设置二维码内容的编码
try {
Bitmap scanBitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
return reader.decode(bitmap1, hints);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例14: decode
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
public static String decode(File file) throws Exception {
BufferedImage image;
image = ImageIO.read(file);
if (image == null) {
return null;
}
CodeImage source = new CodeImage(
image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result;
Hashtable hints = new Hashtable();
hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
result = new MultiFormatReader().decode(bitmap, hints);
String resultStr = result.getText();
return resultStr;
}
示例15: decodes
import com.google.zxing.common.HybridBinarizer; //导入依赖的package包/类
/**
* 解析条形码
*/
public static String decodes(String imgPath) {
BufferedImage image = null;
Result result = null;
try {
image = ImageIO.read(new File(imgPath));
if (image == null) {
System.out.println("the decode image may be not exit.");
}
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
result = new MultiFormatReader().decode(bitmap, null);
return result.getText();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}