當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。