- java.lang.Object
- 
- javax.imageio.ImageTypeSpecifier
 
- 
 public class ImageTypeSpecifier extends Object A class that allows the format of an image (in particular, itsSampleModelandColorModel) to be specified in a convenient manner.
- 
- 
Field SummaryFields Modifier and Type Field Description protected ColorModelcolorModelTheColorModelto be used as a prototype.protected SampleModelsampleModelASampleModelto be used as a prototype.
 - 
Constructor SummaryConstructors Constructor Description ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel)Constructs anImageTypeSpecifierdirectly from aColorModeland aSampleModel.ImageTypeSpecifier(RenderedImage image)Constructs anImageTypeSpecifierfrom aRenderedImage.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ImageTypeSpecifiercreateBanded(ColorSpace colorSpace, int[] bankIndices, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)Returns a specifier for a banded image format that will use aComponentColorModeland aBandedSampleModelto store each channel in a separate array.BufferedImagecreateBufferedImage(int width, int height)Creates aBufferedImagewith a given width and height according to the specification embodied in this object.static ImageTypeSpecifiercreateFromBufferedImageType(int bufferedImageType)Returns anImageTypeSpecifierthat encodes one of the standardBufferedImagetypes (other thanTYPE_CUSTOM).static ImageTypeSpecifiercreateFromRenderedImage(RenderedImage image)Returns anImageTypeSpecifierthat encodes the layout of aRenderedImage(which may be aBufferedImage).static ImageTypeSpecifiercreateGrayscale(int bits, int dataType, boolean isSigned)Returns a specifier for a grayscale image format that will pack pixels of the given bit depth into array elements of the specified data type.static ImageTypeSpecifiercreateGrayscale(int bits, int dataType, boolean isSigned, boolean isAlphaPremultiplied)Returns a specifier for a grayscale plus alpha image format that will pack pixels of the given bit depth into array elements of the specified data type.static ImageTypeSpecifiercreateIndexed(byte[] redLUT, byte[] greenLUT, byte[] blueLUT, byte[] alphaLUT, int bits, int dataType)Returns a specifier for an indexed-color image format that will pack index values of the given bit depth into array elements of the specified data type.static ImageTypeSpecifiercreateInterleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)Returns a specifier for an interleaved image format that will use aComponentColorModeland aPixelInterleavedSampleModelto store each pixel component in a separate byte, short, or int.static ImageTypeSpecifiercreatePacked(ColorSpace colorSpace, int redMask, int greenMask, int blueMask, int alphaMask, int transferType, boolean isAlphaPremultiplied)Returns a specifier for a packed image format that will use aDirectColorModeland a packedSampleModelto store each pixel packed into in a single byte, short, or int.booleanequals(Object o)Returnstrueif the givenObjectis anImageTypeSpecifierand has aSampleModelandColorModelthat are equal to those of this object.intgetBitsPerBand(int band)Return the number of bits used to represent samples of the given band.intgetBufferedImageType()Returns an int containing one of the enumerated constant values describing image formats fromBufferedImage.ColorModelgetColorModel()Returns theColorModelspecified by this object.intgetNumBands()Return the number of bands specified by this object.intgetNumComponents()Return the number of color components specified by this object.SampleModelgetSampleModel()Returns aSampleModelbased on the settings encapsulated within this object.SampleModelgetSampleModel(int width, int height)Returns aSampleModelbased on the settings encapsulated within this object.inthashCode()Returns the hash code for this ImageTypeSpecifier.
 
- 
- 
- 
Field Detail- 
colorModelprotected ColorModel colorModel TheColorModelto be used as a prototype.
 - 
sampleModelprotected SampleModel sampleModel ASampleModelto be used as a prototype.
 
- 
 - 
Constructor Detail- 
ImageTypeSpecifierpublic ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel) Constructs anImageTypeSpecifierdirectly from aColorModeland aSampleModel. It is the caller's responsibility to supply compatible parameters.- Parameters:
- colorModel- a- ColorModel.
- sampleModel- a- SampleModel.
- Throws:
- IllegalArgumentException- if either parameter is- null.
- IllegalArgumentException- if- sampleModelis not compatible with- colorModel.
 
 - 
