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

## jgame
Class ImageUtil

    java.lang.Object
      jgame.ImageUtil

    public class ImageUtil

extends java.lang.Object

Some handy utilities for loading an manipulating images; used internally by jgame.

Field Summary
`java.awt.MediaTracker` | `mediatracker`
`jgame.ImageUtil.DummyObserver` | `observer`

Constructor Summary
`ImageUtil(java.awt.Component comp)`

Method Summary
`java.awt.image.BufferedImage` | `createCompatibleImage(int width, int height, int transparency)` Create empty image with given alpha mode that should be efficient on this display
`java.awt.Image` | `crop(java.awt.Image img, int x, int y, int width, int height)`
`void` | `ensureLoaded(java.awt.Image img)`
`java.awt.Image` | `flip(java.awt.Image img, boolean horiz, boolean vert)`
`int[]` | `getPixels(java.awt.Image img)`
`int[]` | `getPixels(java.awt.Image img, int x, int y, int width, int height)`
`java.awt.Dimension` | `getSize(java.awt.Image img)`
`boolean` | `isOpaque(java.awt.Image img, int alpha_thresh)` true means the image has some transparent pixels below the given alpha threshold, false means image is completely opaque.
`java.awt.Image` | `loadImage(java.lang.String imgfile)` Load image from resource path (using getResource).
`java.awt.Image` | `loadImage(java.net.URL imgurl)` Behaves like loadImage(String).
`void` | `purgeImage(java.lang.String imgfile)` Purge image with the given resourcename from the cache.
`java.awt.Image` | `rotate(java.awt.Image img, int angle)` for angle, only increments of 90 are allowed
`java.awt.Image` | `scale(java.awt.Image img, int width, int height)` Returns a smoothly scaled image using getScaledInstance.
`java.awt.Image` | `toCompatibleBitmask(java.awt.Image img, int thresh, java.awt.Color bg_col, boolean fast)` Turn a (possibly) translucent or indexed image into a display-compatible bitmask image using the given alpha threshold and render-to-background colour.

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

Field Detail

### mediatracker

    public java.awt.MediaTracker mediatracker

### observer

    public jgame.ImageUtil.DummyObserver observer

Constructor Detail

### ImageUtil

    public ImageUtil(java.awt.Component comp)

Method Detail

### loadImage

    public java.awt.Image loadImage(java.lang.String imgfile)

  Load image from resource path (using getResource). Note that GIFs are loaded as _translucent_ indexed images. Images are cached: loading an image with the same name twice will get the cached image the second time. If you want to remove an image from the cache, use purgeImage. Throws JGError when there was an error.

### loadImage

    public java.awt.Image loadImage(java.net.URL imgurl)

  Behaves like loadImage(String). Returns null if there was an error.

### purgeImage

    public void purgeImage(java.lang.String imgfile)

  Purge image with the given resourcename from the cache.

### getSize

    public java.awt.Dimension getSize(java.awt.Image img)

### isOpaque

    public boolean isOpaque(java.awt.Image img,
                            int alpha_thresh)

  true means the image has some transparent pixels below the given alpha threshold, false means image is completely opaque. It actually checks the alpha channel pixel for pixel.

### getPixels

    public int[] getPixels(java.awt.Image img)

### getPixels

    public int[] getPixels(java.awt.Image img,
                           int x,
                           int y,
                           int width,
                           int height)

### rotate

    public java.awt.Image rotate(java.awt.Image img,
                                 int angle)

  for angle, only increments of 90 are allowed

### flip

    public java.awt.Image flip(java.awt.Image img,
                               boolean horiz,
                               boolean vert)

### scale

    public java.awt.Image scale(java.awt.Image img,
                                int width,
                                int height)

  Returns a smoothly scaled image using getScaledInstance. This method has interesting behaviour. The scaled image retains its type (indexed/rgb and bitmask/translucent), and the algorithm tries to scale smoothly within these constraints. For indexed, interpolated pixels are rounded to the existing indexed colours. For bitmask, the behaviour depends on the platform. On WinXP/J1.2 I found that the colour _behind_ each transparent pixel is used to interpolate between nontransparent and transparent pixels. On BSD/J1.4 I found that the colours of transparent pixels are never used, and only the nontransparent pixels are used when interpolating a region with mixed transparent/nontransparent pixels.

### ensureLoaded

    public void ensureLoaded(java.awt.Image img)
                      throws java.lang.Exception

  Throws:
    `java.lang.Exception`

### crop

    public java.awt.Image crop(java.awt.Image img,
                               int x,
                               int y,
                               int width,
                               int height)

### toCompatibleBitmask

    public java.awt.Image toCompatibleBitmask(java.awt.Image img,
                                              int thresh,
                                              java.awt.Color bg_col,
                                              boolean fast)

  Turn a (possibly) translucent or indexed image into a display-compatible bitmask image using the given alpha threshold and render-to-background colour. The alpha values in the image are set to either 0 (below threshold) or 255 (above threshold). The render-to-background colour bg_col is used to determine how the pixels overlapping transparent pixels should be rendered. The fast algorithm just sets the colour behind the transparent pixels in the image (for bitmask source images); the slow algorithm actually renders the image to a background of bg_col (for translucent sources).

  Parameters:
    `thresh` - alpha threshold between 0 and 255
    `fast` - use fast algorithm (only set bg_col behind transp. pixels)

### createCompatibleImage

    public java.awt.image.BufferedImage createCompatibleImage(int width,
                                                              int height,
                                                              int transparency)

  Create empty image with given alpha mode that should be efficient on this display

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