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

public final class QRCodeWriterextends Object implements Writer
This object renders a QR Code as a BitMatrix 2D array of greyscale values.

Encodes text content into a QR Code barcode using the ZXing library's encoder, supporting various error correction levels and encoding hint types.

  • Field Details

    • QUIET_ZONE_SIZE

      private static final int QUIET_ZONE_SIZE
      Blank modules left around the symbol
      See Also:
  • Constructor Details

    • QRCodeWriter

      public QRCodeWriter()
      A stateless writer: everything it needs arrives with the encode() arguments, so a bare instance is ready to use.
  • 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
      Description copied from interface: Writer
      Encode a barcode using the specified settings and optional hints.
      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

      private static BitMatrix renderResult(QRCode code, int width, int height, int quietZone)
      Renders the QR code as a bit matrix, padding with the quiet zone. Note that the input matrix uses 0 == white, 1 == black, while the output matrix uses 0 == black, 255 == white (i.e. an 8 bit greyscale bitmap).
      Parameters:
      code - the QR code to render
      width - the requested width, in modules
      height - the requested height, in modules
      quietZone - the quiet zone width, in modules
      Returns:
      the rendered bit matrix