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


Java BinaryBitmap类代码示例

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


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

示例1: decode

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

示例2: decode

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

示例3: decode

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

示例4: getRawResult

import com.google.zxing.BinaryBitmap; //导入依赖的package包/类
/**
 * 获取解码结果
 * 
 * @param bitmap
 * @return
 */
public Result getRawResult(Bitmap bitmap) {
	if (bitmap == null) {
		return null;
	}

	try {
		return multiFormatReader.decodeWithState(new BinaryBitmap(
				new HybridBinarizer(new BitmapLuminanceSource(bitmap))));
	}
	catch (NotFoundException e) {
		e.printStackTrace();
	}

	return null;
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:22,代码来源:BitmapDecoder.java

示例5: decodeQr

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

示例6: syncDecodeQRCode

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

示例7: decodeQr

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

示例8: decode

import com.google.zxing.BinaryBitmap; //导入依赖的package包/类
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean multiple) 
    throws NotFoundException, FormatException, ChecksumException {
  List<Result> results = new ArrayList<>();
  PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple);
  for (ResultPoint[] points : detectorResult.getPoints()) {
    DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(), points[4], points[5],
        points[6], points[7], getMinCodewordWidth(points), getMaxCodewordWidth(points));
    Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.PDF_417);
    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel());
    PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult.getOther();
    if (pdf417ResultMetadata != null) {
      result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata);
    }
    results.add(result);
  }
  return results.toArray(new Result[results.size()]);
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:18,代码来源:PDF417Reader.java

示例9: decode

import com.google.zxing.BinaryBitmap; //导入依赖的package包/类
@Override
public Result decode(BinaryBitmap image,
                     Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
  try {
    return doDecode(image, hints);
  } catch (NotFoundException nfe) {
    boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
    if (tryHarder && image.isRotateSupported()) {
      BinaryBitmap rotatedImage = image.rotateCounterClockwise();
      Result result = doDecode(rotatedImage, hints);
      // Record that we found it rotated 90 degrees CCW / 270 degrees CW
      Map<ResultMetadataType,?> metadata = result.getResultMetadata();
      int orientation = 270;
      if (metadata != null && metadata.containsKey(ResultMetadataType.ORIENTATION)) {
        // But if we found it reversed in doDecode(), add in that result here:
        orientation = (orientation +
            (Integer) metadata.get(ResultMetadataType.ORIENTATION)) % 360;
      }
      result.putMetadata(ResultMetadataType.ORIENTATION, orientation);
      // Update result points
      ResultPoint[] points = result.getResultPoints();
      if (points != null) {
        int height = rotatedImage.getHeight();
        for (int i = 0; i < points.length; i++) {
          points[i] = new ResultPoint(height - points[i].getY() - 1, points[i].getX());
        }
      }
      return result;
    } else {
      throw nfe;
    }
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:34,代码来源:OneDReader.java

示例10: decode

import com.google.zxing.BinaryBitmap; //导入依赖的package包/类
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, ChecksumException, FormatException {
  DecoderResult decoderResult;
  if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
    BitMatrix bits = extractPureBits(image.getBlackMatrix());
    decoderResult = decoder.decode(bits, hints);
  } else {
    throw NotFoundException.getNotFoundInstance();
  }

  ResultPoint[] points = NO_POINTS;
  Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.MAXICODE);

  String ecLevel = decoderResult.getECLevel();
  if (ecLevel != null) {
    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
  }
  return result;
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:21,代码来源:MaxiCodeReader.java

示例11: decode

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

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

示例15: decode

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


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