Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## echopointng.image
Class EncodedImageReference

    java.lang.Object
      nextapp.echo2.app.StreamImageReference
          echopointng.image.EncodedImageReference

All Implemented Interfaces:
  java.io.Serializable, ImageReference, RenderIdSupport

Direct Known Subclasses:
  TextImageReference

    public class EncodedImageReference

extends StreamImageReference
implements java.io.Serializable

The `EncodedImageReference` class is an ImageReference that can render `java.awt.Image` objects. The `ImageEncoder` used to encode the image data is pluggable.

This class allows you to balance memory usage versus processor usage.

By default the output of the encoding is not kept in memory, so the encoding runs every time the image needs to be rendered. However this can be changed so that the encoding results are kept in memory.

If the image data is cached, they are kept in a `SoftReference` so they may be reclaimed by the GC if memory gets low.

The AWT Image object that is renderered is by default kept in memory. You can change this by deriving a new class from `EncodedImageReference` and then drawing the AWT image on as needed basis during the call to `getImage()`.

See Also:
  Serialized Form

Constructor Summary
`EncodedImageReference()` Constructs an `EncodedImageReference` without an image.
`EncodedImageReference(java.awt.Image image)` Constructs an `EncodedImageReference` with an image.

Method Summary
`java.lang.String` | `getContentType()` Returns the valid RFC 1521 image content type (e.g., image/png, image/jpeg, image/gif, etc) of the image.
`ImageEncoder` | `getEncoder()` Returns the `ImageEncoder` in use.
`Extent` | `getHeight()` Returns the height of the image, or null if the size is unknown.
`java.awt.Image` | `getImage()` Returns the `Image` in use.
`java.lang.String` | `getRenderId()` Returns an identifier that is unique within the `ApplicationInstance` with which the implementor will be used.
`Extent` | `getWidth()` Returns the width of the image, or null if the size is unknown.
`boolean` | `isKeptInMemory()` Returns true if the encoded image is cached in memory.
`boolean` | `isValid()` This returns whether the AWT Image data is currently valid.
`void` | `render(java.io.OutputStream out)` Renders the image data in its native format to the given output stream.
`void` | `setEncoder(ImageEncoder encoder)` Sets the `ImageEncoder` to use for encoding
`void` | `setImage(java.awt.Image image)` Sets the `Image` to encode.
`void` | `setKeptInMemory(boolean b)` If set to true, the image will be encoded only as necessary and then cached in memory, otherwise it will be encoded as required.
`void` | `setValid(boolean valid)` This controls whether the AWT Image data is currently valid.
`void` | `update()` Not supported.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### EncodedImageReference

    public EncodedImageReference()

  Constructs an `EncodedImageReference` without an image. You must of course call `setImage()` before the image is rendered, otherwise there will be nothing to render.

  Another alternative would be to derive a new class and override `getImage()` to provide the image as necessary. This will use a smallest amount of memory at the expense of more CPU processing.

### EncodedImageReference

    public EncodedImageReference(java.awt.Image image)

  Constructs an `EncodedImageReference` with an image.

  Parameters:
    `image` - A java.awt.Image to be displayed. If you intend to extend this class and override the getImage() method to return images only as they are needed, then you may pass null to this parameter.

Method Detail

### getRenderId

    public java.lang.String getRenderId()

  Description copied from interface: `RenderIdSupport`
  Returns an identifier that is unique within the `ApplicationInstance` with which the implementor will be used.

  Specified by:
    `getRenderId` in interface `RenderIdSupport`
  See Also:
    `RenderIdSupport.getRenderId()`

### getContentType

    public java.lang.String getContentType()

  Description copied from class: `StreamImageReference`
  Returns the valid RFC 1521 image content type (e.g., image/png, image/jpeg, image/gif, etc) of the image.

  Specified by:
    `getContentType` in class `StreamImageReference`
  Returns:
    the content type of the image
  See Also:
    `StreamImageReference.getContentType()`

### getEncoder

    public ImageEncoder getEncoder()

  Returns the `ImageEncoder` in use.

  Returns:
    ImageEncoder

### getHeight

    public Extent getHeight()

  Description copied from interface: `ImageReference`
  Returns the height of the image, or null if the size is unknown.

  Specified by:
    `getHeight` in interface `ImageReference`
  Overrides:
    `getHeight` in class `StreamImageReference`
  Returns:
    the height of the image
  See Also:
    `ImageReference.getHeight()`

### getImage

    public java.awt.Image getImage()

  Returns the `Image` in use.

  You may extend this class and override this method such that images are created only when they are needed, thereby reducing memory usage at the cost of increased processor workload.

  Returns:
    Image - the AWT image object

### getWidth

    public Extent getWidth()

  Description copied from interface: `ImageReference`
  Returns the width of the image, or null if the size is unknown.

  Specified by:
    `getWidth` in interface `ImageReference`
  Overrides:
    `getWidth` in class `StreamImageReference`
  Returns:
    the width of the image
  See Also:
    `ImageReference.getWidth()`

### isKeptInMemory

    public boolean isKeptInMemory()

  Returns true if the encoded image is cached in memory.

  Returns:
    boolean true if the image is kept in memory

### isValid

    public boolean isValid()

  This returns whether the AWT Image data is currently valid.

  Returns:
    - true if the AWT image is valid

### render

    public void render(java.io.OutputStream out)
                throws java.io.IOException

  Description copied from class: `StreamImageReference`
  Renders the image data in its native format to the given output stream.

  Specified by:
    `render` in class `StreamImageReference`
  Parameters:
    `out` - the output stream to write the image
  Throws:
    `java.io.IOException`
  See Also:
    `StreamImageReference.render(java.io.OutputStream)`

### setEncoder

    public void setEncoder(ImageEncoder encoder)

  Sets the `ImageEncoder` to use for encoding

  Parameters:
    `encoder` -

### setImage

    public void setImage(java.awt.Image image)

  Sets the `Image` to encode. This can be null.

  Parameters:
    `image` - - the AWT Image to encode.

### setKeptInMemory

    public void setKeptInMemory(boolean b)

  If set to true, the image will be encoded only as necessary and then cached in memory, otherwise it will be encoded as required.

  Parameters:
    `b` -

### setValid

    public void setValid(boolean valid)

  This controls whether the AWT Image data is currently valid.

  This is used to determine whether a call to `getImage()` should be made. If the encoded image is kept in memory but the image is invalid, then it will be encoded again. If it valid, then the cached encoded image data can be re-used.

  If you derive a new class and override the getImage() method, you should set this to false when the image needs to be re-painted.

  Parameters:
    `valid` - - true if the AWT image data is valid.

### update

    public void update()

  Not supported.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD