类com.google.zxing.MultiFormatReader源码实例Demo

下面列出了怎么用com.google.zxing.MultiFormatReader的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: BarcodeScanner   文件: BitmapDecoder.java
public BitmapDecoder(Context context) {

		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);

	}
 
源代码2 项目: StarBarcode   文件: AbsCodec.java
/**
 * 使用YUV解析bitmap
 *
 * @param data
 * @param width
 * @param height
 * @param hintTypeMap
 * @return
 */
private Result decodeFromYUV(int[] data, int width, int height, Map<DecodeHintType, ?> hintTypeMap) {
    Result result = null;
    byte[] yuv = convertRGBToYuv(data, new byte[width * height], width, height);
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(yuv, width, height, 0, 0, width, height, false);
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
    try {
        result = new MultiFormatReader().decode(binaryBitmap, hintTypeMap);
    } catch (NotFoundException e) {
        //使用GlobalHistogramBinarizer算法进行解析
        try {
            result = new MultiFormatReader().decode(new BinaryBitmap(new GlobalHistogramBinarizer(source)), hintTypeMap);
        } catch (NotFoundException e1) {
            e1.printStackTrace();
        }
    }
    return result;
}
 
源代码3 项目: seezoon-framework-all   文件: ZxingHelper.java
/**
 * 解析二维码
 * 
 * @param file
 *            二维码图片
 * @return
 * @throws Exception
 */
public static String decode(InputStream in) throws Exception {
	BufferedImage image = ImageIO.read(in);
	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();
	in.close();
	return resultStr;
}
 
源代码4 项目: code-scanner   文件: BarcodeUtils.java
/**
 * Decode barcode from YUV pixels array
 *
 * @param pixels            YUV image data
 * @param width             Image width
 * @param height            Image height
 * @param rotation          Degrees to rotate image before decoding (only 0, 90, 180 or 270 are allowed)
 * @param reverseHorizontal Reverse image horizontally before decoding
 * @param hints             Decoder hints
 * @return Decode result, if barcode was decoded successfully, {@code null} otherwise
 * @see DecodeHintType
 */
@Nullable
@SuppressWarnings("SuspiciousNameCombination")
public static Result decodeYuv(@NonNull final byte[] pixels, final int width, final int height,
        @Rotation final int rotation, final boolean reverseHorizontal,
        @Nullable final Map<DecodeHintType, ?> hints) {
    Objects.requireNonNull(pixels);
    final byte[] rotatedPixels = Utils.rotateYuv(pixels, width, height, rotation);
    final int rotatedWidth;
    final int rotatedHeight;
    if (rotation == ROTATION_90 || rotation == ROTATION_270) {
        rotatedWidth = height;
        rotatedHeight = width;
    } else {
        rotatedWidth = width;
        rotatedHeight = height;
    }
    final MultiFormatReader reader = createReader(hints);
    try {
        return Utils.decodeLuminanceSource(reader,
                new PlanarYUVLuminanceSource(rotatedPixels, rotatedWidth, rotatedHeight, 0, 0,
                        rotatedWidth, rotatedHeight, reverseHorizontal));
    } catch (final ReaderException e) {
        return null;
    }
}
 
源代码5 项目: code-scanner   文件: DecodeTask.java
@Nullable
@SuppressWarnings("SuspiciousNameCombination")
public Result decode(@NonNull final MultiFormatReader reader) throws ReaderException {
    int imageWidth = mImageSize.getX();
    int imageHeight = mImageSize.getY();
    final int orientation = mOrientation;
    final byte[] image = Utils.rotateYuv(mImage, imageWidth, imageHeight, orientation);
    if (orientation == 90 || orientation == 270) {
        final int width = imageWidth;
        imageWidth = imageHeight;
        imageHeight = width;
    }
    final Rect frameRect =
            Utils.getImageFrameRect(imageWidth, imageHeight, mViewFrameRect, mPreviewSize,
                    mViewSize);
    final int frameWidth = frameRect.getWidth();
    final int frameHeight = frameRect.getHeight();
    if (frameWidth < 1 || frameHeight < 1) {
        return null;
    }
    return Utils.decodeLuminanceSource(reader,
            new PlanarYUVLuminanceSource(image, imageWidth, imageHeight, frameRect.getLeft(),
                    frameRect.getTop(), frameWidth, frameHeight, mReverseHorizontal));
}
 
源代码6 项目: Android-Barcode-Reader   文件: CameraPreview.java
public CameraPreview(Context context, Camera camera) {
    super(context);
    mCamera = camera;
    mContext = context;
    mHolder = getHolder();
    mHolder.addCallback(this);
    // deprecated setting, but required on Android versions prior to 3.0
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    Parameters params = mCamera.getParameters();
    
    mWidth = 640;
    mHeight = 480;
    
    params.setPreviewSize(mWidth, mHeight); 
    mCamera.setParameters(params);
    
    mMultiFormatReader = new MultiFormatReader();
    
    mDialog =  new AlertDialog.Builder(mContext).create();
}
 
源代码7 项目: myapplication   文件: DecodeUtils.java
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;
}
 
源代码8 项目: Shop-for-JavaWeb   文件: ZxingHandler.java
/**
 * 条形码解码
 * 
 * @param imgPath
 * @return String
 */
public static String decode(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;
}
 
源代码9 项目: Shop-for-JavaWeb   文件: ZxingHandler.java
/**
 * 二维码解码
 * 
 * @param imgPath
 * @return String
 */
public static String decode2(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));

		Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
		hints.put(DecodeHintType.CHARACTER_SET, "GBK");

		result = new MultiFormatReader().decode(bitmap, hints);
		return result.getText();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
源代码10 项目: Viewer   文件: DefaultDecoderFactory.java
@Override
public Decoder createDecoder(Map<DecodeHintType, ?> baseHints) {
    Map<DecodeHintType, Object> hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);

    hints.putAll(baseHints);

    if(this.hints != null) {
        hints.putAll(this.hints);
    }

    if(this.decodeFormats != null) {
        hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
    }

    if (characterSet != null) {
        hints.put(DecodeHintType.CHARACTER_SET, characterSet);
    }

    MultiFormatReader reader = new MultiFormatReader();
    reader.setHints(hints);

    return new Decoder(reader);
}
 
源代码11 项目: Viewer   文件: Decoder.java
/**
 * Decode a binary bitmap.
 *
 * @param bitmap the binary bitmap
 * @return a Result or null
 */
protected Result decode(BinaryBitmap bitmap) {
    possibleResultPoints.clear();
    try {
        if (reader instanceof MultiFormatReader) {
            // Optimization - MultiFormatReader's normal decode() method is slow.
            return ((MultiFormatReader) reader).decodeWithState(bitmap);
        } else {
            return reader.decode(bitmap);
        }
    } catch (Exception e) {
        // Decode error, try again next frame
        return null;
    } finally {
        reader.reset();
    }
}
 
源代码12 项目: SimplifyReader   文件: DecodeUtils.java
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;
}
 
源代码13 项目: SimplifyReader   文件: DecodeUtils.java
public String 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);

    if (source != null) {
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
        try {
            rawResult = multiFormatReader.decodeWithState(binaryBitmap);
        } catch (ReaderException re) {
            // continue
        } finally {
            multiFormatReader.reset();
        }
    }

    return rawResult != null ? rawResult.getText() : null;
}
 
源代码14 项目: ZxingSupport   文件: QRCodeCameraDecode.java
public QRCodeCameraDecode(CameraManager cameraManager,ResultPointCallback resultPointCallback){
    this.mCameraManger = cameraManager;
    hints = new Hashtable<>(3);

    Vector<BarcodeFormat> decodeFormats = new Vector<>();
    decodeFormats.addAll(QRCodeDecodeFormat.ONE_D_FORMATS);
    decodeFormats.addAll(QRCodeDecodeFormat.QR_CODE_FORMATS);
    decodeFormats.addAll(QRCodeDecodeFormat.DATA_MATRIX_FORMATS);
    decodeFormats.addAll(QRCodeDecodeFormat.PRODUCT_FORMATS);
    hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
    if (resultPointCallback != null) {
        hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
    }

    multiFormatReader = new MultiFormatReader();
    multiFormatReader.setHints(hints);
}
 
源代码15 项目: StarBarcode   文件: AbsCodec.java
/**
 * 使用RGB解析bitmap
 *
 * @param data
 * @param width
 * @param height
 * @param hintTypeMap
 * @return
 */
private Result decodeFromRGB(int[] data, int width, int height, Map<DecodeHintType, ?> hintTypeMap) {
    RGBLuminanceSource source = new RGBLuminanceSource(width, height, data);
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
    try {
        return new MultiFormatReader().decode(binaryBitmap, hintTypeMap);
    } catch (NotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
源代码16 项目: DevUtils   文件: ZXingQRCodeUtils.java
/**
 * 解析二维码图片
 * @param bitmap         待解析的二维码图片
 * @param qrScanCallBack 解析结果回调
 */
public static void decodeQRCode(final Bitmap bitmap, final QRScanCallBack qrScanCallBack) {
    if (bitmap == null) {
        if (qrScanCallBack != null) {
            qrScanCallBack.onResult(false, null, new Exception("bitmap is null"));
        }
        return;
    }
    // 开始解析
    DevThreadManager.getInstance(5).execute(new Runnable() {
        @Override
        public void run() {
            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)), DECODE_HINTS);
                // 触发回调
                if (qrScanCallBack != null) {
                    qrScanCallBack.onResult((result != null), result, null);
                }
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "decodeQRCode");
                // 触发回调
                if (qrScanCallBack != null) {
                    qrScanCallBack.onResult(false, null, e);
                }
            }
        }
    });
}
 