ImageTypeSpecifierpublic ImageTypeSpecifier(RenderedImage image) Constructs anImageTypeSpecifierfrom aRenderedImage. If aBufferedImageis being used, one of the factory methodscreateFromRenderedImageorcreateFromBufferedImageTypeshould be used instead in order to get a more accurate result.- Parameters:
- image- a- RenderedImage.
- Throws:
- IllegalArgumentException- if the argument is- null.
 
 
- 
 - 
Method Detail- 
createPackedpublic static ImageTypeSpecifier createPacked(ColorSpace colorSpace, int redMask, int greenMask, int blueMask, int alphaMask, int transferType, boolean isAlphaPremultiplied) Returns a specifier for a packed image format that will use aDirectColorModeland a packedSampleModelto store each pixel packed into in a single byte, short, or int.- Parameters:
- colorSpace- the desired- ColorSpace.
- redMask- a contiguous mask indicated the position of the red channel.
- greenMask- a contiguous mask indicated the position of the green channel.
- blueMask- a contiguous mask indicated the position of the blue channel.
- alphaMask- a contiguous mask indicated the position of the alpha channel.
- transferType- the desired- SampleModeltransfer type.
- isAlphaPremultiplied-- trueif the color channels will be premultipled by the alpha channel.
- Returns:
- an ImageTypeSpecifierwith the desired characteristics.
- Throws:
- IllegalArgumentException- if- colorSpaceis- null.
- IllegalArgumentException- if- colorSpaceis not of type- TYPE_RGB.
- IllegalArgumentException- if no mask has at least 1 bit set.
- IllegalArgumentException- if- transferTypeif not one of- DataBuffer.TYPE_BYTE,- DataBuffer.TYPE_USHORT, or- DataBuffer.TYPE_INT.
 
 - 
createInterleavedpublic static ImageTypeSpecifier createInterleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) Returns a specifier for an interleaved image format that will use aComponentColorModeland aPixelInterleavedSampleModelto store each pixel component in a separate byte, short, or int.- Parameters:
- colorSpace- the desired- ColorSpace.
- bandOffsets- an array of- ints indicating the offsets for each band.
- dataType- the desired data type, as one of the enumerations from the- DataBufferclass.
- hasAlpha-- trueif an alpha channel is desired.
- isAlphaPremultiplied-- trueif the color channels will be premultipled by the alpha channel.
- Returns:
- an ImageTypeSpecifierwith the desired characteristics.
- Throws:
- IllegalArgumentException- if- colorSpaceis- null.
- IllegalArgumentException- if- bandOffsetsis- null.
- IllegalArgumentException- if- dataTypeis not one of the legal- DataBuffer.TYPE_*constants.
- IllegalArgumentException- if- bandOffsets.lengthdoes not equal the number of color space components, plus 1 if- hasAlphais- true.
 
 - 
createBandedpublic static ImageTypeSpecifier createBanded(ColorSpace colorSpace, int[] bankIndices, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) Returns a specifier for a banded image format that will use aComponentColorModeland aBandedSampleModelto store each channel in a separate array.- Parameters:
- colorSpace- the desired- ColorSpace.
- bankIndices- an array of- ints indicating the bank in which each band will be stored.
- bandOffsets- an array of- ints indicating the starting offset of each band within its bank.
- dataType- the desired data type, as one of the enumerations from the- DataBufferclass.
- hasAlpha-- trueif an alpha channel is desired.
- isAlphaPremultiplied-- trueif the color channels will be premultipled by the alpha channel.
- Returns:
- an ImageTypeSpecifierwith the desired characteristics.
- Throws:
- IllegalArgumentException- if- colorSpaceis- null.
- IllegalArgumentException- if- bankIndicesis- null.
- IllegalArgumentException- if- bandOffsetsis- null.
- IllegalArgumentException- if the lengths of- bankIndicesand- bandOffsetsdiffer.
- IllegalArgumentException- if- bandOffsets.lengthdoes not equal the number of color space components, plus 1 if- hasAlphais- true.
- IllegalArgumentException- if- dataTypeis not one of the legal- DataBuffer.TYPE_*constants.
 
 - 
