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?
For reference, here is an example 400x400 QR Code produced with the ZXing library:
To reduce the size of your QR code, you can do three things. Lower the character count, lower the error correction, and remove a central graphic if it exists. Large QR codes can slow down scanning. Decreasing QR codes keeps them true to their name.
You can resize as much as you want. The information is encoded in the pattern of the data, not in the size of the dots themselves. As long as a scanner can resolve properly between light/dark, the QR code should be readable at any size.
Press the Ctrl+R hotkey to open the Resize/Resample window. Enter your desired dimensions in pixels or percentages to resize the QR code without losing quality.
You can add borders around a QR code, specifying the border size, color, and type. This can be done through styles or by using local formatting.
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<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With