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