Class QRCodeWriter

java.lang.Object
com.google.zxing.qrcode.QRCodeWriter
All Implemented Interfaces:
Writer

public final class QRCodeWriter extends Object implements Writer
This object renders a QR Code as a BitMatrix 2D array of greyscale values.
Author:
dswitkin@google.com (Daniel Switkin)
  • Constructor Details

    • QRCodeWriter

      public QRCodeWriter()
  • Method Details

    • encode

      public BitMatrix encode(String contents, BarcodeFormat format, int width, int height) throws WriterException
      Description copied from interface: Writer
      Encode a barcode using the default settings.
      Specified by:
      encode in interface Writer
      Parameters:
      contents - The contents to encode in the barcode
      format - The barcode format to generate
      width - The preferred width in pixels
      height - The preferred height in pixels
      Returns:
      BitMatrix representing encoded barcode image
      Throws:
      WriterException - if contents cannot be encoded legally in a format
    • encode

      public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints) throws WriterException
      Specified by:
      encode in interface Writer
      Parameters:
      contents - The contents to encode in the barcode
      format - The barcode format to generate
      width - The preferred width in pixels
      height - The preferred height in pixels
      hints - Additional parameters to supply to the encoder
      Returns:
      BitMatrix representing encoded barcode image
      Throws:
      WriterException - if contents cannot be encoded legally in a format
    • renderResult

      public static BitMatrix renderResult(QRCode code, int width, int height, int quietZone)
      Renders the given QRCode as a BitMatrix, scaling the same to be compliant with the provided dimensions.

      If no scaling is required, both width and height arguments should be non-positive numbers.

      Parameters:
      code - QRCode to be adapted as a BitMatrix
      width - desired width for the QRCode (in pixel units)
      height - desired height for the QRCode (in pixel units)
      quietZone - the size of the QR quiet zone (in pixel units)
      Returns:
      BitMatrix instance
      Throws:
      IllegalStateException - if code does not have a Matrix
      NullPointerException - if code is null