We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

QR Code - setting the size has no effect

I am trying to turn a QR code into an image (for embedding into a PDF). I’ve tried various methods and nothing seems to work. The image is always 33 pixels wide (exactly enough for the the code bits).

In the code below I tried using different units, as well as different sizes, but the image size never changes. How can I get a 2.5 inch image?

getOnlyBarCodeImage() returns a 33 pixel image, and save() saves a 1,914 pixel image…

public static BufferedImage getQrCode2( String text )
BarCodeBuilder builder = new BarCodeBuilder();
builder.setSymbologyType( Symbology.QR );

builder.setCodeText( text );

builder.setCodeLocation( CodeLocation.None );

builder.setQRErrorLevel( QRErrorLevel.LevelH );

builder.setGraphicsUnit( GraphicsUnit.Inch );
builder.setImageHeight( 2.5f );

builder.getMargins().set( 0 );

// builder.save( “…path…\QRImageTWO.png” );

return builder.getOnlyBarCodeImage();

Hi David,

Thank you for your inquiry.

We have tested the scenario at our end. We have used the latest version Aspose.BarCode for Java v.7.7.0. It is working fine. Sample code and generated QR barcode image is attached for your reference.

BarCodeBuilder builder = new BarCodeBuilder();

builder.setSymbologyType( com.aspose.barcode.Symbology.QR );
builder.setCodeText( "123456789" );
builder.setCodeLocation( CodeLocation.None );
builder.setQRErrorLevel( com.aspose.barcode.QRErrorLevel.LevelH );
builder.setGraphicsUnit( com.aspose.barcode.GraphicsUnit.Inch );
builder.setImageHeight( 2.5f );
builder.getMargins().set( 0 );

builder.save( "QRImageTWO.png" );
java.awt.image.BufferedImage ObjImg = builder.getBarCodeImage();
int width = ObjImg.getWidth();
int height = ObjImg.getHeight();
byte[] pixels = ((java.awt.image.DataBufferByte) ObjImg.getRaster().getDataBuffer()).getData();

Feel free to contact us in case you have further query or comments.

Did you check the size of the image you attached - it’s very large (1218 pixels). It should only be 2.5 inches. That varies of course with what “size” means (paper, screen, resolution, etc) but I’m still guessing it’s still too large.

If you change the image height in your code, does it affect the size of your output?

Hi David,

Thank you for writing us back.

Custom height and width of barcode affects the size of output barcode image. Furthermore we have investigated the custom height & width has no affect on QR barcode issue at our end. We are able to notice the issue. The issue has been logged into our issue tracking system with ID BARCODJAVA-33636. Our product team will look into it. We will update you accordingly.

Good to hear. You guys still have some of the best and fastest tech support! Thanks.

Hi David,

Thank you for your feedback. We will keep you posted on the status.