# 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 Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `animate()`
  Advances this image's animation state, if it is animated.
  `static ReplaceableImage`
  `create(EncodedImage placeholder)`
  Creates an encoded image that can later be replaced with a different image
  `byte[]`
  `getImageData()`
  Returns the byte array data backing the image allowing the image to be stored and discarded completely from RAM.
  `boolean`
  `isAnimation()`
  Returns true if this is an animated image
  `boolean`
  `isOpaque()`
  Indicates whether this image is opaque or not
  `void`
  `replace(EncodedImage newImage)`
  Replaces the current image with the new image which must match the dimensions etc.

  ### Methods inherited from class EncodedImage

  `asyncLock, create, create, create, create, create, createFromImage, createFromRGB, createMulti, dispose, drawImage, drawImage, getGraphics, getHeight, getImage, getInternal, getWidth, isDisposed, isLocked, lock, modifyAlpha, modifyAlpha, resetCache, rotate, scale, scaled, scaledEncoded, scaledHeight, scaledSmallerRatio, scaledWidth, subImage, toRGB, unlock`

  ### Methods inherited from class Image

  `addActionListener, applyMask, applyMask, applyMaskAutoScale, createImage, createImage, createImage, createImage, createImage, createImage, createImage, createIndexed, createMask, createSVG, exifRotation, exifRotation, exifRotation, fill, fireChangedEvent, flipHorizontally, flipVertically, getExifOrientationTag, getExifOrientationTag, getImageName, getRGB, getRGB, getRGBCached, getSVGDocument, isAlphaMutableImageSupported, isJPEG, isPNG, isSimdOptimizationsEnabled, isSVG, isSVGSupported, mirror, modifyAlphaWithTranslucency, removeActionListener, requiresDrawImage, resetSimdOptimizationsEnabled, rotate180Degrees, rotate270Degrees, rotate90Degrees, scaledLargerRatio, setImageName, setSimdOptimizationsEnabled`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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()

    Advances this image's animation state, if it is animated.

    ###### Returns

    `true` if the animation state changed.

    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`