integrating zxing in ireport

1,844 views
Skip to first unread message

junaidy junaidy

unread,
Sep 15, 2011, 10:40:57 AM9/15/11
to zxing
Hi alll,
How integrating zxing qrcode in an ireport?
Because an ireport not supported qrcode.
Please help me...
thanks
Message has been deleted
Message has been deleted

Lachezar Dobrev

unread,
Sep 15, 2011, 11:52:07 AM9/15/11
to junaidy junaidy, zxing
Are you referring to Jasper Reports engine and iReport designer?
If that is the case, than it's achievable.
Add the ZXing Core[1] and Java-SE[2] projects to the application's class-path.
Add a new class to your application:

> package your.company;
> import com.google.zxing.qrcode.encoder.Encoder;
> import com.google.zxing.qrcode.encoder.QRCode;
> import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
>
> public class QRGenerator {
> public BufferedImage generate(String content) {
> QRCode qrcode = new QRCode();
> Encoder.encode(content, ErrorCorrectionLevel.L, qrcode);
> return MatrixToImageWriter.toBufferedImage(qrcode.getMatrix());
> }
> }

Add an image in the report with the following expression:
> your.company.QRGenerator.generate("BARCODE_CONTENT")

Replace "BARCODE_CONTENT" with whatever you want encoded.

This is a rewrite of what we're using, so you may have to adapt it
to your needs.

Sean, Daniel: maybe this «handy» class may be added to Java-SE
project, so that non-programmers could make use of it.

[1] http://zxing.googlecode.com/svn/trunk/core/
[2] http://zxing.googlecode.com/svn/trunk/javase/

2011/9/15 junaidy junaidy <magenta...@gmail.com>:

Lachezar Dobrev

unread,
Sep 16, 2011, 10:24:24 AM9/16/11
to junaidy junaidy, zxing
Doh. My bad. Apologies.
I am doing my own conversion to BufferedImage, hence I overlooked that.
Following is a combined code:

> public class QRGenerator {
> private static final int BLACK = 0xFF000000; // ARGB
> private static final int WHITE = 0xFFFFFFFF; // ARGB
>
> public static BufferedImage generateQRCode(String content) throws Exception {
> QRCode q;
> q = new QRCode();
>
> Encoder.encode(content, ErrorCorrectionLevel.L, q);
>
> ByteMatrix m;
> m = qr.getMatrix();
>
> int w = m.getWidth();
> int h = m.getHeight();
>
> // 4 pixels on all sides for the mandatory quiet zone.
> BufferedImage img;
> img = new BufferedImage(w + 8, h + 8, BufferedImage.TYPE_INT_ARGB);
> for (int x = 0; x < w; x++) {
> for (int y = 0; y < h; y++) {
> img.setRGB(x + 4, y + 4, m.get(x, y) != 0 ? BLACK : WHITE);
> }
> }
> return img;
> }
> }

With this code you need ONLY core project.
This code generates very small images (1 pixel per module). Scale
the image to the available space in your report design.

2011/9/16 junaidy junaidy <magenta...@gmail.com>:
> Error : thats return ByteMatrix()
> you mean qrcode.getMatrix(), thats return ByteMatrix()
> it should return BitMatrix not ByteMatrix
> any idea?
>
> 2011/9/15, Lachezar Dobrev <l.do...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages