Top Constructors Methods
com.sun.imageio.plugins.common

public Class ImageUtil

extends Object
Class Inheritance
Imports
java.awt.Rectangle, .Transparency, java.awt.color.ColorSpace, .ICC_ColorSpace, java.awt.image.BufferedImage, .ColorModel, .ComponentColorModel, .ComponentSampleModel, .DataBuffer, .DataBufferByte, .DataBufferInt, .DataBufferShort, .DataBufferUShort, .DirectColorModel, .IndexColorModel, .MultiPixelPackedSampleModel, .Raster, .RenderedImage, .SampleModel, .SinglePixelPackedSampleModel, .WritableRaster, java.util.Iterator, javax.imageio.IIOException, .ImageReadParam, .ImageTypeSpecifier, .ImageWriter, javax.imageio.spi.ImageWriterSpi

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static final void
canEncodeImage(ImageWriter
The provided ImageWriter.
writer
,
ImageTypeSpecifier
The image to be tested.
type
)

Checks that the provided ImageWriter can encode the provided ImageTypeSpecifier or not.

public static final void
canEncodeImage(ImageWriter
The provided ImageWriter.
writer
,
ColorModel
The provided ColorModel.
colorModel
,
SampleModel
The provided SampleModel.
sampleModel
)

Checks that the provided ImageWriter can encode the provided ColorModel and SampleModel.

public static String
convertObjectToString(Object obj)

Converts the provided object to String

public static final ColorModel

Returns:

An instance of ColorModel that is suitable for the supplied SampleModel, or null.
createColorModel
(SampleModel sampleModel)

Creates a ColorModel that may be used with the specified SampleModel.

public static ColorModel
createColorModel(ColorSpace colorSpace, SampleModel sampleModel)

public static long
public static final ImageTypeSpecifier
getDestinationType(ImageReadParam param, Iterator<ImageTypeSpecifier> imageTypes)

Gets the destination image type.

public static int
public static byte[]

Returns:

the binary data as a packed array of bytes with zero offset of null if the data are not binary.
getPackedBinaryData
(Raster raster, Rectangle rect)

For the case of binary data (isBinary() returns true), return the binary data as a packed byte array.

public static long
public static byte[]
getUnpackedBinaryData(Raster raster, Rectangle rect)

Returns the binary data unpacked into an array of bytes.

public static final boolean
imageIsContiguous(RenderedImage image)

Returns whether the image has contiguous data across rows.

public static boolean
public static boolean

Returns:

If all the indices have 256 entries, and are identical mappings, return true; otherwise, return false.
isIndicesForGrayscale
(byte[]
The red channel color indices.
r
,
byte[]
The green channel color indices.
g
,
byte[]
The blue channel color indices.
b
)

Tests whether the color indices represent a gray-scale image.

public static boolean
isNonStandardICCColorSpace(ColorSpace
the ColorSpace to test
cs
)

Returns true if the given ColorSpace object is an instance of ICC_ColorSpace but is not one of the standard ColorSpaces returned by ColorSpace.getInstance().

public static void
setPackedBinaryData(byte[] binaryDataArray, WritableRaster raster, Rectangle rect)

Sets the supplied Raster's data from an array of packed binary data of the form returned by getPackedBinaryData().

public static void
setUnpackedBinaryData(byte[] bdata, WritableRaster raster, Rectangle rect)

Copies data into the packed array of the Raster from an array of unpacked data of the form returned by getUnpackedBinaryData().

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ImageUtilback to summary
public ImageUtil()

Method Detail

canEncodeImageback to summary
public static final void canEncodeImage(ImageWriter writer, ImageTypeSpecifier type) throws IIOException

Checks that the provided ImageWriter can encode the provided ImageTypeSpecifier or not. If not, an IIOException will be thrown.

Parameters
writer:ImageWriter

The provided ImageWriter.

type:ImageTypeSpecifier

The image to be tested.

Exceptions
IIOException:
If the writer cannot encoded the provided image.
canEncodeImageback to summary
public static final void canEncodeImage(ImageWriter writer, ColorModel colorModel, SampleModel sampleModel) throws IIOException

Checks that the provided ImageWriter can encode the provided ColorModel and SampleModel. If not, an IIOException will be thrown.

Parameters
writer:ImageWriter

The provided ImageWriter.

colorModel:ColorModel

The provided ColorModel.

sampleModel:SampleModel

The provided SampleModel.

Exceptions
IIOException:
If the writer cannot encoded the provided image.
convertObjectToStringback to summary
public static String convertObjectToString(Object obj)

