22

I'm seeking an open source QR codes image generator component in java (J2SE), but the open source licence mustn't be a GPL licence (needs to be included in a close source project).

BTW, i can't access the web from the project so no Google API.

oneeyejack
  • 351
  • 1
  • 4
  • 16

3 Answers3

26

Mercer - no, there is an encoder in the library too. com.google.zxing.qrcode.encoder. We provide that in addition to an example web app using Google Chart APIs

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • ok thank you! i just have to create an Image using the qrCode.getMatrix().getArray(); – oneeyejack Aug 19 '09 at 16:02
  • 7
    In case anyone else is doing this, heres the basic idea. Use Encoder.encode() to 'fill-in' the details of a newly instantiated QRCode. Then get the byte[][] from QRCode.getMatrix().getArray() as suggested above. Each line of bytes seems to be a row of pixels for the QRCode, with each byte being zero or one. At this point you could just paint the pixels to a BufferedImage or make a Raster out of it or something to turn it into an AWT image. – CarlG Nov 30 '10 at 18:51
  • 12
    ... or use the provided class MatrixToImageWriter to do all this for you ! – Sean Owen Dec 01 '10 at 09:26
14

ZXing is is an open-source, multi-format 1D/2D barcode image processing library implemented in Java. It is released under the The Apache License, so it allows use of the source code for the development of proprietary software as well as free and open source software.

Paolo Moretti
  • 54,162
  • 23
  • 101
  • 92
2

MatrixToImageWriter uses BitMatrix, not ByteMatrix as returned by QRCode.getMatrix. by looking at android sourcecode, I found the following proof of concept solution:

    try {
        MultiFormatWriter writer = new MultiFormatWriter();    
        Hashtable hints = new Hashtable();
        hints.put( EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q );            
        MatrixToImageWriter.writeToFile( writer.encode( "hello world", BarcodeFormat.QR_CODE, 800, 800, hints ),
                                         "png", new File( "/tmp/qrcode.png" ) );
    } catch ( Exception e ) {
        System.out.println( "failure: " + e );
    }

btw imposing Hashtable in API is not clean. please use Map. not many people still use Hashtable anyway, you should almost always use HashMap instead (except a few use cases).

  • Responding to this very old comment I just saw: it used `Hashtable` for compatibility with J2ME, which does not have `Map`. But since v2.0 J2ME support was dropped and the API takes a `Map`. – Sean Owen Nov 09 '12 at 07:49