源代码17 项目: adamant-android   文件: QrCodeHelper.java
public String parse(InputStream imageStream) {
    final Bitmap bMap = BitmapFactory.decodeStream(imageStream);
    String contents = null;

    int[] intArray = new int[bMap.getWidth()*bMap.getHeight()];
    bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());

    LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(), intArray);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    Map<DecodeHintType, Object> tmpHintsMap = new EnumMap<DecodeHintType, Object>(
            DecodeHintType.class);
    tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    tmpHintsMap.put(DecodeHintType.POSSIBLE_FORMATS,
            EnumSet.allOf(BarcodeFormat.class));
    tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);

    Reader reader = new MultiFormatReader();
    Result result = null;
    try {
        result = reader.decode(bitmap, tmpHintsMap);
        contents = result.getText();
    } catch (NotFoundException | ChecksumException | FormatException e) {
        e.printStackTrace();
    }

    return contents;
}
 
源代码18 项目: bisq   文件: QrCodeReader.java
@Override
public void run() {
    try {
        if (!webCam.isOpen())
            webCam.open();

        isRunning = true;
        Result result;
        BufferedImage bufferedImage;
        while (isRunning) {
            bufferedImage = webCam.getImage();
            if (bufferedImage != null) {
                WritableImage writableImage = SwingFXUtils.toFXImage(bufferedImage, null);
                imageView.setImage(writableImage);
                imageView.setRotationAxis(new Point3D(0.0, 1.0, 0.0));
                imageView.setRotate(180.0);

                LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
                BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

                try {
                    result = new MultiFormatReader().decode(bitmap);
                    isRunning = false;
                    String qrCode = result.getText();
                    UserThread.execute(() -> resultHandler.accept(qrCode));
                } catch (NotFoundException ignore) {
                    // No qr code in image...
                }
            }
        }
    } catch (Throwable t) {
        log.error(t.toString());
    } finally {
        webCam.close();
    }
}
 
源代码19 项目: RxTools-master   文件: DecodeHandler.java
DecodeHandler(ActivityScanerCode activity) {
    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>();

        Vector<BarcodeFormat> PRODUCT_FORMATS = new Vector<BarcodeFormat>(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<BarcodeFormat>(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<BarcodeFormat>(1);
        QR_CODE_FORMATS.add(BarcodeFormat.QR_CODE);
        Vector<BarcodeFormat> DATA_MATRIX_FORMATS = new Vector<BarcodeFormat>(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);

    multiFormatReader.setHints(hints);
    this.activity = activity;
}
 
源代码20 项目: CrazyDaily   文件: ScannerActivity.java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == REQUEST_SELECT_PICTURE) {
        final Uri selectedUri = data.getData();
        if (selectedUri != null) {
            try {
                Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), selectedUri);
                if (bitmap != null) {
                    int width = bitmap.getWidth();
                    int height = bitmap.getHeight();
                    int[] dataArr = new int[width * height];
                    bitmap.getPixels(dataArr, 0, width, 0, 0, width, height);
                    Decoder decoder = new Decoder(new MultiFormatReader());
                    Result result = decoder.decode(new RGBLuminanceSource(width, height, dataArr));
                    if (result != null) {
                        BrowserActivity.start(this, result.getText());
                    } else {
                        SnackbarUtil.show(this, "这个码真扫不了");
                    }
                    bitmap.recycle();
                } else {
                    SnackbarUtil.show(this, "这个码真扫不了");
                }
            } catch (Exception e) {
                SnackbarUtil.show(this, "这个码真扫不了");
            }
        } else {
            SnackbarUtil.show(this, "这个码真扫不了");
        }
    }
}
 
源代码21 项目: code-scanner   文件: BarcodeUtils.java
@NonNull
private static MultiFormatReader createReader(@Nullable final Map<DecodeHintType, ?> hints) {
    final MultiFormatReader reader = new MultiFormatReader();
    if (hints != null) {
        reader.setHints(hints);
    } else {
        reader.setHints(Collections
                .singletonMap(DecodeHintType.POSSIBLE_FORMATS, CodeScanner.ALL_FORMATS));
    }
    return reader;
}
 
