Class QRCode

java.lang.Object
org.attribyte.snook.QRCode

public class QRCode extends Object
Generate QR codes. See: https://www.nayuki.io/page/qr-code-generator-library
  • Field Details

    • DEFAULT_SCALE

      public static final int DEFAULT_SCALE
      The default scale (4).
      See Also:
    • DEFAULT_BORDER

      public static final int DEFAULT_BORDER
      The default border (10).
      See Also:
    • DEFAULT_DARK

      public static final int DEFAULT_DARK
      The default dark color (0).
      See Also:
    • DEFAULT_DARK_TRANSPARENT

      public static final int DEFAULT_DARK_TRANSPARENT
      The default dark color ().
    • DEFAULT_LIGHT

      public static final int DEFAULT_LIGHT
      The default light color (16777215).
      See Also:
    • DEFAULT_MIN_VERSION

      public static final int DEFAULT_MIN_VERSION
      The default minimum version (1).
      See Also:
    • DEFAULT_MAX_VERSION

      public static final int DEFAULT_MAX_VERSION
      The default maximum version (40).
      See Also:
    • DEFAULT_MASK

      public static final int DEFAULT_MASK
      The default mask (-1).
      See Also:
    • DEFAULT_BOOST_ECL

      public static final boolean DEFAULT_BOOST_ECL
      The default ECL boost (true).
      See Also:
    • DEFAULT_TRANSPARENT_BACKGROUND

      public static final boolean DEFAULT_TRANSPARENT_BACKGROUND
      The default transparent background (false).
      See Also:
  • Constructor Details

    • QRCode

      public QRCode()
  • Method Details

    • main

      public static void main(String[] args) throws IOException
      Generate a QR code from the command line. -outputFile, -scale, -border, -lightColor, -darkColor, -mask, -minVersion, -maxVersion, -boostEcl
      Parameters:
      args - The arguments.
      Throws:
      IOException
    • generate

      public static void generate(String text, OutputStream os) throws IOException
      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

      public static String generateHex(String text, QRCode.Options options) throws IOException
      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

      public static String generateImageData(String text, QRCode.Options options) throws IOException
      Generates the value for display as an HTML img.src attribute.
      Parameters:
      text - The text.
      options - The generation options.
      Returns:
      The src value.
      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 (not null)
      scale - the side length (measured in pixels, must be positive) of each module
      border - 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 (not null)
      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