Reduce border width on QR Codes generated by ZXing?

后端 未结 4 610
傲寒
傲寒 2021-01-30 20:58

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

4条回答
  •  再見小時候
    2021-01-30 21:09

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

    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 hints = new EnumMap(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.

提交回复
热议问题