Package org.attribyte.snook
Class QRCode
java.lang.Object
org.attribyte.snook.QRCode
Generate QR codes.
See: https://www.nayuki.io/page/qr-code-generator-library
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe error correction level.static classQR code generation options. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanThe default ECL boost (true).static final intThe default border (10).static final intThe default dark color (0).static final intThe default dark color ().static final intThe default light color (16777215).static final intThe default mask (-1).static final intThe default maximum version (40).static final intThe default minimum version (1).static final intThe default scale (4).static final booleanThe default transparent background (false). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidgenerate(String text, OutputStream os) Generates a QR code (as a PNG) with default values.static com.google.protobuf.ByteStringgenerate(String text, QRCode.Options options) Generate a QR code to an immutable byte string.static voidgenerate(String text, QRCode.Options options, OutputStream os) Generates a QR code (as a PNG) with custom options.static StringgenerateHex(String text, QRCode.Options options) Generates a QR code encoded as base64.static StringgenerateImageData(String text, QRCode.Options options) Generates the value for display as an HTMLimg.srcattribute.static voidGenerate a QR code from the command line.static final BufferedImagetoImage(@NonNull io.nayuki.qrcodegen.QrCode qr, int scale, int border) Returns a raster image depicting the specified QR Code, with the specified module scale and border modules.static final BufferedImagetoImage(@NonNull io.nayuki.qrcodegen.QrCode qr, QRCode.Options options) Copied from: https://github.com/nayuki/QR-Code-generator/blob/master/java/QrCodeGeneratorDemo.java Returns a raster image depicting the specified QR Code, with the specified module scale and border modules.
-
Field Details
-
DEFAULT_SCALE
public static final int DEFAULT_SCALEThe default scale (4).- See Also:
-
DEFAULT_BORDER
public static final int DEFAULT_BORDERThe default border (10).- See Also:
-
DEFAULT_DARK
public static final int DEFAULT_DARKThe default dark color (0).- See Also:
-
DEFAULT_DARK_TRANSPARENT
public static final int DEFAULT_DARK_TRANSPARENTThe default dark color (). -
DEFAULT_LIGHT
public static final int DEFAULT_LIGHTThe default light color (16777215).- See Also:
-
DEFAULT_MIN_VERSION
public static final int DEFAULT_MIN_VERSIONThe default minimum version (1).- See Also:
-
DEFAULT_MAX_VERSION
public static final int DEFAULT_MAX_VERSIONThe default maximum version (40).- See Also:
-
DEFAULT_MASK
public static final int DEFAULT_MASKThe default mask (-1).- See Also:
-
DEFAULT_BOOST_ECL
public static final boolean DEFAULT_BOOST_ECLThe default ECL boost (true).- See Also:
-
DEFAULT_TRANSPARENT_BACKGROUND
public static final boolean DEFAULT_TRANSPARENT_BACKGROUNDThe default transparent background (false).- See Also:
-
-
Constructor Details
-
QRCode
public QRCode()
-
-
Method Details
-
main
Generate a QR code from the command line.-outputFile, -scale, -border, -lightColor, -darkColor, -mask, -minVersion, -maxVersion, -boostEcl- Parameters:
args- The arguments.- Throws:
IOException
-
generate
Generates a QR code (as a PNG) with default values.- Parameters:
text- The embedded text.os- The output stream.- Throws:
IOException- on write error.
-
generate
public static void generate(String text, QRCode.Options options, OutputStream os) throws IOException Generates a QR code (as a PNG) with custom options.- Parameters:
text- The embedded text.options- The options.os- The output stream (not closed).- Throws:
IOException- on write error.
-
generate
public static com.google.protobuf.ByteString generate(String text, QRCode.Options options) throws IOException Generate a QR code to an immutable byte string.- Parameters:
text- The text.options- The generation options.- Returns:
- The byte string.
- Throws:
IOException- on write error.
-
generateHex
Generates a QR code encoded as base64.- Parameters:
text- The text.options- The generation options.- Returns:
- The base64 string.
- Throws:
IOException- on write error.
-
generateImageData
Generates the value for display as an HTMLimg.srcattribute.- Parameters:
text- The text.options- The generation options.- Returns:
- The
srcvalue. - Throws:
IOException- on write error.
-
toImage
public static final BufferedImage toImage(@NonNull io.nayuki.qrcodegen.QrCode qr, int scale, int border) Returns a raster image depicting the specified QR Code, with the specified module scale and border modules.For example, toImage(qr, scale=10, border=4) means to pad the QR Code with 4 light border modules on all four sides, and use 10×10 pixels to represent each module. The resulting image only contains the hex colors 000000 and FFFFFF.
- Parameters:
qr- the QR Code to render (notnull)scale- the side length (measured in pixels, must be positive) of each moduleborder- the number of border modules to add, which must be non-negative- Returns:
- a new image representing the QR Code, with padding and scaling
- Throws:
IllegalArgumentException- if the scale or border is out of range, or if {scale, border, size} cause the image dimensions to exceed Integer.MAX_VALUE
-
toImage
public static final BufferedImage toImage(@NonNull io.nayuki.qrcodegen.QrCode qr, QRCode.Options options) Copied from: https://github.com/nayuki/QR-Code-generator/blob/master/java/QrCodeGeneratorDemo.java Returns a raster image depicting the specified QR Code, with the specified module scale and border modules.For example, toImage(qr, scale=10, border=4) means to pad the QR Code with 4 light border modules on all four sides, and use 10×10 pixels to represent each module.
- Parameters:
qr- the QR Code to render (notnull)options- The QR code options.- Returns:
- a new image representing the QR Code, with padding and scaling
- Throws:
IllegalArgumentException- if the scale or border is out of range, or if {scale, border, size} cause the image dimensions to exceed Integer.MAX_VALUE
-