Class Barcode


  • public class Barcode
    extends Object
    The representation of a 2D barcode.
    Author:
    Martin Lindström (martin@idsec.se), Henrik Bengtsson (extern.henrik.bengtsson@digg.se), Henric Norlander (extern.henric.norlander@digg.se)
    • Constructor Detail

      • Barcode

        public Barcode​(Barcode.BarcodeType type,
                       byte[] image,
                       Barcode.ImageFormat imageFormat,
                       String svgImage,
                       int width,
                       int height,
                       String payload)
        Constructor.
        Parameters:
        type - the type of barcode
        image - byte array representing the barcode image according to the selected image format
        imageFormat - the image format of the code
        svgImage - the barcode image in SVG format
        width - the width in pixels
        height - the height in pixels
        payload - the barcode payload (content)
    • Method Detail

      • getType

        public Barcode.BarcodeType getType()
        Gets the barcode type.
        Returns:
        the barcode type
      • getImageFormat

        public Barcode.ImageFormat getImageFormat()
        Gets the image format of the barcode.
        Returns:
        the image format
      • getImage

        public byte[] getImage()
        Gets the contents that is the barcode image according to the selected image format.
        Returns:
        the image contents representing the barcode
      • getSvgImage

        public String getSvgImage()
        Gets the barcode image as an SVG image.
        Returns:
        the image in SVG format
      • getWidth

        public int getWidth()
        Gets the width of the barcode in pixels.
        Returns:
        the width
      • getHeight

        public int getHeight()
        Gets the height of the barcode in pixels.
        Returns:
        the height
      • getPayload

        public String getPayload()
        Gets the payload/contents of the barcode.
        Returns:
        the payload
      • toBase64Image

        public String toBase64Image()
        Returns a representation of the barcode as a Base64 image.

        For example:

         data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
         AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
         9TXL0Y4OHwAAAABJRU5ErkJggg==
         
         

        The image may then be directly inserted in HTML code as:

         <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
         AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
         9TXL0Y4OHwAAAABJRU5ErkJggg==" scale="0">
         
         
        Returns: