本文整理汇总了Java中com.google.zxing.MultiFormatReader.decodeWithState方法的典型用法代码示例。如果您正苦于以下问题:Java MultiFormatReader.decodeWithState方法的具体用法?Java MultiFormatReader.decodeWithState怎么用?Java MultiFormatReader.decodeWithState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.zxing.MultiFormatReader
的用法示例。
在下文中一共展示了MultiFormatReader.decodeWithState方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeWithZxing
import com.google.zxing.MultiFormatReader; //导入方法依赖的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;
}
示例2: analyzeBitmap
import com.google.zxing.MultiFormatReader; //导入方法依赖的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";
}
}
示例3: decodeWithZxing
import com.google.zxing.MultiFormatReader; //导入方法依赖的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;
}
示例4: handleQRCodeFormBitmap
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
public static Result handleQRCodeFormBitmap(Bitmap bitmap) {
RGBLuminanceSource source = new RGBLuminanceSource(bitmap);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
MultiFormatReader multiFormatReader = new MultiFormatReader();
Hashtable<DecodeHintType, Object> hints = new Hashtable<>(2);
Vector<BarcodeFormat> decodeFormats = new Vector<>();
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
multiFormatReader.setHints(hints);
Result result = null;
try {
result = multiFormatReader.decodeWithState(binaryBitmap);
} catch (NotFoundException e) {
LogHelper.e(e);
e.printStackTrace();
}
return result;
}
示例5: doInBackground
import com.google.zxing.MultiFormatReader; //导入方法依赖的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: decode
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
@NonNull
@SuppressWarnings("SuspiciousNameCombination")
public Result decode(@NonNull MultiFormatReader reader) throws ReaderException {
int imageWidth = mImageSize.getX();
int imageHeight = mImageSize.getY();
byte[] image;
int width;
int height;
if (mOrientation == 0) {
image = mImage;
width = imageWidth;
height = imageHeight;
} else {
image = Utils.rotateNV21(mImage, imageWidth, imageHeight, mOrientation);
if (mOrientation == 90 || mOrientation == 270) {
width = imageHeight;
height = imageWidth;
} else {
width = imageWidth;
height = imageHeight;
}
}
Rect frameRect = Utils.getImageFrameRect(mSquareFrame, width, height, mPreviewSize, mViewSize);
return reader.decodeWithState(new BinaryBitmap(new HybridBinarizer(
new PlanarYUVLuminanceSource(image, width, height, frameRect.getLeft(), frameRect.getTop(),
frameRect.getWidth(), frameRect.getHeight(), mReverseHorizontal))));
}
示例7: analyzeBitmap
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
public static void analyzeBitmap(Bitmap bitmap, AnalyzeCallback analyzeCallback) {
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) {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeSuccess(bitmap, rawResult.getText());
}
} else {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeFailed();
}
}
}
示例8: analyzeBitmap
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
/**
* 解析二维码图片工具类
*/
public static void analyzeBitmap(String path, AnalyzeCallback analyzeCallback) {
/**
* 首先判断图片的大小,若图片过大,则执行图片的裁剪操作,防止OOM
*/
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // 先获取原大小
Bitmap mBitmap = BitmapFactory.decodeFile(path, options);
options.inJustDecodeBounds = false; // 获取新的大小
int sampleSize = (int) (options.outHeight / (float) 400);
if (sampleSize <= 0)
sampleSize = 1;
options.inSampleSize = sampleSize;
mBitmap = BitmapFactory.decodeFile(path, options);
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(mBitmap))));
} catch (Exception e) {
e.printStackTrace();
}
if (rawResult != null) {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeSuccess(mBitmap, rawResult.getText());
}
} else {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeFailed();
}
}
}
示例9: scanningImage
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
public Result scanningImage(String path) {
if (TextUtils.isEmpty(path)) {
return null;
}
multiFormatReader = new MultiFormatReader();
//BufferedImage image =null;
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
multiFormatReader.setHints(hints);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap scanBitmap = BitmapFactory.decodeFile(path, options);
options.inJustDecodeBounds = false;
int sampleSize = (int) (options.outHeight / (float) 200);
if (sampleSize <= 0)
sampleSize = 1;
scanBitmap = BitmapFactory.decodeFile(path, options);
RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
try {
return multiFormatReader.decodeWithState(bitmap1);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
return null;
}
示例10: analyzeBitmap
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
/**
* 解析二维码图片工具类
* @param mBitmap
* @param analyzeCallback
*/
public static void analyzeBitmap(Bitmap mBitmap, AnalyzeCallback analyzeCallback) {
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(mBitmap))));
} catch (Exception e) {
e.printStackTrace();
}
if (rawResult != null) {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeSuccess(mBitmap, rawResult.getText());
}
} else {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeFailed();
}
}
}
示例11: analyzeBitmap
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
/**
* 解析二维码图片工具类
* @param analyzeCallback
*/
public static void analyzeBitmap(String path, AnalyzeCallback analyzeCallback) {
/**
* 首先判断图片的大小,若图片过大,则执行图片的裁剪操作,防止OOM
*/
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // 先获取原大小
Bitmap mBitmap = BitmapFactory.decodeFile(path, options);
options.inJustDecodeBounds = false; // 获取新的大小
int sampleSize = (int) (options.outHeight / (float) 400);
if (sampleSize <= 0)
sampleSize = 1;
options.inSampleSize = sampleSize;
mBitmap = BitmapFactory.decodeFile(path, options);
MultiFormatReader multiFormatReader = new MultiFormatReader();
// 解码的参数
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(2);
// 可以解析的编码类型
Vector<BarcodeFormat> decodeFormats = new Vector<BarcodeFormat>();
if (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(mBitmap))));
} catch (Exception e) {
e.printStackTrace();
}
if (rawResult != null) {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeSuccess(mBitmap, rawResult.getText());
}
} else {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeFailed();
}
}
}
示例12: analyzeBitmap
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
/**
* 解析二维码图片工具类
*
* @param analyzeCallback AnalyzeCallback
*/
public static void analyzeBitmap(@NonNull String path, @NonNull AnalyzeCallback analyzeCallback) {
/**
* 首先判断图片的大小,若图片过大,则执行图片的裁剪操作,防止OOM
*/
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // 先获取原大小
Bitmap mBitmap = BitmapFactory.decodeFile(path, options);
options.inJustDecodeBounds = false; // 获取新的大小
int sampleSize = (int) (options.outHeight / (float) 400);
if (sampleSize <= 0)
sampleSize = 1;
options.inSampleSize = sampleSize;
mBitmap = BitmapFactory.decodeFile(path, options);
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(mBitmap))));
} catch (Exception e) {
e.printStackTrace();
}
if (rawResult != null) {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeSuccess(mBitmap, rawResult.getText());
}
} else {
if (analyzeCallback != null) {
analyzeCallback.onAnalyzeFailed();
}
}
}
示例13: decodeFromPhoto
import com.google.zxing.MultiFormatReader; //导入方法依赖的package包/类
/**
* 解析图片中的 二维码 或者 条形码
*
* @param photo 待解析的图片
* @return Result 解析结果,解析识别时返回NULL
*/
public static Result decodeFromPhoto(Bitmap photo) {
Result rawResult = null;
if (photo != null) {
Bitmap smallBitmap = RxImageTool.zoomBitmap(photo, photo.getWidth() / 2, photo.getHeight() / 2);// 为防止原始图片过大导致内存溢出,这里先缩小原图显示,然后释放原始Bitmap占用的内存
photo.recycle(); // 释放原始图片占用的内存,防止out of memory异常发生
MultiFormatReader multiFormatReader = new MultiFormatReader();
// 解码的参数
Hashtable<DecodeHintType, Object> hints = new Hashtable<>(2);
// 可以解析的编码类型
Vector<BarcodeFormat> decodeFormats = new Vector<>();
if (decodeFormats.isEmpty()) {
decodeFormats = new Vector<>();
Vector<BarcodeFormat> PRODUCT_FORMATS = new Vector<>(5);
PRODUCT_FORMATS.add(BarcodeFormat.UPC_A);
PRODUCT_FORMATS.add(BarcodeFormat.UPC_E);
PRODUCT_FORMATS.add(BarcodeFormat.EAN_13);
PRODUCT_FORMATS.add(BarcodeFormat.EAN_8);
// PRODUCT_FORMATS.add(BarcodeFormat.RSS14);
Vector<BarcodeFormat> ONE_D_FORMATS = new Vector<>(PRODUCT_FORMATS.size() + 4);
ONE_D_FORMATS.addAll(PRODUCT_FORMATS);
ONE_D_FORMATS.add(BarcodeFormat.CODE_39);
ONE_D_FORMATS.add(BarcodeFormat.CODE_93);
ONE_D_FORMATS.add(BarcodeFormat.CODE_128);
ONE_D_FORMATS.add(BarcodeFormat.ITF);
Vector<BarcodeFormat> QR_CODE_FORMATS = new Vector<>(1);
QR_CODE_FORMATS.add(BarcodeFormat.QR_CODE);
Vector<BarcodeFormat> DATA_MATRIX_FORMATS = new Vector<>(1);
DATA_MATRIX_FORMATS.add(BarcodeFormat.DATA_MATRIX);
// 这里设置可扫描的类型,我这里选择了都支持
decodeFormats.addAll(ONE_D_FORMATS);
decodeFormats.addAll(QR_CODE_FORMATS);
decodeFormats.addAll(DATA_MATRIX_FORMATS);
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
// 设置继续的字符编码格式为UTF8
// hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
// 设置解析配置参数
multiFormatReader.setHints(hints);
// 开始对图像资源解码
try {
rawResult = multiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(smallBitmap))));
} catch (Exception e) {
e.printStackTrace();
}
}
return rawResult;
}