gpt4 book ai didi

zxing - 减少 ZXing 生成的二维码的边框宽度?

转载 作者:行者123 更新时间:2023-12-03 07:45:16 38 4
gpt4 key购买 nike

我使用 com.google.zxing.qrcode.QRCodeWriter 对数据进行编码,并使用 com.google.zxing.client.j2se.MatrixToImageWriter 生成 QR 码图像。在 400x400 图像上,代码周围有大约 52 像素宽的边框。我希望这个边框更窄一些,也许是 15 像素,但我在 API 中没有看到任何可以做到这一点的内容。我在文档中遗漏了什么吗?或者我需要自己处理图像吗?

以下是使用 ZXing 库生成的 400x400 QR 码示例,供引用:

An example QR Code

最佳答案

QR 规范需要一个四模块静区,这就是 zxing creates 。 (请参阅 QRCodeWriter.renderResult 中的 QUIET_ZONE_SIZE。)

ZXing 的最新版本允许您通过提供带有 EncodeHintType.MARGIN 的 int 值来设置安静区域的大小(基本上是 QR 代码的固有填充)。 key 。只需将其包含在您提供给 Writerencode(...) 的提示 Map 中即可。方法,例如:

Map<EncodeHintType, Object> hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hints.put(EncodeHintType.MARGIN, 2); /* default = 4 */

如果您更改此设置,则可能会降低解码成功率。

关于zxing - 减少 ZXing 生成的二维码的边框宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10142748/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com