## loci.formats
Class ImageTools

    java.lang.Object
      loci.formats.ImageTools

public abstract class ImageTools
extends Object

A utility class with convenience methods for manipulating images. Much code was stolen and adapted from DrLaszloJamf's posts at: http://forum.java.sun.com/thread.jspa?threadID=522483

Field Summary
`protected static Component` `OBS` ImageObserver for working with AWT images.

Constructor Summary
`ImageTools()`

Method Summary
`static BufferedImage` `copyScaled(BufferedImage source, BufferedImage target, Object hint)` Copies the source image into the target, applying scaling.
`static byte[][]` `getBytes(BufferedImage image)` Extracts pixel data as arrays of unsigned bytes, one per channel.
`static GraphicsConfiguration` `getDefaultConfiguration()` Gets the default graphics configuration for the environment.
`static double[][]` `getDoubles(BufferedImage image)` Extracts pixel data as arrays of doubles, one per channel.
`static float[][]` `getFloats(BufferedImage image)` Extracts pixel data as arrays of floats, one per channel.
`static int[][]` `getInts(BufferedImage image)` Extracts pixel data as arrays of signed integers, one per channel.
`static Object` `getPixels(BufferedImage image)` Gets the image's pixel data as arrays of primitives, one per channel.
`static short[][]` `getShorts(BufferedImage image)` Extracts pixel data as arrays of unsigned shorts, one per channel.
`static Dimension` `getSize(Image image)` Gets the width and height of the given AWT image, waiting for it to finish loading if necessary.
`static boolean` `loadImage(Image image)` Ensures the given AWT image is fully loaded.
`static BufferedImage` `makeBuffered(Image image)` Creates a buffered image from the given AWT image object.
`static BufferedImage` `makeBuffered(Image image, ColorModel cm)` Creates a buffered image possessing the given color model, from the specified AWT image object.
`static ColorModel` `makeColorModel(int c, int dataType)` Gets a color space for the given number of color components.
`static BufferedImage` `makeCompatible(BufferedImage image, GraphicsConfiguration gc)` Creates a buffered image compatible with the given graphics configuration, using the given buffered image as a source.
`static BufferedImage` `makeImage(byte[][] data, int w, int h)` Creates an image from the given unsigned byte data.
`static BufferedImage` `makeImage(byte[] data, int w, int h)` Creates an image from the given single-channel unsigned byte data.
`static BufferedImage` `makeImage(byte[] data, int w, int h, int c, boolean interleaved)` Creates an image from the given unsigned byte data.
`static BufferedImage` `makeImage(double[][] data, int w, int h)` Creates an image from the given double-precision floating point data.
`static BufferedImage` `makeImage(double[] data, int w, int h)` Creates an image from the given single-channel double data.
`static BufferedImage` `makeImage(double[] data, int w, int h, int c, boolean interleaved)` Creates an image from the given double data.
`static BufferedImage` `makeImage(float[][] data, int w, int h)` Creates an image from the given single-precision floating point data.
`static BufferedImage` `makeImage(float[] data, int w, int h)` Creates an image from the given single-channel float data.
`static BufferedImage` `makeImage(float[] data, int w, int h, int c, boolean interleaved)` Creates an image from the given float data.
`static BufferedImage` `makeImage(int[][] data, int w, int h)` Creates an image from the given signed int data.
`static BufferedImage` `makeImage(int[] data, int w, int h)` Creates an image from the given single-channel signed int data.
`static BufferedImage` `makeImage(int[] data, int w, int h, int c, boolean interleaved)` Creates an image from the given signed int data.
`static BufferedImage` `makeImage(short[][] data, int w, int h)` Creates an image from the given unsigned short data.
`static BufferedImage` `makeImage(short[] data, int w, int h)` Creates an image from the given single-channel unsigned short data.
`static BufferedImage` `makeImage(short[] data, int w, int h, int c, boolean interleaved)` Creates an image from the given unsigned short data.
`static BufferedImage` `makeType(BufferedImage image, int type)` Copies the given image into a result with the specified data type.
`static BufferedImage` `mergeChannels(BufferedImage[] images)` Merges the given images into a single multi-channel image.
`static BufferedImage` `scale(BufferedImage source, int width, int height)` Scales the image using the most appropriate API, with the resultant image having the same color model as the original image.
`static BufferedImage` `scale2D(BufferedImage image, int width, int height, Object hint, ColorModel cm)` Scales the image using the Java2D API, with the resultant image having the given color model.
`static BufferedImage` `scale2D(BufferedImage image, int width, int height, Object hint, GraphicsConfiguration gc)` Scales the image using the Java2D API, with the resultant image optimized for the given graphics configuration.
`static Image` `scaleAWT(BufferedImage source, int width, int height, int hint)` Scales the image using the AWT Image API.
`static BufferedImage[]` `splitChannels(BufferedImage image)` Splits the given multi-channel image into single-channel images.

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

Field Detail

### OBS

    protected static final Component OBS

  ImageObserver for working with AWT images.

Constructor Detail

### ImageTools

    public ImageTools()

Method Detail

### makeImage

    public static BufferedImage makeImage(byte[] data,
                                          int w,
                                          int h,
                                          int c,
                                          boolean interleaved)

  Creates an image from the given unsigned byte data. If the interleaved flag is set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.

### makeImage

    public static BufferedImage makeImage(short[] data,
                                          int w,
                                          int h,
                                          int c,
                                          boolean interleaved)

  Creates an image from the given unsigned short data. If the interleaved flag is set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.

