67,512
社区成员
发帖
与我相关
我的任务
分享
String filePath = "D://42b0b8a4db194e8cbc048dd7c1b86f0e.png";
BufferedImage image;
try {
image = ImageIO.read(new File(filePath));
LuminanceSource source = new BufferedImageLuminanceSource(image);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Map<DecodeHintType, Object> hints = new HashMap<DecodeHintType, Object>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
Result result = new MultiFormatReader().decode(binaryBitmap, hints);// 对图像进行解码
System.out.println("图片中内容: "+ result.getText());
System.out.println("图片中格式: " + result.getBarcodeFormat());
} catch (Exception e) {
e.printStackTrace();
}