Class LVGLImage

java.lang.Object
com.vuzix.ultralite.LVGLImage

public class LVGLImage extends Object
Represents an image in LVGL format. Use fromBitmap() to convert from Bitmap to LVGLImage.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Maps RGB colors to 1 or 2 bit colors.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Constant for color format value LV_IMG_CF_INDEXED_1BIT
    static final int
    Constant for color format value LV_IMG_CF_INDEXED_2BIT
  • Constructor Summary

    Constructors
    Constructor
    Description
    LVGLImage(int cf, int width, int height, android.graphics.Color[] colors, byte[] pixelData)
    Constructs a new LVGLImage.
  • Method Summary

    Modifier and Type
    Method
    Description
    static LVGLImage
    fromBitmap(android.graphics.Bitmap bitmap, int cf)
    Converts an Android bitmap to LVGLImage.
    static LVGLImage
    fromBitmap(android.graphics.Bitmap bitmap, int cf, LVGLImage.ColorMapper mapper)
    Converts an Android bitmap to LVGLImage using the provided color mapper.
    int
    Get the color format (CF) of the image
    android.graphics.Color[]
    Get the color palette
    int
    Get the height of the image
    byte[]
    Get the pixel data.
    int
    Get the width of the image

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CF_INDEXED_1_BIT

      public static final int CF_INDEXED_1_BIT
      Constant for color format value LV_IMG_CF_INDEXED_1BIT
      See Also:
    • CF_INDEXED_2_BIT

      public static final int CF_INDEXED_2_BIT
      Constant for color format value LV_IMG_CF_INDEXED_2BIT
      See Also:
  • Constructor Details

    • LVGLImage

      public LVGLImage(int cf, int width, int height, android.graphics.Color[] colors, byte[] pixelData)
      Constructs a new LVGLImage.
      Parameters:
      cf - the color format, must be one of CF_INDEXED_1_BIT or CF_INDEXED_2_BIT
      width - the image width, no larger than 2048
      height - the image height, no larger than 2048
      colors - the color palette, must contain 2 colors for CF_INDEXED_1_BIT and 4 colors for CF_INDEXED_2_BIT
      pixelData - the image pixel data
      Throws:
      IllegalArgumentException - if cf is not CF_INDEXED_1_BIT or CF_INDEXED_2_BIT, if colors is not the correct length, if width and height are zero or larger than 2048, if pixelData is null
  • Method Details

    • getCf

      public int getCf()
      Get the color format (CF) of the image
      Returns:
      int value of the color format
    • getWidth

      public int getWidth()
      Get the width of the image
      Returns:
      width in pixels
    • getHeight

      public int getHeight()
      Get the height of the image
      Returns:
      height in pixels
    • getColors

      public android.graphics.Color[] getColors()

      Get the color palette

       Images in CF_INDEXED_1_BIT will have 2 color entries for indexes (0,1).
       Images in CF_INDEXED_2_BIT will have 4 color entries for indexes (0,1,2,3).
      
      Returns:
      Color[] array of colors associated with each encoded pixel color index
    • getPixelData

      public byte[] getPixelData()
      Get the pixel data.
      Returns:
      byte[] array of pixels in packed form (for example: 4 pixels per byte in CF_INDEXED_2_BIT.)
    • fromBitmap

      public static LVGLImage fromBitmap(android.graphics.Bitmap bitmap, int cf)
      Converts an Android bitmap to LVGLImage. Default color mapping will be used and is based on the color format provided. Default color mapping will convert the image to gray scale and choose an appropriate color from the palette. For more control, provide your own color mapper.
      Parameters:
      bitmap - the source Bitmap, can be no larger than 2048x2048
      cf - the color format, must be one of CF_INDEXED_1_BIT or CF_INDEXED_2_BIT
      Returns:
      LVGLImage representation of the provided bitmap
      Throws:
      IllegalArgumentException - if bitmap is null, if cf is not CF_INDEXED_1_BIT or CF_INDEXED_2_BIT, if bitmap width and height are zero or larger than 2048
    • fromBitmap

      public static LVGLImage fromBitmap(android.graphics.Bitmap bitmap, int cf, LVGLImage.ColorMapper mapper)
      Converts an Android bitmap to LVGLImage using the provided color mapper.
      Parameters:
      bitmap - the source Bitmap, can be no larger than 2048x2048
      cf - the color format, must be one of CF_INDEXED_1_BIT or CF_INDEXED_2_BIT
      mapper - a color mapper used to map colors to 1 or 2 bit
      Returns:
      LVGLImage representation of the provided bitmap
      Throws:
      IllegalArgumentException - if bitmap or mapper is null, if cf is not CF_INDEXED_1_BIT or CF_INDEXED_2_BIT, if mapper provides wrong number of colors for the given cf, if bitmap width and height are zero or larger than 2048, if mapper provides an invalid index