本文整理匯總了Java中com.google.zxing.client.j2se.BufferedImageLuminanceSource類的典型用法代碼示例。如果您正苦於以下問題:Java BufferedImageLuminanceSource類的具體用法?Java BufferedImageLuminanceSource怎麽用?Java BufferedImageLuminanceSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BufferedImageLuminanceSource類屬於com.google.zxing.client.j2se包,在下文中一共展示了BufferedImageLuminanceSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: multiple
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的package包/類
/**
* Decode all barcodes in the image
*/
private String multiple(BufferedImage img) throws NotFoundException, ChecksumException, FormatException {
long begin = System.currentTimeMillis();
LuminanceSource source = new BufferedImageLuminanceSource(img);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
com.google.zxing.Reader reader = new MultiFormatReader();
MultipleBarcodeReader bcReader = new GenericMultipleBarcodeReader(reader);
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
StringBuilder sb = new StringBuilder();
for (Result result : bcReader.decodeMultiple(bitmap, hints)) {
sb.append(result.getText()).append(" ");
}
SystemProfiling.log(null, System.currentTimeMillis() - begin);
log.trace("multiple.Time: {}", System.currentTimeMillis() - begin);
return sb.toString();
}
示例2: decode
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
}
示例3: decode
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例4: decode
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例5: decodeQr
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例6: decodeQr
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例7: decodes
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例8: decode
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例9: decode2
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例10: readQrCode
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例11: decode
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例12: decode2
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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;
}
示例13: checkFormat
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的package包/類
private void checkFormat(File file, BarcodeFormat format) throws IOException {
Reader reader = new MultiFormatReader();
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(file))));
Result result;
try {
result = reader.decode(bitmap);
} catch (ReaderException ex) {
throw new IOException(ex);
}
assertEquals(format, result.getBarcodeFormat());
}
示例14: decode
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的package包/類
/**
* @param srcImgFilePath 要解碼的圖片地址
* @return
*/
public 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 hints = new Hashtable();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
result = new MultiFormatReader().decode(bitmap, hints);
} else {
log.debug("Could not decode image.");
}
} catch (Throwable t) {
log.error("decode-ex:{}", t);
throw Throwables.propagate(t);
} finally {
return result;
}
}
示例15: decode
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; //導入依賴的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);
}