> 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>:
> 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>: