Size of the qr code image excluding the border

2,451 views
Skip to first unread message

Sri

unread,
Dec 4, 2013, 4:10:51 PM12/4/13
to zx...@googlegroups.com
Our requirement is that the qr code should be at least 2.75 centimeters. When we give the size of 105, the actual length of qr code is only 2.25 cm.. even if we specify  120, it expands the border, but the size of qr code remains same (around 2.3 cm).. When i increase the size to 150, it makes the QR code too big (at least 3.5cm)
 
what are our options? Should we resize the image?

Sean Owen

unread,
Dec 4, 2013, 5:58:06 PM12/4/13
to zx...@googlegroups.com
It's not clear how you're encoding it. Java? online encoder? you need to expand the margin, yes, but how you do it varies.
You can always just add it yourself.

The QR code spec requires 4 modules of margin, not a fixed size.

Lachezar Dobrev

unread,
Dec 5, 2013, 4:47:04 AM12/5/13
to Sri, zxing
The generation will create the QR code with EXACT scaling only (x1,
x2, x3), and if there is more space available, it will expand the
margins (4 modules minimum). This is designed to avoid doubling some
pixels when up-scaling, which would result in broken code.
Your requirement says it must be 2.75 centimetres, but the QR Code
is generated in pixels. I would suggest that you do the scaling in the
print, not in the generation phase.
Typically I request a 1x1 code, and I get a QR code with the minimum
allowed size. Afterwards I scale the bar-code to whatever size needs
to be printed by calculating the density, not the size.

Alternatively if your medium has fixed density you could use image
manipulation to resize the (minimum-size-generated) image to the
appropriate size to fit your medium. That is what I do when dealing
with label printers, which have fixed density and fixed space
available.


2013/12/4 Sri <sriv...@gmail.com>:
> --
>
> ---
> 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/groups/opt_out.

Sri

unread,
Dec 5, 2013, 11:26:05 AM12/5/13
to zx...@googlegroups.com
We are using Java for encoding, this is our code and we use bmp format and qrcode size '105'.
 
when we use 105 pixel size, the image is printed with actual qr content 2.3*2.3  size.
 
If I use 140 pixel size, the image is printed with actual qr content 3.3 * 3.3 size (and when i change resolution to '100' from 75 , it reduces the size to 2.5*2.5 cm)
 
 
 
            Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
 
         hintMap
.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
             
QRCodeWriter qrCodeWriter = new QRCodeWriter();
             
BitMatrix byteMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, qrCodeSize, qrCodeSize, hintMap);
             
// Make the BufferedImage that are to hold the QRCode
             
int matrixWidth = byteMatrix.getWidth();
             
BufferedImage image = new BufferedImage(matrixWidth, matrixWidth, BufferedImage.TYPE_BYTE_BINARY);
             
             image
.createGraphics();
             
Graphics2D graphics = (Graphics2D) image.getGraphics();
             graphics
.setColor(Color.BLACK);
             graphics
.fillRect(0, 0, matrixWidth, matrixWidth);
             
// Paint and save the image using the ByteMatrix
             graphics
.setColor(Color.WHITE);
             
for (int i = 0; i < matrixWidth; i++)
             
{
                 
for (int j = 0; j < matrixWidth; j++)
                 
{
                     
if (byteMatrix.get(i, j) == false)
                     
{
                         graphics
.fillRect(i, j, 1, 1);
                     
}
                 
}
             
}
             
             
ImageIO.write(image, imageFormat, outputStream);

 
Reply all
Reply to author
Forward
0 new messages