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


Java QRCodeReader.decode方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: decode

import com.google.zxing.qrcode.QRCodeReader; //导入方法依赖的package包/类
public 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);
            log.info("Decoded image successfully, result was : '" + result.getText() + "'");

            return result.getText();
        } catch (ReaderException e) {
            // the data is improperly formatted
            log.debug(e.getMessage());
            log.error("Error while decoding image", e);
        }

        return "";
    }
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:25,代码来源:QRCodeEncoderDecoder.java

示例9: decodeImage

import com.google.zxing.qrcode.QRCodeReader; //导入方法依赖的package包/类
/**
 * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, reuse the same reader
 * objects from one decode to the next.
 */
public static Result decodeImage(byte[] data, int width, int height) {
    // 处理
    Result result = null;
    try {
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
        PlanarYUVLuminanceSource source =
                new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
        /**
         * HybridBinarizer算法使用了更高级的算法,但使用GlobalHistogramBinarizer识别效率确实比HybridBinarizer要高一些。
         *
         * GlobalHistogram算法:(http://kuangjianwei.blog.163.com/blog/static/190088953201361015055110/)
         *
         * 二值化的关键就是定义出黑白的界限,我们的图像已经转化为了灰度图像,每个点都是由一个灰度值来表示,就需要定义出一个灰度值,大于这个值就为白(0),低于这个值就为黑(1)。
         * 在GlobalHistogramBinarizer中,是从图像中均匀取5行(覆盖整个图像高度),每行取中间五分之四作为样本;以灰度值为X轴,每个灰度值的像素个数为Y轴建立一个直方图,
         * 从直方图中取点数最多的一个灰度值,然后再去给其他的灰度值进行分数计算,按照点数乘以与最多点数灰度值的距离的平方来进行打分,选分数最高的一个灰度值。接下来在这两个灰度值中间选取一个区分界限,
         * 取的原则是尽量靠近中间并且要点数越少越好。界限有了以后就容易了,与整幅图像的每个点进行比较,如果灰度值比界限小的就是黑,在新的矩阵中将该点置1,其余的就是白,为0。
         */
        BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
        // BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader2 = new QRCodeReader();
        result = reader2.decode(bitmap1, hints);
    } catch (ReaderException e) {
    }
    return result;
}
 
开发者ID:simplezhli,项目名称:Tesseract-OCR-Scanner,代码行数:33,代码来源:QrUtils.java

示例10: decodeImage

import com.google.zxing.qrcode.QRCodeReader; //导入方法依赖的package包/类
/**
 * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, reuse the same reader
 * objects from one decode to the next.
 */
public static Result decodeImage(byte[] data, int width, int height) {
    // 处理
    Result result = null;
    try {
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
        PlanarYUVLuminanceSource source =
            new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
        /**
         * HybridBinarizer算法使用了更高级的算法,但使用GlobalHistogramBinarizer识别效率确实比HybridBinarizer要高一些。
         * 
         * GlobalHistogram算法:(http://kuangjianwei.blog.163.com/blog/static/190088953201361015055110/)
         * 
         * 二值化的关键就是定义出黑白的界限,我们的图像已经转化为了灰度图像,每个点都是由一个灰度值来表示,就需要定义出一个灰度值,大于这个值就为白(0),低于这个值就为黑(1)。
         * 在GlobalHistogramBinarizer中,是从图像中均匀取5行(覆盖整个图像高度),每行取中间五分之四作为样本;以灰度值为X轴,每个灰度值的像素个数为Y轴建立一个直方图,
         * 从直方图中取点数最多的一个灰度值,然后再去给其他的灰度值进行分数计算,按照点数乘以与最多点数灰度值的距离的平方来进行打分,选分数最高的一个灰度值。接下来在这两个灰度值中间选取一个区分界限,
         * 取的原则是尽量靠近中间并且要点数越少越好。界限有了以后就容易了,与整幅图像的每个点进行比较,如果灰度值比界限小的就是黑,在新的矩阵中将该点置1,其余的就是白,为0。
         */
        BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
        // BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader2 = new QRCodeReader();
        result = reader2.decode(bitmap1, hints);
    } catch (ReaderException e) {
    }
    return result;
}
 
开发者ID:yiwent,项目名称:Mobike,代码行数:33,代码来源:QrUtils.java

示例11: scanningImage