createGrayscalepublic static ImageTypeSpecifier createGrayscale(int bits, int dataType, boolean isSigned) Returns a specifier for a grayscale image format that will pack pixels of the given bit depth into array elements of the specified data type.- Parameters:
- bits- the number of bits per gray value (1, 2, 4, 8, or 16).
- dataType- the desired data type, as one of the enumerations from the- DataBufferclass.
- isSigned-- trueif negative values are to be represented.
- Returns:
- an ImageTypeSpecifierwith the desired characteristics.
- Throws:
- IllegalArgumentException- if- bitsis not one of 1, 2, 4, 8, or 16.
- IllegalArgumentException- if- dataTypeis not one of- DataBuffer.TYPE_BYTE,- DataBuffer.TYPE_SHORT, or- DataBuffer.TYPE_USHORT.
- IllegalArgumentException- if- bitsis larger than the bit size of the given- dataType.
 
 - 
createGrayscalepublic static ImageTypeSpecifier createGrayscale(int bits, int dataType, boolean isSigned, boolean isAlphaPremultiplied) Returns a specifier for a grayscale plus alpha image format that will pack pixels of the given bit depth into array elements of the specified data type.- Parameters:
- bits- the number of bits per gray value (1, 2, 4, 8, or 16).
- dataType- the desired data type, as one of the enumerations from the- DataBufferclass.
- isSigned-- trueif negative values are to be represented.
- isAlphaPremultiplied-- trueif the luminance channel will be premultipled by the alpha channel.
- Returns:
- an ImageTypeSpecifierwith the desired characteristics.
- Throws:
- IllegalArgumentException- if- bitsis not one of 1, 2, 4, 8, or 16.
- IllegalArgumentException- if- dataTypeis not one of- DataBuffer.TYPE_BYTE,- DataBuffer.TYPE_SHORT, or- DataBuffer.TYPE_USHORT.
- IllegalArgumentException- if- bitsis larger than the bit size of the given- dataType.
 
 - 
createIndexedpublic static ImageTypeSpecifier createIndexed(byte[] redLUT, byte[] greenLUT, byte[] blueLUT, byte[] alphaLUT, int bits, int dataType) Returns a specifier for an indexed-color image format that will pack index values of the given bit depth into array elements of the specified data type.- Parameters:
- redLUT- an array of- bytes containing the red values for each index.
- greenLUT- an array of- bytes containing * the green values for each index.
- blueLUT- an array of- bytes containing the blue values for each index.
- alphaLUT- an array of- bytes containing the alpha values for each index, or- nullto create a fully opaque LUT.
- bits- the number of bits in each index.
- dataType- the desired output type, as one of the enumerations from the- DataBufferclass.
- Returns:
- an ImageTypeSpecifierwith the desired characteristics.
- Throws:
- IllegalArgumentException- if- redLUTis- null.
- IllegalArgumentException- if- greenLUTis- null.
- IllegalArgumentException- if- blueLUTis- null.
- IllegalArgumentException- if- bitsis not one of 1, 2, 4, 8, or 16.
- IllegalArgumentException- if the non-- nullLUT parameters do not have lengths of exactly- 1 << bits.
- IllegalArgumentException- if- dataTypeis not one of- DataBuffer.TYPE_BYTE,- DataBuffer.TYPE_SHORT,- DataBuffer.TYPE_USHORT, or- DataBuffer.TYPE_INT.
- IllegalArgumentException- if- bitsis larger than the bit size of the given- dataType.
 
 - 
createFromBufferedImageTypepublic static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) Returns anImageTypeSpecifierthat encodes one of the standardBufferedImagetypes (other thanTYPE_CUSTOM).- Parameters:
- bufferedImageType- an int representing one of the standard- BufferedImagetypes.
- Returns:
- an ImageTypeSpecifierwith the desired characteristics.
- Throws:
- IllegalArgumentException- if- bufferedImageTypeis not one of the standard types, or is equal to- TYPE_CUSTOM.
- See Also:
- BufferedImage,- BufferedImage.TYPE_INT_RGB,- BufferedImage.TYPE_INT_ARGB,- BufferedImage.TYPE_INT_ARGB_PRE,- BufferedImage.TYPE_INT_BGR,- BufferedImage.TYPE_3BYTE_BGR,- BufferedImage.TYPE_4BYTE_ABGR,- BufferedImage.TYPE_4BYTE_ABGR_PRE,- BufferedImage.TYPE_USHORT_565_RGB,- BufferedImage.TYPE_USHORT_555_RGB,- BufferedImage.TYPE_BYTE_GRAY,- BufferedImage.TYPE_USHORT_GRAY,- BufferedImage.TYPE_BYTE_BINARY,- BufferedImage.TYPE_BYTE_INDEXED
 
 - 
createFromRenderedImagepublic static ImageTypeSpecifier createFromRenderedImage(RenderedImage image) Returns anImageTypeSpecifierthat encodes the layout of aRenderedImage(which may be aBufferedImage).- Parameters:
- image- a- RenderedImage.
- Returns:
- an ImageTypeSpecifierwith the desired characteristics.
- Throws:
- IllegalArgumentException- if- imageis- null.
 
 - 
getBufferedImageTypepublic int getBufferedImageType() Returns an int containing one of the enumerated constant values describing image formats fromBufferedImage.- Returns:
- an intrepresenting aBufferedImagetype.
- See Also:
- BufferedImage,- BufferedImage.TYPE_CUSTOM,- BufferedImage.TYPE_INT_RGB,- BufferedImage.TYPE_INT_ARGB,- BufferedImage.TYPE_INT_ARGB_PRE,- BufferedImage.TYPE_INT_BGR,- BufferedImage.TYPE_3BYTE_BGR,- BufferedImage.TYPE_4BYTE_ABGR,- BufferedImage.TYPE_4BYTE_ABGR_PRE,- BufferedImage.TYPE_USHORT_565_RGB,- BufferedImage.TYPE_USHORT_555_RGB,- BufferedImage.TYPE_BYTE_GRAY,- BufferedImage.TYPE_USHORT_GRAY,- BufferedImage.TYPE_BYTE_BINARY,- BufferedImage.TYPE_BYTE_INDEXED
 
 - 
getNumComponentspublic int getNumComponents() Return the number of color components specified by this object. This is the same value as returned byColorModel.getNumComponents- Returns:
- the number of components in the image.
 
 - 
getNumBandspublic int getNumBands() Return the number of bands specified by this object. This is the same value as returned bySampleModel.getNumBands- Returns:
- the number of bands in the image.
 
 - 
getBitsPerBandpublic int getBitsPerBand(int band) Return the number of bits used to represent samples of the given band.- Parameters:
- band- the index of the band to be queried, as an int.
- Returns:
- an int specifying a number of bits.
- Throws:
- IllegalArgumentException- if- bandis negative or greater than the largest band index.
 
 - 
getSampleModelpublic SampleModel getSampleModel() Returns aSampleModelbased on the settings encapsulated within this object. The width and height of theSampleModelwill be set to arbitrary values.- Returns:
- a SampleModelwith arbitrary dimensions.
 
 - 
getSampleModelpublic SampleModel getSampleModel(int width, int height) Returns aSampleModelbased on the settings encapsulated within this object. The width and height of theSampleModelwill be set to the supplied values.- Parameters:
- width- the desired width of the returned- SampleModel.
- height- the desired height of the returned- SampleModel.
- Returns:
- a SampleModelwith the given dimensions.
- Throws:
- IllegalArgumentException- if either- widthor- heightare negative or zero.
- IllegalArgumentException- if the product of- widthand- heightis greater than- Integer.MAX_VALUE
 
 - 
getColorModelpublic ColorModel getColorModel() Returns theColorModelspecified by this object.- Returns:
- a ColorModel.
 
 - 
createBufferedImagepublic BufferedImage createBufferedImage(int width, int height) Creates aBufferedImagewith a given width and height according to the specification embodied in this object.- Parameters:
- width- the desired width of the returned- BufferedImage.
- height- the desired height of the returned- BufferedImage.
- Returns:
- a new BufferedImage
- Throws:
- IllegalArgumentException- if either- widthor- heightare negative or zero.
- IllegalArgumentException- if the product of- widthand- heightis greater than- Integer.MAX_VALUE, or if the number of array elements needed to store the image is greater than- Integer.MAX_VALUE.
 
 - 
equalspublic boolean equals(Object o) Returnstrueif the givenObjectis anImageTypeSpecifierand has aSampleModelandColorModelthat are equal to those of this object.- Overrides:
- equalsin class- Object
- Parameters:
- o- the- Objectto be compared for equality.
- Returns:
- trueif the given object is an equivalent- ImageTypeSpecifier.
- See Also:
- Object.hashCode(),- HashMap
 
 - 
hashCodepublic int hashCode() Returns the hash code for this ImageTypeSpecifier.- Overrides:
- hashCodein class- Object
- Returns:
- a hash code for this ImageTypeSpecifier
- See Also:
- Object.equals(java.lang.Object),- System.identityHashCode(java.lang.Object)
 
 
- 
 
-