Class ImageTypeSpecifier
java.lang.Object
javax.imageio.ImageTypeSpecifier
A class that allows the format of an image (in particular, its
 
SampleModel and ColorModel) to be
 specified in a convenient manner.- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ColorModelTheColorModelto be used as a prototype.protected SampleModelASampleModelto be used as a prototype.
- 
Constructor SummaryConstructorsConstructorDescriptionImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel) Constructs anImageTypeSpecifierdirectly from aColorModeland aSampleModel.ImageTypeSpecifier(RenderedImage image) Constructs anImageTypeSpecifierfrom aRenderedImage.
- 
Method SummaryModifier and TypeMethodDescriptionstatic 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.createBufferedImage(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 ImageTypeSpecifierReturns 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.booleanReturnstrueif 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.intReturns an int containing one of the enumerated constant values describing image formats fromBufferedImage.Returns theColorModelspecified by this object.intReturn the number of bands specified by this object.intReturn the number of color components specified by this object.Returns aSampleModelbased on the settings encapsulated within this object.getSampleModel(int width, int height) Returns aSampleModelbased on the settings encapsulated within this object.inthashCode()Returns the hash code for this ImageTypeSpecifier.
- 
Field Details- 
colorModelTheColorModelto be used as a prototype.
- 
sampleModelASampleModelto be used as a prototype.
 
- 
- 
Constructor Details- 
ImageTypeSpecifierConstructs 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.
 
- 
ImageTypeSpecifierConstructs 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 Details- 
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.
 
- 
createGrayscaleReturns 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.
 
- 
createFromBufferedImageTypeReturns 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:
 
- 
createFromRenderedImageReturns 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:
 
- 
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.
 
- 
getSampleModelReturns aSampleModelbased on the settings encapsulated within this object. The width and height of theSampleModelwill be set to arbitrary values.- Returns:
- a SampleModelwith arbitrary dimensions.
 
- 
getSampleModelReturns 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
 
- 
getColorModelReturns theColorModelspecified by this object.- Returns:
- a ColorModel.
 
- 
createBufferedImageCreates 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.
 
- 
equalsReturnstrueif the givenObjectis anImageTypeSpecifierand has aSampleModelandColorModelthat are equal to those of this object.
- 
hashCode
 
-