本文整理汇总了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);
}