请教个问题:一张图片当中在不固定位置包含有条形码,怎么读取条形码出来呢?怎么读取一张图片中的多个条形码?用zxing读取图片当中的条形码,报错com.google.zxing.NotFoundException。有大神知道的吗?谢谢
1条回答 默认 最新
yushulx 2020-03-16 10:36关注首先把图像读到BufferedImage
import java.awt.image.*; import javax.imageio.ImageIO; BufferedImage image = null; try { image = ImageIO.read(new File(filename)); } catch (IOException e) { System.out.println(e); return; }然后转换成BinaryBitmap传给ZXing
BinaryBitmap bitmap = null; int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth()); RGBLuminanceSource source = new RGBLuminanceSource(image.getWidth(), image.getHeight(), pixels); bitmap = new BinaryBitmap(new HybridBinarizer(source)); MultiFormatReader reader = new MultiFormatReader(); GenericMultipleBarcodeReader multiReader = new GenericMultipleBarcodeReader(reader); try { Result[] zxingResults = multiReader.decodeMultiple(bitmap); } catch (NotFoundException e) { e.printStackTrace(); } pixels = null; bitmap = null;解决 无用评论 打赏 举报