com.google.zxing.MultiFormatReader Java Examples
The following examples show how to use
com.google.zxing.MultiFormatReader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultDecoderFactory.java From Viewer with Apache License 2.0 | 6 votes |
@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); }
Example #2
Source File: DecodeTask.java From code-scanner with MIT License | 6 votes |
@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)); }
Example #3
Source File: BarcodeUtils.java From code-scanner with MIT License | 6 votes |
/** * 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; } }
Example #4
Source File: ZxingHelper.java From seezoon-framework-all with Apache License 2.0 | 6 votes |
/** * 解析二维码 * * @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; }
Example #5
Source File: CameraPreview.java From Android-Barcode-Reader with MIT License | 6 votes |
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(); }
Example #6
Source File: DecodeUtils.java From myapplication with Apache License 2.0 | 6 votes |
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; }
Example #7
Source File: ZxingHandler.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 条形码解码 * * @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; }
Example #8
Source File: ZxingHandler.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 二维码解码 * * @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; }
Example #9
Source File: Decoder.java From Viewer with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #10
Source File: DecodeUtils.java From SimplifyReader with Apache License 2.0 | 6 votes |
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; }
Example #11
Source File: AbsCodec.java From StarBarcode with Apache License 2.0 | 6 votes |
/** * 使用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; }
Example #12
Source File: DecodeUtils.java From SimplifyReader with Apache License 2.0 | 6 votes |
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; }
Example #13
Source File: BitmapDecoder.java From BarcodeScanner with Apache License 2.0 | 6 votes |
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); }
Example #14
Source File: QRCodeCameraDecode.java From ZxingSupport with Apache License 2.0 | 6 votes |
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); }
Example #15
Source File: QrCodeReader.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
@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(); } }
Example #16
Source File: QRCodeDecode.java From ZxingSupport with Apache License 2.0 | 5 votes |
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); }
Example #17
Source File: ZXingQRCodeUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 解析二维码图片 * @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); } } } }); }
Example #18
Source File: AbsCodec.java From StarBarcode with Apache License 2.0 | 5 votes |
/** * 使用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; }
Example #19
Source File: ScannerActivity.java From CrazyDaily with Apache License 2.0 | 5 votes |
@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, "这个码真扫不了"); } } }
Example #20
Source File: DecodeHandler.java From RxTools-master with Apache License 2.0 | 5 votes |
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; }
Example #21
Source File: QrCodeHelper.java From adamant-android with GNU General Public License v3.0 | 5 votes |
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; }
Example #22
Source File: BarcodeUtils.java From code-scanner with MIT License | 5 votes |
@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; }
Example #23
Source File: Utils.java From code-scanner with MIT License | 5 votes |
@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(); } }
Example #24
Source File: DecodeHandler.java From Tesseract-OCR-Scanner with Apache License 2.0 | 5 votes |
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); }
Example #25
Source File: ZXDecoder.java From CamView with Apache License 2.0 | 5 votes |
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); }
Example #26
Source File: CodeUtils.java From UVCCameraZxing with Apache License 2.0 | 5 votes |
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(); } } }
Example #27
Source File: QRCodeUtil.java From JavaWeb with Apache License 2.0 | 5 votes |
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; }
Example #28
Source File: QRCode.java From jeewx-api with Apache License 2.0 | 5 votes |
/** * 解析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()); } }
Example #29
Source File: DecodeHandler.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
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); }
Example #30
Source File: DecodeHandler.java From GOpenSource_AppKit_Android_AS with MIT License | 4 votes |
public DecodeHandler(CaptureActivity activity, Map<DecodeHintType, Object> hints) { multiFormatReader = new MultiFormatReader(); multiFormatReader.setHints(hints); this.activity = activity; }