本文整理匯總了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;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}