Package net.sourceforge.jiu.gui.awt

# Class ImageCreator

java.lang.Object
net.sourceforge.jiu.gui.awt.ImageCreator

public class ImageCreator extends Object
A class to create `Image` objects from various JIU image data types and vice versa. java.awt.Image objects can be used with the AWT and Swing GUI environments.

Author:
  Marco Schmidt

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_ALPHA`
The default transparency value to be used: full opacity.
`private static Frame`
`frame`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`private`
`ImageCreator()`

## Method Summary

Modifier and Type
Method
Description
`static RGB24Image`
`convertImageToRGB24Image(Image image)`
Creates an `RGB24Image` from the argument AWT image instance.
`static BufferedImage`
`convertToAwtBufferedImage(PixelImage image)`
`static BufferedImage`
`convertToAwtBufferedImage(RGB24Image image)`
Convert a JIU `RGB24Image` to a `BufferedImage` with the given alpha value (use `RGBA.DEFAULT_ALPHA` as default).
`static Image`
`convertToAwtImage(BilevelImage image, int alpha)`
Convert a BilevelImage object to an AWT image object.
`static Image`
`convertToAwtImage(Gray16Image image, int alpha)`
Creates an AWT Image object from a Gray16Image object and an alpha value.
`static Image`
`convertToAwtImage(Gray8Image image, int alpha)`
Creates an AWT Image object from a Gray8Image object and an alpha value.
`static Image`
`convertToAwtImage(Paletted8Image image, int alpha)`
`static Image`
`convertToAwtImage(PixelImage image, int alpha)`
Creates an instance of `Image` from an instance of `RGB24Image`.
`static Image`
`convertToAwtImage(RGB24Image image, int alpha)`
`static Image`
`convertToAwtImage(RGB48Image image, int alpha)`
`static Image`
`createImage(int[] pixels, int width, int height)`
Creates a `Image` object from a pixel array.

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

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

## Field Details

### DEFAULT_ALPHA

public static final int DEFAULT_ALPHA
The default transparency value to be used: full opacity.

See Also:
  - Constant Field Values

### frame

private static Frame frame

## Constructor Details

### ImageCreator

private ImageCreator()

## Method Details

### createImage

public static Image createImage(int[] pixels, int width, int height)
Creates a `Image` object from a pixel array. Internally, a `Frame` object is used to call its `Component.createImage(java.awt.image.ImageProducer)` method with a `MemoryImageSource` object.

Parameters:
  `pixels` - the image pixel data in the typical RGBA 32-bit format, one int per pixel
  `width` - the horizontal resolution in pixels of the image to be created
  `height` - the vertical resolution in pixels of the image to be created

### convertToAwtBufferedImage

public static BufferedImage convertToAwtBufferedImage(PixelImage image)

### convertToAwtBufferedImage

public static BufferedImage convertToAwtBufferedImage(RGB24Image image)
Convert a JIU `RGB24Image` to a `BufferedImage` with the given alpha value (use `RGBA.DEFAULT_ALPHA` as default).

Parameters:
  `image` - JIU image to be converted
Returns:
  a new BufferedImage
Since:
  0.14.2

### convertToAwtImage

public static Image convertToAwtImage(PixelImage image, int alpha)
Creates an instance of `Image` from an instance of `RGB24Image`. This will require `image.getWidth() * image.getHeight() * 4` bytes of free memory. This method checks the type of the argument image via instanceof and the calls the right convertToAwtImage method of this class.

Parameters:
  `image` - the RGB24Image to be converted
  `alpha` - alpha value to be used with each pixel
Returns:
  newly-created AWT image instance

### convertToAwtImage

public static Image convertToAwtImage(BilevelImage image, int alpha)
Convert a BilevelImage object to an AWT image object.

Parameters:
  `image` - the image to be converted
  `alpha` - the transparency value to be written to each pixel in the resulting image
Returns:
  newly-created AWT image

### convertToAwtImage

public static Image convertToAwtImage(Gray16Image image, int alpha)
Creates an AWT Image object from a Gray16Image object and an alpha value. This is done by allocating a new int array with image.getWidth() times image.getHeight() elements, copying the data to those ints (using transparency information from the top eight bits of the alpha argument) and calling Toolkit.createImage with a MemoryImageSource of those int[] pixels.

Parameters:
  `image` - the grayscale image to be converted
  `alpha` - the alpha value, bits must only be set in the top eight bits
Returns:
  AWT image created from the argument input image

### convertToAwtImage

public static Image convertToAwtImage(Gray8Image image, int alpha)
Creates an AWT Image object from a Gray8Image object and an alpha value. This is done by allocating a new int array with image.getWidth() times image.getHeight() elements, copying the data to those ints (using transparency information from the top eight bits of the alpha argument) and calling Toolkit.createImage with a MemoryImageSource of those int[] pixels.

Parameters:
  `image` - the grayscale image to be converted
  `alpha` - the alpha value, bits must only be set in the top eight bits
Returns:
  AWT image created from the argument input image

### convertToAwtImage

public static Image convertToAwtImage(Paletted8Image image, int alpha)

### convertToAwtImage

public static Image convertToAwtImage(RGB24Image image, int alpha)

### convertToAwtImage

public static Image convertToAwtImage(RGB48Image image, int alpha)

### convertImageToRGB24Image

public static RGB24Image convertImageToRGB24Image(Image image)
Creates an `RGB24Image` from the argument AWT image instance.

Parameters:
  `image` - AWT image object to be converted to a `RGB24Image`
Returns:
  a `RGB24Image` object holding the image data from the argument image