源代码22 项目: code-scanner   文件: Utils.java
@Nullable
public static Result decodeLuminanceSource(@NonNull final MultiFormatReader reader,
        @NonNull final LuminanceSource luminanceSource) throws ReaderException {
    try {
        return reader.decodeWithState(new BinaryBitmap(new HybridBinarizer(luminanceSource)));
    } catch (final NotFoundException e) {
        return reader.decodeWithState(
                new BinaryBitmap(new HybridBinarizer(luminanceSource.invert())));
    } finally {
        reader.reset();
    }
}
 
源代码23 项目: Tesseract-OCR-Scanner   文件: DecodeHandler.java
DecodeHandler(ScannerActivity activity) {
    this.mActivity = activity;
    mMultiFormatReader = new MultiFormatReader();
    mHints = new Hashtable<>();
    mHints.put(DecodeHintType.CHARACTER_SET, "utf-8");
    mHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    Collection<BarcodeFormat> barcodeFormats = new ArrayList<>();
    barcodeFormats.add(BarcodeFormat.CODE_39);
    barcodeFormats.add(BarcodeFormat.CODE_128); // 快递单常用格式39,128
    barcodeFormats.add(BarcodeFormat.QR_CODE); //扫描格式自行添加
    mHints.put(DecodeHintType.POSSIBLE_FORMATS, barcodeFormats);
}
 
源代码24 项目: CamView   文件: ZXDecoder.java
public ZXDecoder()
{
    reader = new MultiFormatReader();

    hints.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class));
    hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
    hints.put(DecodeHintType.TRY_HARDER, true);

    reader.setHints(hints);
}
 
源代码25 项目: QrCodeScanner   文件: DecodeHandler.java
DecodeHandler(QrCodeActivity activity) {
    this.mActivity = activity;
    mMultiFormatReader = new MultiFormatReader();
    mHints = new Hashtable<>();
    mHints.put(DecodeHintType.CHARACTER_SET, "utf-8");
    mHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    Collection<BarcodeFormat> barcodeFormats = new ArrayList<>();
    barcodeFormats.add(BarcodeFormat.QR_CODE);
    barcodeFormats.add(BarcodeFormat.CODE_39);
    barcodeFormats.add(BarcodeFormat.CODE_93);
    barcodeFormats.add(BarcodeFormat.CODE_128);
    mHints.put(DecodeHintType.POSSIBLE_FORMATS, barcodeFormats);
}
 
源代码26 项目: UVCCameraZxing   文件: CodeUtils.java
public static void analyzeBitmap(Bitmap bitmap, AnalyzeCallback analyzeCallback) {
    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);
    // 设置继续的字符编码格式为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();
        }
    }
}
 
源代码27 项目: JavaWeb   文件: QRCodeUtil.java
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<>();
    hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
    result = new MultiFormatReader().decode(bitmap, hints);
    String resultStr = result.getText();
    return resultStr;
}
 
源代码28 项目: jeewx-api   文件: QRCode.java
/**
 * 解析QRCode二维码
 */
@SuppressWarnings("unchecked")
public static void decode(File file) {
	try {
		BufferedImage image;
		try {
			image = ImageIO.read(file);
			if (image == null) {
				System.out.println("Could not decode image");
			}
			LuminanceSource source = new BufferedImageLuminanceSource(image);
			BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
			Result result;
			@SuppressWarnings("rawtypes")
			Hashtable hints = new Hashtable();
			//解码设置编码方式为:utf-8
			hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
			result = new MultiFormatReader().decode(bitmap, hints);
			String resultStr = result.getText();
			System.out.println("解析后内容:" + resultStr);
		} catch (IOException ioe) {
			System.out.println(ioe.toString());
		} catch (ReaderException re) {
			System.out.println(re.toString());
		}
	} catch (Exception ex) {
		System.out.println(ex.toString());
	}
}
 
源代码29 项目: ZxingSupport   文件: QRCodeDecode.java
private QRCodeDecode(Builder builder) {
    mMultiFormatReader = new MultiFormatReader();
    Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
    Collection<BarcodeFormat> formats = new ArrayList<>();
    formats.add(BarcodeFormat.QR_CODE);
    hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
    hints.put(DecodeHintType.CHARACTER_SET, builder.mCharset);
    mMultiFormatReader.setHints(hints);
}
 
源代码30 项目: QrCodeLib   文件: DecodeHandler.java
DecodeHandler(CaptureActivity activity, Hashtable<DecodeHintType, Object> hints) {
    multiFormatReader = new MultiFormatReader();
    multiFormatReader.setHints(hints);
    this.activity = activity;
}
 
 类所在包
 同包方法