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


Java LuminanceSource类代码示例

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


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

示例1: decode

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

import com.google.zxing.LuminanceSource; //导入依赖的package包/类
@Override
public LuminanceSource rotateCounterClockwise() {

  int sourceWidth = this.image.getWidth();
  int sourceHeight = this.image.getHeight();

  AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0,
    0.0, sourceWidth);

  BufferedImage rotatedImage = new BufferedImage(sourceHeight,
    sourceWidth, BufferedImage.TYPE_BYTE_GRAY);

  Graphics2D g = rotatedImage.createGraphics();
  g.drawImage(this.image, transform, null);
  g.dispose();

  int width = getWidth();
  return new BufferedImageLuminanceSource(rotatedImage, this.top,
    sourceWidth - (this.left + width), getHeight(), width);
}
 
开发者ID:binarywang,项目名称:qrcode-utils,代码行数:21,代码来源:BufferedImageLuminanceSource.java

示例4: decodeQr

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

示例5: decodeQr

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

示例6: decodes

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

示例7: decode

import com.google.zxing.LuminanceSource; //导入依赖的package包/类
/**
 * 条形码解码
 *
 * @param imgPath 文件路径
 * @return String string
 */
public static String decode(String imgPath) {
    BufferedImage image;
    Result result;
    try {
        image = ImageIO.read(new File(imgPath));
        if (image == null) {
            LOGGER.error("the decode image may be not exit.");
            return null;
        }
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        result = new MultiFormatReader().decode(bitmap, null);
        return result.getText();
    } catch (Exception e) {
        LOGGER.error("条形码解析错误", e);
    }
    return null;
}
 
开发者ID:ruyangit,项目名称:angit,代码行数:26,代码来源:ZxingHelper.java

示例8: decode2

import com.google.zxing.LuminanceSource; //导入依赖的package包/类
/**
 * 二维码解码
 *
 * @param imgPath 文件路径
 * @return String string
 */
public static String decode2(String imgPath) {
    BufferedImage image;
    Result result;
    try {
        image = ImageIO.read(new File(imgPath));
        if (image == null) {
            LOGGER.error("the decode image may be not exit.");
            return null;
        }
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        EnumMap<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
        hints.put(DecodeHintType.CHARACTER_SET, "GBK");

        result = new MultiFormatReader().decode(bitmap, hints);
        return result.getText();
    } catch (Exception e) {
        LOGGER.error("二维码解码错误", e);
    }
    return null;
}
 
开发者ID:ruyangit,项目名称:angit,代码行数:29,代码来源:ZxingHelper.java

示例9: scanBitmap

import com.google.zxing.LuminanceSource; //导入依赖的package包/类
public Result scanBitmap(Bitmap bitmap) throws FormatException, ChecksumException, NotFoundException {
    Reader reader = new MultiFormatReader();
    Result result;

    int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
    //copy pixel data from the Bitmap into the 'intArray' array
    bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());

    LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);
    BinaryBitmap bMap = new BinaryBitmap(new HybridBinarizer(source));

    result = reader.decode(bMap);

    return result;
}
 
开发者ID:areebbeigh,项目名称:QRCodeUtility,代码行数:16,代码来源:ActivityHelper.java

示例10: readQrCode

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

示例11: decode

import com.google.zxing.LuminanceSource; //导入依赖的package包/类
/**
 * 条形码解码
 * 
 * @param imgPath
 * @return String
 */
public static String decode(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:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:25,代码来源:ZxingHandler.java

示例12: decode2

import com.google.zxing.LuminanceSource; //导入依赖的package包/类
/**
 * 二维码解码
 * 
 * @param imgPath
 * @return String
 */
public static String decode2(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));

		Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
		hints.put(DecodeHintType.CHARACTER_SET, "GBK");

		result = new MultiFormatReader().decode(bitmap, hints);
		return result.getText();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:28,代码来源:ZxingHandler.java

示例13: decode

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

示例14: rotateCounterClockwise

import com.google.zxing.LuminanceSource; //导入依赖的package包/类
@Override
public LuminanceSource rotateCounterClockwise() {
  //if (!isRotateSupported()) {
  //  throw new IllegalStateException("Rotate not supported");
  //}
  int sourceWidth = image.getWidth();
  int sourceHeight = image.getHeight();

  // Rotate 90 degrees counterclockwise.
  AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth);

  // Note width/height are flipped since we are rotating 90 degrees.
  BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY);

  // Draw the original image into rotated, via transformation
  Graphics2D g = rotatedImage.createGraphics();
  g.drawImage(image, transform, null);
  g.dispose();

  // Maintain the cropped region, but rotate it too.
  int width = getWidth();
  return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width);
}
 
开发者ID:lzh9102,项目名称:qrcode-desktop,代码行数:24,代码来源:BufferedImageLuminanceSource.java

示例15: rotateCounterClockwise

import com.google.zxing.LuminanceSource; //导入依赖的package包/类
@Override
public LuminanceSource rotateCounterClockwise() {
	int sourceWidth = image.getWidth();
	int sourceHeight = image.getHeight();

	// Rotate 90 degrees counterclockwise.
	AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth);

	// Note width/height are flipped since we are rotating 90 degrees.
	BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY);

	// Draw the original image into rotated, via transformation
	Graphics2D g = rotatedImage.createGraphics();
	g.drawImage(image, transform, null);
	g.dispose();

	// Maintain the cropped region, but rotate it too.
	int width = getWidth();
	return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width);
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:21,代码来源:BufferedImageLuminanceSource.java


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