當前位置: 首頁>>代碼示例>>Java>>正文


Java MultiFormatReader類代碼示例

本文整理匯總了Java中com.google.zxing.MultiFormatReader的典型用法代碼示例。如果您正苦於以下問題:Java MultiFormatReader類的具體用法?Java MultiFormatReader怎麽用?Java MultiFormatReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MultiFormatReader類屬於com.google.zxing包,在下文中一共展示了MultiFormatReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initializeFromIntent

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
/**
 * Convenience method to initialize camera id, decode formats and prompt message from an intent.
 *
 * @param intent the intent, as generated by IntentIntegrator
 */
public void initializeFromIntent(Intent intent) {
    // Scan the formats the intent requested, and return the result to the calling activity.
    Set<BarcodeFormat> decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
    Map<DecodeHintType, Object> decodeHints = DecodeHintManager.parseDecodeHints(intent);

    CameraSettings settings = new CameraSettings();

    if (intent.hasExtra(Intents.Scan.CAMERA_ID)) {
        int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1);
        if (cameraId >= 0) {
            settings.setRequestedCameraId(cameraId);
        }
    }

    // Check to see if the scan should be inverted.
    boolean inverted = intent.getBooleanExtra(Intents.Scan.INVERTED_SCAN, false);

    String characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

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

    barcodeView.setCameraSettings(settings);
    barcodeView.setDecoderFactory(new DefaultDecoderFactory(decodeFormats, decodeHints, characterSet, inverted));
}
 
開發者ID:yinhaojun,項目名稱:ZxingForAndroid,代碼行數:31,代碼來源:DecoratedBarcodeView.java

示例2: convert

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
public static String convert(Bitmap bitmap) {
    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 rgbLuminanceSource = new RGBLuminanceSource(
                width, height, pixels);
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
                rgbLuminanceSource));
        HashMap<DecodeHintType, Object> hints = new HashMap<DecodeHintType, Object>();
        hints.put(DecodeHintType.CHARACTER_SET, DEFAULT_CHARSET);
        MultiFormatReader multiFormatReader = new MultiFormatReader();
        Result result = multiFormatReader.decode(binaryBitmap, hints);
        return result.getText();
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:wavinsun,項目名稱:MUtils,代碼行數:20,代碼來源:QRCodeUtil.java

示例3: decode

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
/**
 * @param srcImgFilePath
 *            要解碼的圖片地址
 * @return {Result}
 */
@SuppressWarnings("finally")
public static Result decode(String srcImgFilePath) {
	Result result = null;
	BufferedImage image;
	try {
		File srcFile = new File(srcImgFilePath);
		image = ImageIO.read(srcFile);
		if (null != image) {
			LuminanceSource source = new BufferedImageLuminanceSource(image);
			BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

			Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
			hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
			result = new MultiFormatReader().decode(bitmap, hints);
		} else {
			throw new IllegalArgumentException ("Could not decode image.");
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		return result;
	}
}
 
開發者ID:Javen205,項目名稱:IJPay,代碼行數:29,代碼來源:ZxingKit.java

示例4: decode

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
/**
 * 條形碼解碼
 */
public static String decode(BufferedImage image) {
	Result result = null;
	try {
		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;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:20,代碼來源:BarCodeUtils.java

示例5: decode

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
/**
 * 解析二維碼
 *
 * @param file 二維碼圖片
 * @return
 * @throws Exception
 */
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<DecodeHintType, Object>();
	hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
	result = new MultiFormatReader().decode(bitmap, hints);
	String resultStr = result.getText();
	return resultStr;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:23,代碼來源:QRCodeUtils.java

示例6: BitmapDecoder

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
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);

	}
 
開發者ID:wp521,項目名稱:MyFire,代碼行數:27,代碼來源:BitmapDecoder.java

示例7: decodeQr

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
public static String decodeQr(String filePath) {
    String retStr = "";
    if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
        return "圖片路徑為空!";
    }
    try {
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
        LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap bitmap = new BinaryBitmap(binarizer);
        HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
        hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
        retStr = result.getText();
    } catch (Exception e) {
        logger.error("", e);
    }
    return retStr;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:20,代碼來源:QrcodeUtil.java

示例8: syncDecodeQRCode

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
/**
 * 同步解析bitmap二維碼。該方法是耗時操作,請在子線程中調用。
 *
 * @param bitmap 要解析的二維碼圖片
 * @return 返回二維碼圖片裏的內容 或 null
 */
public static String syncDecodeQRCode(Bitmap bitmap) {
    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)), HINTS);
        return result.getText();
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:20,代碼來源:QRCodeDecoder.java

示例9: decodeQr

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
public static String decodeQr(String filePath) {
	String retStr = "";
	if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
		return "圖片路徑為空!";
	}
	try {
		BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
		LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
		Binarizer binarizer = new HybridBinarizer(source);
		BinaryBitmap bitmap = new BinaryBitmap(binarizer);
		HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
		hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
		Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
		retStr = result.getText();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return retStr;
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:20,代碼來源:QrcodeUtil.java

示例10: createDecoder

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
@Override
public Decoder createDecoder(Map<DecodeHintType, ?> baseHints) {
    Map<DecodeHintType, Object> hints = new EnumMap<>(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 inverted ? new InvertedDecoder(reader) : new Decoder(reader);

}
 
開發者ID:yinhaojun,項目名稱:ZxingForAndroid,代碼行數:25,代碼來源:DefaultDecoderFactory.java

示例11: decode

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:yinhaojun,項目名稱:ZxingForAndroid,代碼行數:23,代碼來源:Decoder.java

示例12: decodeWithZxing

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
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;
}
 
開發者ID:snice,項目名稱:androidscan,代碼行數:22,代碼來源:DecodeUtils.java

示例13: analyzeBitmap

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
/**
 * 解析二維碼圖片工具類
 *
 * @param bitmap
 */
public static String analyzeBitmap(Bitmap bitmap) {
    MultiFormatReader 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);

    // 開始對圖像資源解碼
    Result rawResult = null;
    try {
        rawResult = multiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(bitmap))));
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (rawResult != null) {
        return rawResult.getText();
    } else {
        return "Failed";
    }
}
 
開發者ID:ymqq,項目名稱:CommonFramework,代碼行數:41,代碼來源:ImageUtils.java

示例14: decode

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
public static String decode(File file) throws Exception {
    BufferedImage image;
    image = ImageIO.read(file);
    if (image == null) {
        return null;
    }
    CodeImage source = new CodeImage(
            image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Result result;
    Hashtable hints = new Hashtable();
    hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
    result = new MultiFormatReader().decode(bitmap, hints);
    String resultStr = result.getText();
    return resultStr;
}
 
開發者ID:Fetax,項目名稱:Fetax-AI,代碼行數:17,代碼來源:CodeUtil.java

示例15: decodes

import com.google.zxing.MultiFormatReader; //導入依賴的package包/類
/**
* 解析條形碼
*/
  public static String decodes(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;
  }
 
開發者ID:Fetax,項目名稱:Fetax-AI,代碼行數:22,代碼來源:CodeUtil.java


注:本文中的com.google.zxing.MultiFormatReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。