Converts the provided object to String

createColorModelback to summary
public static final ColorModel createColorModel(SampleModel sampleModel)

Creates a ColorModel that may be used with the specified SampleModel. If a suitable ColorModel cannot be found, this method returns null.

Suitable ColorModels are guaranteed to exist for all instances of ComponentSampleModel. For 1- and 3- banded SampleModels, the returned ColorModel will be opaque. For 2- and 4-banded SampleModels, the output will use alpha transparency which is not premultiplied. 1- and 2-banded data will use a grayscale ColorSpace, and 3- and 4-banded data a sRGB ColorSpace. Data with 5 or more bands will have a BogusColorSpace.

An instance of DirectColorModel will be created for instances of SinglePixelPackedSampleModel with no more than 4 bands.

An instance of IndexColorModel will be created for instances of MultiPixelPackedSampleModel. The colormap will be a grayscale ramp with 1 << numberOfBits entries ranging from zero to at most 255.

Returns:ColorModel

An instance of ColorModel that is suitable for the supplied SampleModel, or null.

Exceptions
IllegalArgumentException:
If sampleModel is null.
createColorModelback to summary
public static ColorModel createColorModel(ColorSpace colorSpace, SampleModel sampleModel)
getBandSizeback to summary
public static long getBandSize(SampleModel sm)
getDestinationTypeback to summary
public static final ImageTypeSpecifier getDestinationType(ImageReadParam param, Iterator<ImageTypeSpecifier> imageTypes) throws IIOException

Gets the destination image type.

getElementSizeback to summary
public static int getElementSize(SampleModel sm)
getPackedBinaryDataback to summary
public static byte[] getPackedBinaryData(Raster raster, Rectangle rect)

For the case of binary data (isBinary() returns true), return the binary data as a packed byte array. The data will be packed as eight bits per byte with no bit offset, i.e., the first bit in each image line will be the left-most of the first byte of the line. The line stride in bytes will be (int)((getWidth()+7)/8). The length of the returned array will be the line stride multiplied by getHeight()

Returns:byte[]

the binary data as a packed array of bytes with zero offset of null if the data are not binary.

Exceptions
IllegalArgumentException:
if isBinary() returns false with the SampleModel of the supplied Raster as argument.
getTileSizeback to summary
public static long getTileSize(SampleModel sm)
getUnpackedBinaryDataback to summary
public static byte[] getUnpackedBinaryData(Raster raster, Rectangle rect)

Returns the binary data unpacked into an array of bytes. The line stride will be the width of the Raster.

Exceptions
IllegalArgumentException:
if isBinary() returns false with the SampleModel of the supplied Raster as argument.
imageIsContiguousback to summary
public static final boolean imageIsContiguous(RenderedImage image)

Returns whether the image has contiguous data across rows.

isBinaryback to summary
public static boolean isBinary(SampleModel sm)
isIndicesForGrayscaleback to summary
public static boolean isIndicesForGrayscale(byte[] r, byte[] g, byte[] b)

Tests whether the color indices represent a gray-scale image.

Parameters
r:byte[]

The red channel color indices.

g:byte[]

The green channel color indices.

b:byte[]

The blue channel color indices.

Returns:boolean

If all the indices have 256 entries, and are identical mappings, return true; otherwise, return false.

isNonStandardICCColorSpaceback to summary
public static boolean isNonStandardICCColorSpace(ColorSpace cs)

Returns true if the given ColorSpace object is an instance of ICC_ColorSpace but is not one of the standard ColorSpaces returned by ColorSpace.getInstance().

Parameters
cs:ColorSpace

the ColorSpace to test

setPackedBinaryDataback to summary
public static void setPackedBinaryData(byte[] binaryDataArray, WritableRaster raster, Rectangle rect)

Sets the supplied Raster's data from an array of packed binary data of the form returned by getPackedBinaryData().

Exceptions
IllegalArgumentException:
if isBinary() returns false with the SampleModel of the supplied Raster as argument.
setUnpackedBinaryDataback to summary
public static void setUnpackedBinaryData(byte[] bdata, WritableRaster raster, Rectangle rect)

Copies data into the packed array of the Raster from an array of unpacked data of the form returned by getUnpackedBinaryData().

If the data are binary, then the target bit will be set if and only if the corresponding byte is non-zero.

Exceptions
IllegalArgumentException:
if isBinary() returns false with the SampleModel of the supplied Raster as argument.