当前位置: 首页>>代码示例>>Java>>正文


Java QRCodeReader类代码示例

本文整理汇总了Java中com.google.zxing.qrcode.QRCodeReader的典型用法代码示例。如果您正苦于以下问题:Java QRCodeReader类的具体用法?Java QRCodeReader怎么用?Java QRCodeReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QRCodeReader类属于com.google.zxing.qrcode包,在下文中一共展示了QRCodeReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doInBackground

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
/**
 * Searches Bitmap image for a QR code, and returns the String representation
 * of it if a valid QR code was found.
 * Returns empty String if no valid QR code was found.
 *
 * @param bitmap The Bitmap to decode
 * @return The string representation of the Bitmap, or "" if no valid QR code was found
 */
@Override
protected String doInBackground(BinaryBitmap... bitmap) {
    String decodedText;
    // get QR reader
    final Reader reader = new QRCodeReader();
    // try to decode QR code
    try {
        // get Result from decoder
        final Result result = reader.decode(bitmap[0]);
        // get text from Result
        decodedText = result.getText();
    } catch (Exception e) {
        // set text to blank, no QR code found
        decodedText = "";
    }
    // return text
    return decodedText;
}
 
开发者ID:cscd-488,项目名称:event-app,代码行数:27,代码来源:DecodeImageTask.java

