net.glxn.qrgen
Class QRCode

java.lang.Object
  extended by net.glxn.qrgen.QRCode

public class QRCode
extends Object

QRCode generator. This is a simple class that is built on top of ZXING

Please take a look at their framework, as it has a lot of features.
This small project is just a wrapper that gives a convenient interface to work with.

Start here: from(String) (e.g QRCode.from("hello"))


Method Summary
 File file()
          returns a File representation of the QR code.
 File file(String name)
          returns a File representation of the QR code.
static QRCode from(String text)
          Create a QR code from the given text.
 ByteArrayOutputStream stream()
          returns a ByteArrayOutputStream representation of the QR code
 QRCode to(ImageType imageType)
          Overrides the imageType from its default ImageType.PNG
 QRCode withCharset(String charset)
          Overrides the default cahrset by supplying a EncodeHintType.CHARACTER_SET hint to QRCodeWriter.encode(java.lang.String, com.google.zxing.BarcodeFormat, int, int)
 QRCode withSize(int width, int height)
          Overrides the size of the qr from its default 125x125
 void writeTo(OutputStream stream)
          writes a representation of the QR code to the supplied OutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

from

public static QRCode from(String text)
Create a QR code from the given text.

There is a size limitation to how much you can put into a QR code. This has been tested to work with up to a length of 2950 characters.

The QRCode will have the following defaults:
{size: 100x100}
{imageType:PNG}

Both size and imageType can be overridden:
Image type override is done by calling to(net.glxn.qrgen.image.ImageType) e.g. QRCode.from("hello world").to(JPG)
Size override is done by calling withSize(int, int) e.g. QRCode.from("hello world").to(JPG).withSize(125, 125)

Parameters:
text - the text to encode to a new QRCode, this may fail if the text is too large.
Returns:
the QRCode object

to

public QRCode to(ImageType imageType)
Overrides the imageType from its default ImageType.PNG

Parameters:
imageType - the ImageType you would like the resulting QR to be
Returns:
the current QRCode object

withSize

public QRCode withSize(int width,
                       int height)
Overrides the size of the qr from its default 125x125

Parameters:
width - the width in pixels
height - the height in pixels
Returns:
the current QRCode object

withCharset

public QRCode withCharset(String charset)
Overrides the default cahrset by supplying a EncodeHintType.CHARACTER_SET hint to QRCodeWriter.encode(java.lang.String, com.google.zxing.BarcodeFormat, int, int)

Returns:
the current QRCode object

file

public File file()
returns a File representation of the QR code. The file is set to be deleted on exit (i.e. File.deleteOnExit()). If you want the file to live beyond the life of the jvm process, you should make a copy.

Returns:
qrcode as file

file

public File file(String name)
returns a File representation of the QR code. The file has the given name. The file is set to be deleted on exit (i.e. File.deleteOnExit()). If you want the file to live beyond the life of the jvm process, you should make a copy.

Parameters:
name - name of the created file
Returns:
qrcode as file
See Also:
file()

stream

public ByteArrayOutputStream stream()
returns a ByteArrayOutputStream representation of the QR code

Returns:
qrcode as stream

writeTo

public void writeTo(OutputStream stream)
writes a representation of the QR code to the supplied OutputStream

Parameters:
stream - the OutputStream to write QR Code to


Copyright © 2013. All Rights Reserved.