Generating QR Codes -- why do sizes jump?

1,605 views
Skip to first unread message

fbs419

unread,
Mar 4, 2015, 11:01:28 PM3/4/15
to zx...@googlegroups.com
I generate a QRCode like this:

var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new EncodingOptions
{
Height = 82,
Width = 82
}
};

This gives me a QR Code about 11/16" square. If I drop the Height and Width to 81, it gives me a QR Code just over 5/16" inches square.

The 82 size is too big for me -- I need to generate something in between the 11/16 and 5/16 size.

It seems that using larger sizes works fine -- they are proportional -- but once I get below 82, they're all that same small size. Is this a bug?

How can I get a QR Code in between 5/16" and 11/16"?

Thanks

fbs419

unread,
Mar 5, 2015, 9:06:10 PM3/5/15
to zx...@googlegroups.com
I guess this could be answered by this post:

https://groups.google.com/forum/#!searchin/zxing/qrcode$20sizes/zxing/4DPXPm2UPks/NMhsklJcJRIJ

Too bad. Using 1 X 1, you get about a 45 X 45 image. That goes up until about 82 -- then you get 82 X 82. Unfortunately, the size I need, to fit on a circular label 1 inch in diameter is right in between -- probably around 65 X 65. Oh well...

BTW, I am doing this on an Android phone using ZXing.Net.Mobile-1.4.7

Lachezar Dobrev

unread,
Mar 6, 2015, 5:16:26 AM3/6/15
to fbs419, zxing
First of all: The ZXing.Net is a different project/product, that has
common ancestry with ZXing, but is not a part of the base ZXing
project set. So it might pay to ask on their help channels than this
one.

Your 'problem' however is a more generic, so here it goes: the ZXing
generator generates a MATRIX, which is modules/pixels. Actual media
has a density, which comes into play. If your 1" circular label has
space for only 65 pixels, than it is a pretty bad media: the earliest
screens I remember had 75 ppi, 65 seems really low (~92 ppi if using
the diagonal). Most low-resolution print methods start at 150 ppi and
even the worst one I've seen in practice (an industrial thermal
printer) has 210 ppi.
The QR Code is not a free-size one: it has Version which specifies
the *EXACT* number of modules (a.k.a. pixels) the code must use [1].
The version also specifies the number of characters it encodes. So
depending on the size of the content you have to use a specific
version, and that is it. I have the feeling, that you're encoding some
text that needs version 6 (41x41), and all sizes between 41x41 and
82x82 will end up a 41x41 matrix with white padding to the matrix
size. If you want to fit that in a 65x65 that means the code must be
scaled 1.59 times, and 24 pixels will be doubled, while 17 will not,
this will produce s very distorted code, which will make it
unnecessarily hard to scan.
That is why scaling should be done from the minimal size using the
maximum available (reasonable) density of the print media/method.
Depending on your print method you might have access to smart scaling
that would provide extra density (like sub-pixel scaling).

I hope you can now understand the actual issue at hand: density of
the print media/method.

[1] http://www.qrcode.com/en/about/version.html
> --
> You received this message because you are subscribed to the Google Groups "zxing" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to zxing+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

fbs419

unread,
Mar 6, 2015, 7:13:14 PM3/6/15
to zx...@googlegroups.com
This makes sense -- thanks a lot. You are correct. I am encoding some text, and telling it to do 1 X 1 gives 41 X 41. I don't think my 1" circular label is bad media -- besides the QR code, I'm also writing some text below it using the Android.Graphics Canvas DrawText method. If I were putting only the QR Code on the label, it might work better.

So currently, my Scandit scanner on the phone (which is a good scanner) can't scan the 41 X 41 image, but it can scan the 82 X 82 image.

So it seems to make sense to scale it. I've tried that, generating the 1 X 1 image (41 X 41) and then going into Adobe Photoshop Elements, hitting Image Reize, and changing the resolution from about 99 to anywhere from 50 to 60. I first tried with Resample Image off, figuring that is the way to scale. I also tried the other way, but basically none of it works. The only image that scans is my original 82 X 82 one (and anything larger).

Perhaps I'm missing something here ...

fbs419

unread,
Mar 7, 2015, 12:07:53 PM3/7/15
to zx...@googlegroups.com
So it seems to work better in reverse. I generated the barcode at 150 X 150 pixels, which gave me a resolution of 72. I changed the resolution in Photo Shop Elements to 218, and it gave me an image of 7/16" square that scanned fine. So now I just have to find the resolution that will give me an 11/16" square image, and I should be good to go. To figure out the resolution, I did:

150 / (11/16), which gave me 218. As I mentioned, it produced a 7/16" square image, which wasn't what I was expecting. But at least I have a path to success here.

Thanks for all the help.
Reply all
Reply to author
Forward
0 new messages