示例2: processImage

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
public IAnswerData processImage(Image image)
        throws ImageProcessingException {
    MonochromeBitmapSource source = new LCDUIImageMonochromeBitmapSource(
            image);
    Reader reader = new QRCodeReader();
    Hashtable hints = new Hashtable();
    // hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);

    try {
        Result result = reader.decode(source, hints);
        if ((result != null) && (result.getText() != null)) {
            String scannedCode = result.getText();
            return new StringData(scannedCode);
        } else {
            throw new ImageProcessingException("Barcode scanning failed");
        }
    } catch (ReaderException re) {
        throw new ImageProcessingException("Barcode scanning failed");
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:21,代码来源:ZXingBarcodeProcessingService.java

示例3: onPreviewFrame

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的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: scanningImage

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的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;
}
 
开发者ID:guzhigang001,项目名称:Zxing,代码行数:21,代码来源:CaptureActivity.java

示例5: readQrCode

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
/**
 * 读取二维码
 * @param qrCodeFile
 * @return
 */
public String readQrCode(File qrCodeFile){
	String ret = null;
	try {			
		QRCodeReader reader = new QRCodeReader();
		BufferedImage image = ImageIO.read(qrCodeFile);
		LuminanceSource source = new BufferedImageLuminanceSource(image);
		Binarizer binarizer = new HybridBinarizer(source);
		BinaryBitmap imageBinaryBitmap = new BinaryBitmap(binarizer);
		Result result = reader.decode(imageBinaryBitmap);
		ret = result.getText();
	} catch (IOException |NotFoundException | ChecksumException | FormatException e) {
		Exceptions.printException(e);
	}
	return ret;		
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:21,代码来源:QrCodeUtil.java

示例6: processFrame

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
@Override
public void processFrame(final Frame frame) {
    MAIN_THREAD_HANDLER.post(new Runnable() {
        @Override
        public void run() {
            try {
                reader = new QRCodeReader();
                LuminanceSource ls = new PlanarYUVLuminanceSource(
                        frame.image, frame.size.width, frame.size.height,
                        0, 0, frame.size.width, frame.size.height, false);
                Result r = reader.decode(new BinaryBitmap(new HybridBinarizer(ls)));
                sendTextToActivity(r.getText());
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
开发者ID:freeotp,项目名称:freeotp-android,代码行数:20,代码来源:ScanFrameProcessor.java

示例7: decode_qr

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
/**
 * Writes decoded message to Decoded.txt
 * @param f Input QRCode image
 */
public void decode_qr(String f)
{
	try
	{			
		tv= (TextView)findViewById(R.id.dqr);
		tv.setText("");
		Bitmap bmp=BitmapFactory.decodeFile(f); //import QRCode image file
		int width = bmp.getWidth(), height = bmp.getHeight();
        int[] pixels = new int[width * height];
        bmp.getPixels(pixels, 0, width, 0, 0, width, height);
        bmp.recycle();
	 	bmp = null;
        RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); 
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));	       
		Result qr_result = new QRCodeReader().decode(bitmap);
		tv.setText("Successfully Decoded!\n");
		tv.append("Decoded file is at:\n");
		write_to_file(qr_result.getText().toString());
	}
	catch(Exception e)
	{
		Log.create_log(e, getApplicationContext());
	}
}
 
开发者ID:montimaj,项目名称:PROJECT_QR,代码行数:29,代码来源:DecodeQR.java

示例8: scanningImage

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
/**
 * 扫描二维码图片的方法
 * 
 * @param path
 * @return
 */
public Result scanningImage(String path) {
	try {
		if (TextUtils.isEmpty(path)) {
			return null;
		}
		Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
		hints.put(DecodeHintType.CHARACTER_SET, "UTF8"); // 设置二维码内容的编码

		InputStream is = new FileInputStream(path);
		BitmapFactory.Options options = new BitmapFactory.Options();
		options.inJustDecodeBounds = false;
		// width,hight设为原来的十分一
		options.inSampleSize = 10;
		scanBitmap = BitmapFactory.decodeStream(is, null, options);
		RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
		BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
		QRCodeReader reader = new QRCodeReader();
		return reader.decode(bitmap, hints);

	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:cxbiao,项目名称:Android_Study_Demos,代码行数:31,代码来源:CaptureActivity.java

示例9: decode

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
/**
 * Decodes a QR code from a BufferedImage object.
 * 
 * @param image
 * @return a Result object containing the decoded data or information about
 *         an unsuccessful decoding attempt
 * @throws Exception
 */
private Result decode(BufferedImage image) throws Exception {

	// create a luminance source from the BufferedImage
	LuminanceSource lumSource = new BufferedImageLuminanceSource(image);
	// create a binary bitmap from the luminance source. a Binarizer
	// converts luminance data to 1 bit data.
	BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(lumSource));

	// a reader for decoding
	QRCodeReader reader = new QRCodeReader();

	// attempt decoding and return result
	Hashtable<DecodeHintType, Boolean> hints = new Hashtable<DecodeHintType, Boolean>();
	hints.put(DecodeHintType.TRY_HARDER, true);
	return reader.decode(bitmap, hints);
}
 
开发者ID:karoliina,项目名称:qr-code-reader,代码行数:25,代码来源:QRDecoder.java

示例10: decode

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
public static String decode(BufferedImage image) {

        // convert the image to a binary bitmap source
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        // decode the barcode
        QRCodeReader reader = new QRCodeReader();

        try {
            @SuppressWarnings("rawtypes")
            Hashtable hints = new Hashtable();
            Result result = reader.decode(bitmap, hints);


            return result.getText();
        } catch (ReaderException e) {
            // the data is improperly formatted
        }

        return "";
    }
 
开发者ID:bither,项目名称:bither-desktop-java,代码行数:23,代码来源:QRCodeEncoderDecoder.java

示例11: decode

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
private String decode(byte[] data, int width, int height) {
    ScannerManager manager = mManager.get();
    if (manager == null) {
        return null;
    }
    Rect rect = manager.getFramingRectInPreview();
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data,
            width, height, rect.left, rect.top, rect.right, rect.bottom, false);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeReader();
    try {
        Result result = reader.decode(bitmap, mHints);
        return result.getText();
    } catch (ReaderException e) {
        // Ignore as we will repeatedly decode the preview frame
        return null;
    }
}
 
开发者ID:googlesamples,项目名称:attendee-checkin,代码行数:19,代码来源:ScannerManager.java

示例12: setHints

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
/**
 * This method adds state to the MultiFormatReader. By setting the hints once, subsequent calls
 * to decodeWithState(image) can reuse the same set of readers without reallocating memory. This
 * is important for performance in continuous scan clients.
 *
 * @param hints The set of hints to use for subsequent calls to decode(image)
 */
public void setHints(Map<DecodeHintType,?> hints) {
  this.hints = hints;

  // boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
  @SuppressWarnings("unchecked")
  Collection<BarcodeFormat> formats =
      hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS);
  Collection<Reader> readers = new ArrayList<Reader>();
  if (formats != null) {
    if (formats.contains(BarcodeFormat.QR_CODE)) {
      readers.add(new QRCodeReader());
    }
  }
  if (readers.isEmpty()) {
    readers.add(new QRCodeReader());
  }
  this.readers = readers.toArray(new Reader[readers.size()]);
}
 
开发者ID:ourbeehive,项目名称:AndPlug,代码行数:26,代码来源:MultiFormatReader.java

示例13: onSurfaceTextureAvailable

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
    mCamera = getCameraInstance();
    setCameraDisplayOrientation();

    try {
        mReader = new QRCodeReader();

        setPreviewParameters(mCamera);

        mCamera.setPreviewTexture(surface);
        mCamera.setPreviewCallback(mCameraPreviewCallback);
        mCamera.setErrorCallback(mCameraErrorCallback);

        mCamera.startPreview();
    } catch (Exception e) {
        Log.e(TAG, "Failed to init preview: " + e.getLocalizedMessage());
    }

    // mTextureView.setVisibility(View.INVISIBLE);
    // mTextureView.setAlpha(0.5f);


    webView.getView().setBackgroundColor(0x00000000);
    webView.getView().bringToFront();
}
 
开发者ID:asennikov,项目名称:BarcodeScannerPlugin,代码行数:26,代码来源:BarcodeScanner.java

示例14: onCreateView

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_decoder, container, false);
    mQrReader = new QRCodeReader();

    mTextureView = new AutoFitTextureView(getActivity());
    layout = (RelativeLayout) rootView.findViewById(R.id.fragment_decoder_layout);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            if (layout.getChildAt(0) == mTextureView) return;
            layout.addView(mTextureView, 0);
            startBackgroundThread();
        }
    }, 700);
    return rootView;
}
 
开发者ID:Gutyn,项目名称:camera2QRcodeReader,代码行数:21,代码来源:FragmentDecoder.java

示例15: readQRCode

import com.google.zxing.qrcode.QRCodeReader; //导入依赖的package包/类
/**
 * Versucht aus dem �bergeben BufferedImage ein QR Code zu finden und �bersetzt dieses in einen String.
 * 
 * @param qrcodeImage : BufferedImage 
 * @return String mit dem Inhalt des QRCodes
 * @throws Exception 
 */
private static String readQRCode(BufferedImage qrcodeImage) throws Exception{
	//Die Parameter anlegen
	Hashtable<DecodeHintType, Object> hintMap = new Hashtable<DecodeHintType, Object>();
       hintMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
       
	//Bild zu BinaryBitmap verwandeln
	BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(qrcodeImage);
	BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

	//QR Leser initialisieren...
	QRCodeReader reader = new QRCodeReader();
	Result result;
	//...und lesen:
	result = reader.decode(bitmap,hintMap);
	
	return result.getText();
}
 
开发者ID:SecUSo,项目名称:EasyVote,代码行数:25,代码来源:VotingQRCode.java


注:本文中的com.google.zxing.qrcode.QRCodeReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。