import com.google.zxing.qrcode.QRCodeReader; //导入方法依赖的package包/类
protected Result scanningImage(String path) {
    if (StringUtil.isBlank(path)) {
        return null;
    }
    // DecodeHintType 和EncodeHintType
    Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
    hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 设置二维码内容的编码
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true; // 先获取原大小
    scanBitmap = BitmapFactory.decodeFile(path, options);
    options.inJustDecodeBounds = false; // 获取新的大小

    int sampleSize = (int) (options.outHeight / (float) 200);

    if (sampleSize <= 0)
        sampleSize = 1;
    options.inSampleSize = sampleSize;
    scanBitmap = BitmapFactory.decodeFile(path, options);
    int width = scanBitmap.getWidth(), height = scanBitmap.getHeight();
    int[] pixels = new int[width * height];
    scanBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    scanBitmap.recycle();
    scanBitmap = null;
    RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
    BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeReader();
    try {
        return reader.decode(bitmap1, hints);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:jianliaoim,项目名称:talk-android,代码行数:34,代码来源:ScannerActivity.java

示例12: decodeQRCodeImage

import com.google.zxing.qrcode.QRCodeReader; //导入方法依赖的package包/类
/**
 * 解码 QRCode 图片,解析出其内容
 *
 * @param imageURI QRCode 图片 URI
 * @return 解析后的内容
 * @throws IOException
 */
public static String decodeQRCodeImage(URI imageURI) throws IOException {

    BufferedImage bufferedImage = ImageReader.readImage(imageURI);
    LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeReader();
    try {
        Result result = reader.decode(bitmap);
        return result.getText();
    } catch (ReaderException e) {
        e.printStackTrace();
    }
    return "";
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:22,代码来源:MyQRCodeUtils.java

示例13: getStringFromQRCode

import com.google.zxing.qrcode.QRCodeReader; //导入方法依赖的package包/类
public static String getStringFromQRCode(String path) {
        String httpString = null;

        Bitmap bmp = convertToBitmap(path);
        byte[] data = getYUV420sp(bmp.getWidth(), bmp.getHeight(), bmp);
        // 处理
        try {
            Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
//            hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
            hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
            hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
            PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data,
                    bmp.getWidth(),
                    bmp.getHeight(),
                    0, 0,
                    bmp.getWidth(),
                    bmp.getHeight(),
                    false);
            BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
            QRCodeReader reader2= new QRCodeReader();
            Result result = reader2.decode(bitmap1, hints);

            httpString = result.getText();
        } catch (Exception e) {
            e.printStackTrace();
        }

        bmp.recycle();
        bmp = null;

        return httpString;
    }
 
开发者ID:react-native-component,项目名称:react-native-smart-barcode,代码行数:33,代码来源:DecodeUtil.java

示例14: decodePureBitmap

import com.google.zxing.qrcode.QRCodeReader; //导入方法依赖的package包/类
public static Result decodePureBitmap(Bitmap bmp) throws FormatException, ChecksumException, NotFoundException {
    int width = bmp.getWidth(), height = bmp.getHeight();
    int[] pixels = new int[width * height];
    bmp.getPixels(pixels, 0, width, 0, 0, width, height);
    RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
    QRCodeReader reader = new QRCodeReader();
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
    Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
    hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
    return reader.decode(binaryBitmap, hints);
}
 
开发者ID:timberdoodle,项目名称:TimberdoodleApp,代码行数:12,代码来源:QRReaderWriterTests.java

示例15: doInBackground

import com.google.zxing.qrcode.QRCodeReader; //导入方法依赖的package包/类
@Override
protected Result doInBackground(Uri... params) {
    if (params == null || params.length != 1) {
        return null;
    }

    try {
        InputStream inputStream = QRScanActivity.this.getContentResolver().openInputStream(params[0]);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        Rect padding = new Rect(0, 0, 0, 0);
        BitmapFactory.decodeStream(inputStream, null, options);
        inputStream.close();
        int minLength = Math.min(options.outWidth, options.outHeight);
        int MAX = 512; // 图片短边不超过 512
        if (minLength > MAX) {
            options.inSampleSize = minLength / MAX;
        }
        options.inJustDecodeBounds = false;
        // 流打开后只能用一次, 需要重新获取
        inputStream = QRScanActivity.this.getContentResolver().openInputStream(params[0]);
        // 对图片裁剪后再扫码, 否则花的时间太长
        Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, options);
        if (bitmap == null) {
            return null;
        }

        int width = bitmap.getWidth(), height = bitmap.getHeight();
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
        bitmap.recycle();

        RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader = new QRCodeReader();
        Result result = reader.decode(bBitmap);
        return result;
    } catch (Exception e) {
        Log.e(TAG, "can not open file", e);
        return null;
    }
}
 
开发者ID:huang303513,项目名称:Coding-Android,代码行数:43,代码来源:QRScanActivity.java


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