Removing Padding from Encoded QR Codes

4,500 views
Skip to first unread message

Anirvan Majumdar

unread,
Dec 26, 2011, 12:05:58 PM12/26/11
to zx...@googlegroups.com

Hello,

 

I’ve been using zxing for generating QR Codes both in my web application and android apps. There’s no issue in the data encoding part. However, what I’ve observed is that in either case there’s a thick padding/border around the QR code image. This is white in colour, so it’s not much of an issue if I’m using a light background. But with a coloured background, this becomes quite a problem. I’m attaching a sample QR image to give a clearer picture of what I mean. I could try and programmatically crop the image, but I’m not sure what can be a consistent %-age value by which I can crop the edges, so that irrespective of the size of the image I get a proper, cropped QR image.

 

The code I use to generate the QR image is –  

BitMatrix matrix = writer.encode(str, com.google.zxing.BarcodeFormat.QR_CODE,

                                    QR_WIDTH, QR_HEIGHT);

 

After that, in case of web applications, I write the matrix to a stream, and in case of Android I re-encode it into a Bitmap.

 

Last but certainly not the least, I believe you guys [zxing team] are doing an excellent job at making such a core technology available to so many people.

 

Thank you so very much!

anirvan

 

 

 

 

sample-qr.png

Sean Owen

unread,
Dec 26, 2011, 3:57:39 PM12/26/11
to zx...@googlegroups.com
Yes, the quiet zone is required. I think it needs to be at least 4 modules, so I think that's what it generates. So, I would not crop this out as you technically need it for it to scan... though some readers will scan it with just a little border, it will be harder. And some won't read at all.

If you need to recolor it, you can do that programmatically. Or just change the RGB value used for "WHITE" in the source code to what you like.
Reply all
Reply to author
Forward
0 new messages