### makeImage

    public static BufferedImage makeImage(int[] data,
                                          int w,
                                          int h,
                                          int c,
                                          boolean interleaved)

  Creates an image from the given signed int data. If the interleaved flag is set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.

### makeImage

    public static BufferedImage makeImage(float[] data,
                                          int w,
                                          int h,
                                          int c,
                                          boolean interleaved)

  Creates an image from the given float data. If the interleaved flag is set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.

### makeImage

    public static BufferedImage makeImage(double[] data,
                                          int w,
                                          int h,
                                          int c,
                                          boolean interleaved)

  Creates an image from the given double data. If the interleaved flag is set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.

### makeImage

    public static BufferedImage makeImage(byte[][] data,
                                          int w,
                                          int h)

  Creates an image from the given unsigned byte data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.

### makeImage

    public static BufferedImage makeImage(short[][] data,
                                          int w,
                                          int h)

  Creates an image from the given unsigned short data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.

### makeImage

    public static BufferedImage makeImage(int[][] data,
                                          int w,
                                          int h)

  Creates an image from the given signed int data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.

### makeImage

    public static BufferedImage makeImage(float[][] data,
                                          int w,
                                          int h)

  Creates an image from the given single-precision floating point data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.

### makeImage

    public static BufferedImage makeImage(double[][] data,
                                          int w,
                                          int h)

  Creates an image from the given double-precision floating point data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.

### makeImage

    public static BufferedImage makeImage(byte[] data,
                                          int w,
                                          int h)

  Creates an image from the given single-channel unsigned byte data.

### makeImage

    public static BufferedImage makeImage(short[] data,
                                          int w,
                                          int h)

  Creates an image from the given single-channel unsigned short data.

### makeImage

    public static BufferedImage makeImage(int[] data,
                                          int w,
                                          int h)

  Creates an image from the given single-channel signed int data.

### makeImage

    public static BufferedImage makeImage(float[] data,
                                          int w,
                                          int h)

  Creates an image from the given single-channel float data.

### makeImage

    public static BufferedImage makeImage(double[] data,
                                          int w,
                                          int h)

  Creates an image from the given single-channel double data.

### getPixels

    public static Object getPixels(BufferedImage image)

  Gets the image's pixel data as arrays of primitives, one per channel. The returned type will be either byte[][], short[][], int[][], float[][] or double[][], depending on the image's transfer type.

### getBytes

    public static byte[][] getBytes(BufferedImage image)

  Extracts pixel data as arrays of unsigned bytes, one per channel.

### getShorts

    public static short[][] getShorts(BufferedImage image)

  Extracts pixel data as arrays of unsigned shorts, one per channel.

### getInts

    public static int[][] getInts(BufferedImage image)

  Extracts pixel data as arrays of signed integers, one per channel.

### getFloats

    public static float[][] getFloats(BufferedImage image)

  Extracts pixel data as arrays of floats, one per channel.

### getDoubles

    public static double[][] getDoubles(BufferedImage image)

  Extracts pixel data as arrays of doubles, one per channel.

### makeType

    public static BufferedImage makeType(BufferedImage image,
                                         int type)

  Copies the given image into a result with the specified data type.

### splitChannels

    public static BufferedImage[] splitChannels(BufferedImage image)

  Splits the given multi-channel image into single-channel images.

### mergeChannels

    public static BufferedImage mergeChannels(BufferedImage[] images)

  Merges the given images into a single multi-channel image.

### copyScaled

    public static BufferedImage copyScaled(BufferedImage source,
                                           BufferedImage target,
                                           Object hint)

  Copies the source image into the target, applying scaling.

### scale2D

    public static BufferedImage scale2D(BufferedImage image,
                                        int width,
                                        int height,
                                        Object hint,
                                        GraphicsConfiguration gc)

  Scales the image using the Java2D API, with the resultant image optimized for the given graphics configuration.

### scale2D

    public static BufferedImage scale2D(BufferedImage image,
                                        int width,
                                        int height,
                                        Object hint,
                                        ColorModel cm)

  Scales the image using the Java2D API, with the resultant image having the given color model.

### scaleAWT

    public static Image scaleAWT(BufferedImage source,
                                 int width,
                                 int height,
                                 int hint)

  Scales the image using the AWT Image API.

### scale

    public static BufferedImage scale(BufferedImage source,
                                      int width,
                                      int height)

  Scales the image using the most appropriate API, with the resultant image having the same color model as the original image.

### makeBuffered

    public static BufferedImage makeBuffered(Image image)

  Creates a buffered image from the given AWT image object. If the AWT image is already a buffered image, no new object is created.

### makeBuffered

    public static BufferedImage makeBuffered(Image image,
                                             ColorModel cm)

  Creates a buffered image possessing the given color model, from the specified AWT image object. If the AWT image is already a buffered image with the given color model, no new object is created.

### loadImage

    public static boolean loadImage(Image image)

  Ensures the given AWT image is fully loaded.

### getSize

    public static Dimension getSize(Image image)

  Gets the width and height of the given AWT image, waiting for it to finish loading if necessary.

### makeCompatible

    public static BufferedImage makeCompatible(BufferedImage image,
                                               GraphicsConfiguration gc)

  Creates a buffered image compatible with the given graphics configuration, using the given buffered image as a source. If gc is null, the default graphics configuration is used.

### getDefaultConfiguration

    public static GraphicsConfiguration getDefaultConfiguration()

  Gets the default graphics configuration for the environment.

### makeColorModel

    public static ColorModel makeColorModel(int c,
                                            int dataType)

  Gets a color space for the given number of color components.