ZXing to generate QRCode

7,198 views
Skip to first unread message

Neha

unread,
Jul 23, 2010, 2:22:11 AM7/23/10
to zxing
Hello,

Can we use zxing to generate QRCode that works for all the mobile
devices? I downloaded the zing1.5 framework. but it has many modules.
I am not sure which one is useful for me... My requirement is encode a
URL into QR Code image, save the image and also scan the image to open
the url. Please guide me on how to use it?

Thanks

Sean Owen

unread,
Jul 23, 2010, 3:18:40 AM7/23/10
to zxing
If you just want a QR code, look at http://zxing.appspot.com/generator

If you want the code behind it, look in core/, in
com.google.zxing.qrcode.encode. You can see an example of its use in
android/, in the EncodeActivity class.

Neha

unread,
Jul 23, 2010, 4:22:12 AM7/23/10
to zxing
Thanks for your reply. Is the zxing aPI specific for android mobile
device or it can be used for any mobile device?



On Jul 23, 12:18 pm, Sean Owen <sro...@gmail.com> wrote:
> If you just want a QR code, look athttp://zxing.appspot.com/generator

Sean Owen

unread,
Jul 23, 2010, 2:06:56 PM7/23/10
to zxing
The core library is not Android specific.

Neha

unread,
Jul 26, 2010, 2:40:34 AM7/26/10
to zxing
Hi,

Is core library enough to generate and read the QR Code? Also can u
please tell me how to save a qr code image after generating it?

Thanks
Neha

Sean Owen

unread,
Jul 27, 2010, 9:55:10 AM7/27/10
to zxing
Yes, but translating to a concrete image representation is platform-
specific. For example you need an implementation of
MonochromeBitmapSource that works with image classes for your
platform. Saving images is a platform-specific question right?

Yue Liu

unread,
Jul 27, 2010, 7:23:14 PM7/27/10
to zx...@googlegroups.com
I wrote the following code, to try to generate a simple QR code. It seems working, as a PNG file is generated. and it looks like a QR code.
However, using Barcode scanner v3.31 on my Android phone does not read it at all.

Any clue?

Thanks
George

Sean Owen

unread,
Jul 28, 2010, 3:39:39 AM7/28/10
to zxing
I don't think you can attach images to forum messages but you can mail
be directly with the image.

Yue Liu

unread,
Jul 28, 2010, 1:56:22 PM7/28/10
to Sean Owen, zx...@googlegroups.com
Sean,

It's good to know that at least it worked somehow. However, how to solve the problem?
I tried to change to write a JPG file, it gave me back a color file (Blue/Pink), but still couldn't be read by barcode scanner v3.31 on Android phone.

Is there any flag I should set? Maybe I should convert from ByteMatrix to BitMatrix before writing? I'm running my the test program on Vista, maybe related to big-endian, small-endian?

    static void test() {
        QRCodeWriter writer = new QRCodeWriter();
        ByteMatrix matrix = null;
        try {
            matrix = writer.encode("http://www.google.com/", BarcodeFormat.QR_CODE, 256, 256);
        } catch (WriterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
        if (matrix != null) {           
            try {
                File file = new File("test.png");
                MatrixToImageWriter.writeToFile(matrix, "PNG", file);
                System.out.println(file.getAbsolutePath());               
            }
            catch (IOException e) {
                System.out.println(e.getMessage());               
            }
        }       
    }




On Wed, Jul 28, 2010 at 10:09 AM, Sean Owen <sro...@gmail.com> wrote:
This image is inverted. The QR code should be black on white, not
white on black. That is why it cannot be read.

On Wed, Jul 28, 2010 at 5:19 PM, Yue Liu <george...@gmail.com> wrote:
> I have attached the generated file. Thanks for helping.
>

Sean Owen

unread,
Jul 28, 2010, 1:57:38 PM7/28/10
to Yue Liu, zx...@googlegroups.com
Hmm are you using an old version of the code? I seem to remember it
output the QR code inverted at some point. The latest code doesn't
have that problem.

I don't know why JPG would come out blue/pink but that's outside the
app or library.

The snippet looks OK.

Yue Liu

unread,
Jul 28, 2010, 5:50:46 PM7/28/10
to Sean Owen, zx...@googlegroups.com
I'm using the core.jar file from ZXing 1.5,

From the online documentation, http://zxing.org/w/docs/javadoc/index.html,
QRWriter.encode() returns BitMatrix, but from the jar file I got, it returns ByteMatrix.

MatrixToImageWriter.writeToFile takes in both BitMatrix and ByteMatrix. I wonder whether this is causing the problem.

Do you know the online documentation is mapped to which version of ZXing? Is there a way to convert ByteMatrix to BitMatrix?

Thanks
George

Sean Owen

unread,
Jul 29, 2010, 3:02:42 AM7/29/10
to zxing
Use the latest code from Subversion, it should not have this issue.

Yue Liu

unread,
Jul 30, 2010, 7:41:14 PM7/30/10
to zx...@googlegroups.com
Really great advise that pinpointed the problem.

I used the latest core.jar and j2se.jar compiled from svn source, and problem solved. Barcode scanner on my phone can read the encoded messages!

Finally got my "hello world" program working!

Thanks for all the help.
George

Forrest Lin

unread,
Sep 12, 2010, 2:11:26 AM9/12/10
to zx...@googlegroups.com
Seem like that you got succeed on Android ?  

I need figure it out for iPhone now .
--
      Best Regards,
      Forrest 


lucy pad

unread,
Jun 30, 2014, 3:24:35 AM6/30/14
to zx...@googlegroups.com
Zxing is a good and professional barcode control for .net. it is easy to generate barcode with that. beside Zxing,there are many other barcode libraries that can be used. such as http://www.keepdynamic.com/barcoding/java-barcode-generator.shtml
and http://www.keepdynamic.com/dotnet-barcode/barcode/qr-code.shtml
search online and you can find more of that for mobile devices
Reply all
Reply to author
Forward
0 new messages