Creating colored QR codes using zxing

10,311

Solution 1

In MatrixToImageWriter.java (which I assume you are using), under javase/ change the constant BLACK. It is an int in ARGB format and currently has value 0xFF000000. Leave the alpha value at 0xFF. Change the rest to describe your color in hex format. You can do the same with WHITE if you like.

Solution 2

Try this ::

BitMatrix matrix = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, this.width, this.height, getEncodeHints());
/*
Here the config object represents the QR Code colors.
i.e. Brown and White respectively
*/ 
MatrixToImageConfig conf = new MatrixToImageConfig(-10223615,-1);
BufferedImage qrcode = MatrixToImageWriter.toBufferedImage(matrix, conf);
Share:
10,311
Shaun McCran
Author by

Shaun McCran

Updated on June 05, 2022

Comments

  • Shaun McCran
    Shaun McCran almost 2 years

    I am using the google open source java zxing creator: http://code.google.com/p/zxing/

    to create QR codes. I have everything in place and working (I'm loading the java files using coldfusion and writing the image to the browser.)

    What I want now is to change the black QR colour to something else. Is there an easy way of doing this?

    Would I need to edit a decompiled version of the encoder java file? Or is there a way I could add a color argument to the encoding routine?

    Thanks Shaun