我可以使用ZXing库获取QR码的值,但我还需要QR码角点的坐标。如何访问这些坐标。
我不确定您要提取哪个角的坐标,但我非常确定您可以从Result.getResultPoints()方法获得的结果点计算它们。
例如,对于以下图像(200x200像素)和代码片段:
BufferedImage image = ImageIO.read(new File("QRCode-1.png"));
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
new BufferedImageLuminanceSource(image)));
Reader reader = new QRCodeReader();
Result result = reader.decode(binaryBitmap);
System.out.println("text: " + result.getText());
ResultPoint[] resultPoints = result.getResultPoints();
System.out.println("resultPoints:");
for (int i = 0; i < resultPoints.length; i++) {
ResultPoint resultPoint = resultPoints[i];
System.out.print(" [" + i + "]:");
System.out.print(" x = " + resultPoint.getX());
System.out.print(", y = " + resultPoint.getY());
if (resultPoint instanceof FinderPattern)
System.out.print(", estimatedModuleSize = "
+ ((FinderPattern) resultPoint).getEstimatedModuleSize());
System.out.println();
}
text: Hello World!
resultPoints:
[0]: x = 36.5, y = 162.5, estimatedModuleSize = 9.0
[1]: x = 36.5, y = 36.5, estimatedModuleSize = 9.0
[2]: x = 162.5, y = 36.5, estimatedModuleSize = 9.0
x
和y
是正方形查找图案的中心坐标。
知道QR码查找图案的大小为7x7模块,
您可以轻松计算出角落坐标。
QRCodeReader
会更好用。 - Thomas Fritsch3*moduleSize
像素。 - zhy