本文整理汇总了Java中com.google.zxing.Binarizer类的典型用法代码示例。如果您正苦于以下问题:Java Binarizer类的具体用法?Java Binarizer怎么用?Java Binarizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Binarizer类属于com.google.zxing包,在下文中一共展示了Binarizer类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeQr
import com.google.zxing.Binarizer; //导入依赖的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;
}
示例2: decodeQr
import com.google.zxing.Binarizer; //导入依赖的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;
}
示例3: readQrCode
import com.google.zxing.Binarizer; //导入依赖的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;
}
示例4: parse
import com.google.zxing.Binarizer; //导入依赖的package包/类
private static void parse() throws IOException, NotFoundException, ChecksumException, FormatException {
BufferedImage image = ImageReader.readImage(Paths.get("d:/qr.png").toUri());
LuminanceSource source = new BufferedImageLuminanceSource(image);
Binarizer bin = new HybridBinarizer(source);
BinaryBitmap bitmap = new BinaryBitmap(bin);
Result result = new QRCodeReader().decode(bitmap);
System.out.println(result.toString());
}
示例5: binarization
import com.google.zxing.Binarizer; //导入依赖的package包/类
private Bitmap binarization(Bitmap bitmap, int lowColor, int highColor) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int pixels[] = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
Binarizer binarizer = new HybridBinarizer(source);
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
try {
BitMatrix matrix = binarizer.getBlackMatrix();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (matrix.get(j, i)) {
result.setPixel(j, i, highColor);
} else {
result.setPixel(j, i, lowColor);
}
}
}
} catch (NotFoundException e) {
e.printStackTrace();
}
return result;
}
示例6: binarization
import com.google.zxing.Binarizer; //导入依赖的package包/类
/**
* 二值化
*
* @param bitmap
* @return
*/
private Bitmap binarization(Bitmap bitmap, int lowColor, int highStartColor, int highEndColor) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int pixels[] = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
Binarizer binarizer = new HybridBinarizer(source);
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
try {
BitMatrix matrix = binarizer.getBlackMatrix();
int highColor;
for (int i = 0; i < height; i++) {
// highColor = getGradientColor(highStartColor, highEndColor, i / (float) height);
highColor = getGradientColorByCurve(highStartColor, highEndColor, 0, height, i);
for (int j = 0; j < width; j++) {
if (matrix.get(j, i)) {
result.setPixel(j, i, highColor);
} else {
result.setPixel(j, i, lowColor);
}
}
}
} catch (NotFoundException e) {
e.printStackTrace();
}
return result;
}
示例7: createBinarizer
import com.google.zxing.Binarizer; //导入依赖的package包/类
@Override
public Binarizer createBinarizer(LuminanceSource source) {
return new GlobalHistogramBinarizer(source);
}
示例8: createBinarizer
import com.google.zxing.Binarizer; //导入依赖的package包/类
@Override
public Binarizer createBinarizer(LuminanceSource source) {
return new HybridBinarizer(source);
}
示例9: createBinarizer
import com.google.zxing.Binarizer; //导入依赖的package包/类
public Binarizer createBinarizer(LuminanceSource source) {
return new GlobalHistogramBinarizer(source);
}
示例10: createBinarizer
import com.google.zxing.Binarizer; //导入依赖的package包/类
public Binarizer createBinarizer(LuminanceSource source) {
return new HybridBinarizer(source);
}
示例11: createBinarizer
import com.google.zxing.Binarizer; //导入依赖的package包/类
@Override
public Binarizer createBinarizer(LuminanceSource source) {
return new GlobalHistogramBinarizer(source);
}
示例12: createBinarizer
import com.google.zxing.Binarizer; //导入依赖的package包/类
@Override
public Binarizer createBinarizer(LuminanceSource source) {
return new HybridBinarizer(source);
}