Class ReplaceableImage

java.lang.Object
com.codename1.ui.Image
com.codename1.ui.EncodedImage
com.codename1.components.ReplaceableImage
All Implemented Interfaces:
ActionSource

public final class ReplaceableImage extends EncodedImage
Allows the image data to be replaced at runtime when a different image is available. The only limitation is that the image width/height must be identical and opacity status can't change (an opaque image can't be made translucent and visa versa).
  • Method Details

    • create

      public static ReplaceableImage create(EncodedImage placeholder)

      Creates an encoded image that can later be replaced with a different image

      Parameters
      • placeholder: a temporary image
      Returns

      image that will be replaceable later on

    • getImageData

      public byte[] getImageData()

      Returns the byte array data backing the image allowing the image to be stored and discarded completely from RAM.

      Returns

      byte array used to create the image, e.g. encoded PNG, JPEG etc.

      Overrides:
      getImageData in class EncodedImage
    • replace

      public void replace(EncodedImage newImage)

      Replaces the current image with the new image which must match the dimensions etc. of the previous image.

      Parameters
      • newImage: the image to apply
    • animate

      public boolean animate()
      Overrides:
      animate in class Image
    • isAnimation

      public boolean isAnimation()

      Returns true if this is an animated image

      Returns

      true if this image represents an animation

      Overrides:
      isAnimation in class EncodedImage
    • isOpaque

      public boolean isOpaque()

      Indicates whether this image is opaque or not

      Returns

      true if the image is completely opqaque which allows for some heavy optimizations

      Overrides:
      isOpaque in class EncodedImage