本文整理匯總了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;
}