#

| Chapter 19 java.awt Reference |

# Image

## Name

Image

##

## Description

The `Image` class represents a displayable object maintained in memory. Because `Image` is an abstract class, you never work with the `Image` class itself, but with a platform specific subclass. However, you should never need to know what that subclass is. To draw on an `Image`, get its graphics context.

## Class Definition

    public abstract class java.awt.Image
        extends java.lang.Object
        implements java.io.Serializable {

      // Constants
      public final static int SCALE_AREA_AVERAGING;
      public final static int SCALE_DEFAULT;
      public final static int SCALE_FAST;
      public final static int SCALE_REPLICATE;
      public final static int SCALE_SMOOTH;
      public final static Object UndefinedProperty;

      // Instance Methods
      public abstract void flush();
      public abstract Graphics getGraphics();
      public abstract int getHeight (ImageObserver observer);
      public abstract Object getProperty (String name, ImageObserver observer);
      public Image getScaledInstance (int width, int height, int hints);
      public abstract ImageProducer getSource();
      public abstract int getWidth (ImageObserver observer);
    }

## Constants

### SCALE_AREA_AVERAGING

#### public final static int SCALE_AREA_AVERAGING

Flag that requests use of `AreaAveragingScaleFilter`.

### SCALE_DEFAULT

#### public final static int SCALE_DEFAULT

Flag that requests use of the default image scaling algorithm.

### SCALE_FAST

#### public final static int SCALE_FAST

Flag that requests use of an image scaling algorithm that is faster rather than smoother.

### SCALE_REPLICATE

#### public final static int SCALE_REPLICATE

Flag that requests use of ReplicateScaleFilter.

### SCALE_SMOOTH

#### public final static int SCALE_SMOOTH

Flag that requests use of an image scaling algorithm that is smoother rather than faster.

### UndefinedProperty

#### public final static Object UndefinedProperty

Possible return object from `getProperty()`.

## Instance Methods

### flush

#### public abstract void flush()

Description

  Resets image to initial state.

### getGraphics

#### public abstract Graphics getGraphics()

Throws

  ClassCastException

    If image created from file or URL.

Returns

  The graphics context of the image.

Description

  Gets the graphics context of the image for drawing.

### getHeight

#### public abstract int getHeight (ImageObserver observer)

Parameters

  observer

    An image observer; usually the `Component` on which the image is rendered.

Returns

  Image height, or -1 if the height is not yet available.

### getProperty

#### public abstract Object getProperty (String name, ImageObserver observer)

Parameters

  name

    Name of the property to fetch.

  observer

    An image observer; usually the `Component` on which the image is rendered.

Returns

  `Object` representing the requested property, `null`, or `UndefinedProperty`.

Throws

  ArrayIndexOutOfBoundsException

    If `offset` or `length` is invalid.

Description

  Retrieves a property from the image's private property list.

### getScaledInstance

#### public Image getScaledInstance (int width, int height, int hints)

Parameters

  width

    The width for the scaled image. Use -1 to preserve the aspect ratio with reference to `height`.

  height

    The height for the scaled image. Use -1 to preserve the aspect ratio with reference to `width`.

  hints

    One or more of the `SCALE_` constants.

Returns

  The scaled image. It may be loaded asynchronously, even if the original image was fully loaded.

Description

  Creates a copy of an image, scaled to `width` x `height` and using an algorithm chosen based on the `hints` given.

### getSource

#### public abstract ImageProducer getSource()

Returns

  The `ImageProducer` of the image.

### getWidth

#### public abstract int getWidth (ImageObserver observer)

Parameters

  observer

    An image observer; usually the `Component` on which the image is rendered.

Returns

  Image width, or -1 if the width is not yet available.

## See Also

`Graphics`, `ImageObserver`, `ImageProducer`, `Object`, `Properties`, `String`

IllegalComponentStateException |  | Insets