# Class ComponentImage

java.lang.Object
com.codename1.ui.Image
com.codename1.ui.ComponentImage

All Implemented Interfaces:
  `ActionSource`

public class ComponentImage extends Image
A utility wrapper that allows a Component to be used as an Image so that it can be set as the icon for a Label or button.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `class`
  `ComponentImage.EncodedWrapper`
  A wrapper for ComponentImage to convert it to an EncodedImage.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ComponentImage(Component cmp, int w, int h)`
  Creates a new image that renders the given component.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `animate()`
  Advances this image's animation state, if it is animated.
  `Image`
  `applyMask(java.lang.Object mask)`
  Applies the given alpha mask onto this image and returns the resulting image see the createMask method for indication on how to convert an image into an alpha mask.
  `void`
  `disablePulsingAnimation()`
  Disables the pulsing animation.
  `protected void`
  `drawImage(Graphics g, java.lang.Object nativeGraphics, int x, int y)`
  Draws the image.
  `protected void`
  `drawImage(Graphics g, java.lang.Object nativeGraphics, int x, int y, int w, int h)`
  Callback invoked internally by Codename One to draw the image/frame onto the display.
  `void`
  `enablePulsingAnimation(double currStep, double stepSize, double minAlpha, double maxAlpha)`
  Enables a pulsing animation on the image.
  `Image`
  `fill(int width, int height)`
  Resizes/crops the image so that its center fills the given dimensions.
  `Component`
  `getComponent()`
  Gets the wrapped component that is rendered by this image.
  `int`
  `getHeight()`
  Returns the height of the image
  `int`
  `getWidth()`
  Returns the width of the image
  `boolean`
  `isAnimation()`
  Checks if this is an animation.
  `boolean`
  `isPulsingAnimationEnabled()`
  Checks if pulsing animation is enabled.
  `boolean`
  `requiresDrawImage()`
  Overridden to always return true so that the paint() method is called on this image.
  `void`
  `scale(int width, int height)`
  Scale the image to the given width and height, this is a fast algorithm that preserves translucent information
  `Image`
  `scaled(int width, int height)`
  Returns a scaled version of this image image using the given width and height, this is a fast algorithm that preserves translucent information.
  `void`
  `setAnimation(boolean anim)`
  Sets whether this in an animation.
  `EncodedImage`
  `toEncodedImage()`
  Converts to an encoded image.

  ### Methods inherited from class Image

  `addActionListener, applyMask, applyMaskAutoScale, asyncLock, createImage, createImage, createImage, createImage, createImage, createImage, createImage, createIndexed, createMask, createSVG, dispose, exifRotation, exifRotation, exifRotation, fireChangedEvent, flipHorizontally, flipVertically, getExifOrientationTag, getExifOrientationTag, getGraphics, getImage, getImageName, getRGB, getRGB, getRGBCached, getSVGDocument, isAlphaMutableImageSupported, isJPEG, isLocked, isOpaque, isPNG, isSimdOptimizationsEnabled, isSVG, isSVGSupported, lock, mirror, modifyAlpha, modifyAlpha, modifyAlphaWithTranslucency, removeActionListener, resetSimdOptimizationsEnabled, rotate, rotate180Degrees, rotate270Degrees, rotate90Degrees, scaledHeight, scaledLargerRatio, scaledSmallerRatio, scaledWidth, setImageName, setSimdOptimizationsEnabled, subImage, toRGB, unlock`

  ### Methods inherited from class java.lang.Object

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

- ## Constructor Details

  - ### ComponentImage

    public ComponentImage(Component cmp, int w, int h)

    Creates a new image that renders the given component.

    ###### Parameters

    - `cmp`: The component to render.

    - `w`: The width of the image.

    - `h`: The height of the image.

- ## Method Details

  - ### getComponent

    public Component getComponent()
    Gets the wrapped component that is rendered by this image.

  - ### enablePulsingAnimation

    public void enablePulsingAnimation(double currStep, double stepSize, double minAlpha, double maxAlpha)

    Enables a pulsing animation on the image.

    ###### Parameters

    - `currStep`: The current step.

    - `stepSize`: The step size.

    - `minAlpha`: The min alpha

    - `maxAlpha`: The max alpha

  - ### disablePulsingAnimation

    public void disablePulsingAnimation()
    Disables the pulsing animation.

  - ### isPulsingAnimationEnabled

    public boolean isPulsingAnimationEnabled()
    Checks if pulsing animation is enabled.

  - ### getWidth

    public int getWidth()

    Returns the width of the image

    ###### Returns

    the width of the image

    Overrides:
      `getWidth` in class `Image`

  - ### getHeight

    public int getHeight()

    Returns the height of the image

    ###### Returns

    the height of the image

    Overrides:
      `getHeight` in class `Image`

  - ### scale

    public void scale(int width, int height)

    Scale the image to the given width and height, this is a fast algorithm that preserves translucent information

    ###### Parameters

    - `width`: width for the scaling

    - `height`: height of the scaled image

    ###### Deprecated

    ###### Parameters

    - `width`

    - `height`

    Overrides:
      `scale` in class `Image`

  - ### fill

    public Image fill(int width, int height)
    Description copied from class: `Image`

    Resizes/crops the image so that its center fills the given dimensions. This is similar to `com.codename1.ui.plaf.Style#BACKGROUND_IMAGE_SCALED_FILL`

    ###### Parameters

    - `width`: the width to fill

    - `height`: the height to fill

    ###### Returns

    a new image (or the same image if dimensions happen to match) filling the width/height

    Overrides:
      `fill` in class `Image`

  - ### applyMask

    public Image applyMask(java.lang.Object mask)

    Applies the given alpha mask onto this image and returns the resulting image see the createMask method for indication on how to convert an image into an alpha mask.

    ###### Parameters

    - `mask`: mask object created by the createMask() method.

    ###### Returns

    image masked based on the given object

    ###### Throws

    - `IllegalArgumentException`: if the image size doesn't match the mask size

    ###### Parameters

    - `mask`
    Overrides:
      `applyMask` in class `Image`

  - ### isAnimation

    public boolean isAnimation()
    Checks if this is an animation.
    Overrides:
      `isAnimation` in class `Image`

  - ### setAnimation

    public void setAnimation(boolean anim)

    Sets whether this in an animation.

    ###### Parameters

    - `anim`: True to make this an animated image

  - ### requiresDrawImage

    public boolean requiresDrawImage()
    Overridden to always return true so that the paint() method is called on this image.
    Overrides:
      `requiresDrawImage` in class `Image`

  - ### drawImage

    protected void drawImage(Graphics g, java.lang.Object nativeGraphics, int x, int y)

    Draws the image.

    ###### Parameters

    - `g`: The graphics context

    - `nativeGraphics`: The native graphics context

    - `x`: The x coordinate at which to draw the image.

    - `y`: The y coordinate at which to draw the image.

    Overrides:
      `drawImage` in class `Image`

  - ### drawImage

    protected void drawImage(Graphics g, java.lang.Object nativeGraphics, int x, int y, int w, int h)

    Callback invoked internally by Codename One to draw the image/frame onto the display. Image subclasses can override this method to perform drawing of custom image types.

    ###### Parameters

    - `g`: the graphics object

    - `nativeGraphics`: the underlying native graphics which might be essential for some image types

    - `x`: the x coordinate

    - `y`: the y coordinate

    - `w`: the width to occupy

    - `h`: the height to occupy

    Overrides:
      `drawImage` in class `Image`

  - ### scaled

    public Image scaled(int width, int height)

    Returns a scaled version of this image image using the given width and height, this is a fast algorithm that preserves translucent information. The method accepts -1 to preserve aspect ratio in the given axis.

    ###### Parameters

    - `width`: width for the scaling

    - `height`: height of the scaled image

    ###### Returns

    new image instance scaled to the given height and width

    Overrides:
      `scaled` in class `Image`

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

  - ### toEncodedImage

    public EncodedImage toEncodedImage()
    Converts to an encoded image.