GTGE API

com.golden.gamedev.util
Class ImageUtil

java.lang.Object
  extended by com.golden.gamedev.util.ImageUtil

public class ImageUtil
extends Object

Utility class for creating, loading, and manipulating image.


Field Summary
static GraphicsConfiguration CONFIG
           
 
Method Summary
static BufferedImage applyMask(Image img, Color keyColor)
          Applying mask into image by specified masking color.
static BufferedImage createImage(int width, int height)
          Creates blank image with specified width, height, without transparency (opaque).
static BufferedImage createImage(int width, int height, int transparency)
          Creates blank image with specified width, height, and transparency.
static BufferedImage flip(BufferedImage src)
          Flips an image.
static BufferedImage fromByteArray(byte[] imagebytes)
          Constructs image from byte array.
static BufferedImage getImage(URL url)
          Loads an image from URL without transparency (completely opaque).
static BufferedImage getImage(URL url, Color keyColor)
          Loads an image from URL with specified masking color.
static BufferedImage getImage(URL url, int transparency)
          Loads an image from URL and specified transparency.
static BufferedImage[] getImages(URL url, int col, int row)
          Loads and splits image from URL, without transparency.
static BufferedImage[] getImages(URL url, int col, int row, Color keyColor)
          Loads and splits image from URL with specified masking color.
static BufferedImage[] getImages(URL url, int col, int row, int transparency)
          Loads and splits image from URL and transparency.
static BufferedImage resize(BufferedImage src, int w, int h)
          Resizes an image into specified size.
static BufferedImage rotate(BufferedImage src, int angle)
          Rotates an image by specified angle (clockwise).
static void saveImage(BufferedImage image, File imagefile)
          Saves image into specified file.
static BufferedImage[] splitImages(BufferedImage image, int col, int row)
          Splits a single image into an array of images.
static byte[] toByteArray(BufferedImage image, String extension)
          Saves image into byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG

public static final GraphicsConfiguration CONFIG
Method Detail

getImage

public static BufferedImage getImage(URL url,
                                     int transparency)
Loads an image from URL and specified transparency.

Parameters:
url - image url
transparency - image transparency
Returns:
Loaded image.
See Also:
Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT

getImage

public static BufferedImage getImage(URL url)
Loads an image from URL without transparency (completely opaque).

Parameters:
url - image url
Returns:
Loaded image.

getImage

public static BufferedImage getImage(URL url,
                                     Color keyColor)
Loads an image from URL with specified masking color.

Parameters:
url - image url
keyColor - masking color
Returns:
Loaded image.

getImages

public static BufferedImage[] getImages(URL url,
                                        int col,
                                        int row,
                                        int transparency)
Loads and splits image from URL and transparency. The images will be splitted by specified column and row.

Parameters:
url - image url
col - column
row - row
transparency - image transparency
Returns:
Loaded and splitted images.
See Also:
Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT

getImages

public static BufferedImage[] getImages(URL url,
                                        int col,
                                        int row)
Loads and splits image from URL, without transparency. The images will be splitted by specified column and row.

Parameters:
url - image url
col - column
row - row
Returns:
Loaded and splitted images.

getImages

public static BufferedImage[] getImages(URL url,
                                        int col,
                                        int row,
                                        Color keyColor)
Loads and splits image from URL with specified masking color. The images will be split by specified column and row.

Parameters:
url - image url
col - column
row - row
keyColor - masking color
Returns:
Loaded and splitted images.

createImage

public static BufferedImage createImage(int width,
                                        int height,
                                        int transparency)
Creates blank image with specified width, height, and transparency.

Parameters:
width - image width
height - image height
transparency - image transparency
Returns:
Blank image.
See Also:
Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT

createImage

public static BufferedImage createImage(int width,
                                        int height)
Creates blank image with specified width, height, without transparency (opaque).

Parameters:
width - image width
height - image height
Returns:
Blank image.

applyMask

public static BufferedImage applyMask(Image img,
                                      Color keyColor)
Applying mask into image by specified masking color.

Color in the image that match with specified masking color will be converted to transparent.

Parameters:
img - the source image
keyColor - masking color
Returns:
Masked image.

splitImages

public static BufferedImage[] splitImages(BufferedImage image,
                                          int col,
                                          int row)
Splits a single image into an array of images. The image is cut by specified column and row.

Parameters:
image - the source image
col - image column
row - image row
Returns:
Array of images cutted by specified column and row.

rotate

public static BufferedImage rotate(BufferedImage src,
                                   int angle)
Rotates an image by specified angle (clockwise).

For example:

    BufferedImage image;

    // rotate the image by 90 degree clockwise
    BufferedImage rotated = ImageUtil.rotate(image, 90);
 

Parameters:
src - the source image
angle - angle rotation
Returns:
Rotated image.

resize

public static BufferedImage resize(BufferedImage src,
                                   int w,
                                   int h)
Resizes an image into specified size.

For example:

    BufferedImage image;

    // resize the image to 200x300 size
    BufferedImage resized = ImageUtil.resize(image, 200, 300);

    // double the size of the image
    BufferedImage doubleResize = ImageUtil.resize(image,
                                                  image.getWidth()*2,
                                                  image.getHeight()*2);
 

Parameters:
src - the source image
w - width of the resized image
h - height of the resized image
Returns:
Resized image.

flip

public static BufferedImage flip(BufferedImage src)
Flips an image.

Parameters:
src - the source image
Returns:
Flipped image.

saveImage

public static void saveImage(BufferedImage image,
                             File imagefile)
Saves image into specified file.

Parameters:
image - image to be saved
imagefile - file where the image will be saved

toByteArray

public static byte[] toByteArray(BufferedImage image,
                                 String extension)
Saves image into byte array.

Parameters:
image - image to be saved
extension - the image extension (png)
Returns:
Image in byte array.
See Also:
fromByteArray(byte[])

fromByteArray

public static BufferedImage fromByteArray(byte[] imagebytes)
Constructs image from byte array.

Parameters:
imagebytes - image in byte array
Returns:
Image object.
See Also:
toByteArray(BufferedImage, String)

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id