减少 ZXing 生成的 QR 码的边框宽度? [英] Reduce border width on QR Codes generated by ZXing?

查看:35
本文介绍了减少 ZXing 生成的 QR 码的边框宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 com.google.zxing.qrcode.QRCodeWriter 来编码数据和 com.google.zxing.client.j2se.MatrixToImageWriter 来生成二维码图片.在 400x400 图像上,代码周围有大约 52 像素宽的边框.我希望这个边框更窄,可能是 15 像素,但我在 API 中没有看到任何用于这样做的内容.我在文档中遗漏了什么吗?还是我需要自己处理图像?

I'm using com.google.zxing.qrcode.QRCodeWriter to encode data and com.google.zxing.client.j2se.MatrixToImageWriter to generate the QR Code image. On a 400x400 image, there is about a 52 pixel wide border around the code. I'd like this border to be narrower, maybe 15 pixels, but I don't see anything in the API for doing that. Am I missing something in the documenation? Or would I need to process the image myself?

作为参考,以下是使用 ZXing 库生成的 400x400 二维码示例:

For reference, here is an example 400x400 QR Code produced with the ZXing library:

推荐答案

QR 规范需要一个四模块静区,这就是 zxing 创建.(请参阅 QRCodeWriter.renderResult.)

The QR spec requires a four module quiet zone and that's what zxing creates. (See QUIET_ZONE_SIZE in QRCodeWriter.renderResult.)

最新版本的 ZXing 允许您通过使用 EncodeHintType.MARGIN 键.只需将其包含在您提供给 Writerencode(...) 方法,例如:

More recent versions of ZXing allow you to set the size of the quiet zone (basically the intrinsic padding of the QR code) by supplying an int value with the EncodeHintType.MARGIN key. Simply include it in the hints Map you supply to the Writer's encode(...) method, e.g.:

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

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

If you change this, you risk lowering the decode success rate.

这篇关于减少 ZXing 生成的 QR 码的边框宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