Class ImageTypeSpecifier
- java.lang.Object
-
- javax.imageio.ImageTypeSpecifier
public class ImageTypeSpecifier extends Object
A class that allows the format of an image (in particular, its SampleModel
and ColorModel
) to be specified in a convenient manner.
Fields
Modifier and Type | Field and Description |
---|---|
protected ColorModel |
colorModel The |
protected SampleModel |
sampleModel A |
Constructors
Constructor and Description |
---|
ImageTypeSpecifier(ColorModel colorModel,
SampleModel sampleModel) Constructs an |
ImageTypeSpecifier(RenderedImage image) Constructs an |
Methods
Modifier and Type | Method and Description |
---|---|
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 a |
BufferedImage |
createBufferedImage(int width,
int height) Creates a |
static ImageTypeSpecifier |
createFromBufferedImageType(int bufferedImageType) Returns an |
static ImageTypeSpecifier |
createFromRenderedImage(RenderedImage image) Returns an |
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. |
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. |
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. |
static ImageTypeSpecifier |
createInterleaved(ColorSpace colorSpace,
int[] bandOffsets,
int dataType,
boolean hasAlpha,
boolean isAlphaPremultiplied) Returns a specifier for an interleaved image format that will use a |
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 a |
boolean |
equals(Object o) Returns |
int |
getBitsPerBand(int band) Return the number of bits used to represent samples of the given band. |
int |
getBufferedImageType() Returns an int containing one of the enumerated constant values describing image formats from |
ColorModel |
getColorModel() Returns the |
int |
getNumBands() Return the number of bands specified by this object. |
int |
getNumComponents() Return the number of color components specified by this object. |
SampleModel |
getSampleModel() Returns a |
SampleModel |
getSampleModel(int width,
int height) Returns a |
int |
hashCode() Returns the hash code for this ImageTypeSpecifier. |
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Fields
colorModel
protected ColorModel colorModel
The ColorModel
to be used as a prototype.
sampleModel
protected SampleModel sampleModel
A SampleModel
to be used as a prototype.
Constructors
ImageTypeSpecifier
public ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel)
Constructs an ImageTypeSpecifier
directly from a ColorModel
and a SampleModel
. It is the caller's responsibility to supply compatible parameters.
- Parameters:
-
colorModel
- aColorModel
. -
sampleModel
- aSampleModel
. - Throws:
-
IllegalArgumentException
- if either parameter isnull
. -
IllegalArgumentException
- ifsampleModel
is not compatible withcolorModel
.
ImageTypeSpecifier
public ImageTypeSpecifier(RenderedImage image)
Constructs an ImageTypeSpecifier
from a RenderedImage
. If a BufferedImage
is being used, one of the factory methods createFromRenderedImage
or createFromBufferedImageType
should be used instead in order to get a more accurate result.
- Parameters:
-
image
- aRenderedImage
. - Throws:
-
IllegalArgumentException
- if the argument isnull
.
Methods
createPacked
public 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 a DirectColorModel
and a packed SampleModel
to store each pixel packed into in a single byte, short, or int.
- Parameters:
-
colorSpace
- the desiredColorSpace
. -
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 desiredSampleModel
transfer type. -
isAlphaPremultiplied
-true
if the color channels will be premultipled by the alpha channel. - Returns:
- an
ImageTypeSpecifier
with the desired characteristics. - Throws:
-
IllegalArgumentException
- ifcolorSpace
isnull
. -
IllegalArgumentException
- ifcolorSpace
is not of typeTYPE_RGB
. -
IllegalArgumentException
- if no mask has at least 1 bit set. -
IllegalArgumentException
- iftransferType
if not one ofDataBuffer.TYPE_BYTE
,DataBuffer.TYPE_USHORT
, orDataBuffer.TYPE_INT
.
createInterleaved
public static ImageTypeSpecifier createInterleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)
Returns a specifier for an interleaved image format that will use a ComponentColorModel
and a PixelInterleavedSampleModel
to store each pixel component in a separate byte, short, or int.
- Parameters:
-
colorSpace
- the desiredColorSpace
. -
bandOffsets
- an array ofint
s indicating the offsets for each band. -
dataType
- the desired data type, as one of the enumerations from theDataBuffer
class. -
hasAlpha
-true
if an alpha channel is desired. -
isAlphaPremultiplied
-true
if the color channels will be premultipled by the alpha channel. - Returns:
- an
ImageTypeSpecifier
with the desired characteristics. - Throws:
-
IllegalArgumentException
- ifcolorSpace
isnull
. -
IllegalArgumentException
- ifbandOffsets
isnull
. -
IllegalArgumentException
- ifdataType
is not one of the legalDataBuffer.TYPE_*
constants. -
IllegalArgumentException
- ifbandOffsets.length
does not equal the number of color space components, plus 1 ifhasAlpha
istrue
.
createBanded
public 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 a ComponentColorModel
and a BandedSampleModel
to store each channel in a separate array.
- Parameters:
-
colorSpace
- the desiredColorSpace
. -
bankIndices
- an array ofint
s indicating the bank in which each band will be stored. -
bandOffsets
- an array ofint
s indicating the starting offset of each band within its bank. -
dataType
- the desired data type, as one of the enumerations from theDataBuffer
class. -
hasAlpha
-true
if an alpha channel is desired. -
isAlphaPremultiplied
-true
if the color channels will be premultipled by the alpha channel. - Returns:
- an
ImageTypeSpecifier
with the desired characteristics. - Throws:
-
IllegalArgumentException
- ifcolorSpace
isnull
. -
IllegalArgumentException
- ifbankIndices
isnull
. -
IllegalArgumentException
- ifbandOffsets
isnull
. -
IllegalArgumentException
- if the lengths ofbankIndices
andbandOffsets
differ. -
IllegalArgumentException
- ifbandOffsets.length
does not equal the number of color space components, plus 1 ifhasAlpha
istrue
. -
IllegalArgumentException
- ifdataType
is not one of the legalDataBuffer.TYPE_*
constants.
createGrayscale
public 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 theDataBuffer
class. -
isSigned
-true
if negative values are to be represented. - Returns:
- an
ImageTypeSpecifier
with the desired characteristics. - Throws:
-
IllegalArgumentException
- ifbits
is not one of 1, 2, 4, 8, or 16. -
IllegalArgumentException
- ifdataType
is not one ofDataBuffer.TYPE_BYTE
,DataBuffer.TYPE_SHORT
, orDataBuffer.TYPE_USHORT
. -
IllegalArgumentException
- ifbits
is larger than the bit size of the givendataType
.
createGrayscale
public 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 theDataBuffer
class. -
isSigned
-true
if negative values are to be represented. -
isAlphaPremultiplied
-true
if the luminance channel will be premultipled by the alpha channel. - Returns:
- an
ImageTypeSpecifier
with the desired characteristics. - Throws:
-
IllegalArgumentException
- ifbits
is not one of 1, 2, 4, 8, or 16. -
IllegalArgumentException
- ifdataType
is not one ofDataBuffer.TYPE_BYTE
,DataBuffer.TYPE_SHORT
, orDataBuffer.TYPE_USHORT
. -
IllegalArgumentException
- ifbits
is larger than the bit size of the givendataType
.
createIndexed
public 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 ofbyte
s containing the red values for each index. -
greenLUT
- an array ofbyte
s containing * the green values for each index. -
blueLUT
- an array ofbyte
s containing the blue values for each index. -
alphaLUT
- an array ofbyte
s containing the alpha values for each index, ornull
to create a fully opaque LUT. -
bits
- the number of bits in each index. -
dataType
- the desired output type, as one of the enumerations from theDataBuffer
class. - Returns:
- an
ImageTypeSpecifier
with the desired characteristics. - Throws:
-
IllegalArgumentException
- ifredLUT
isnull
. -
IllegalArgumentException
- ifgreenLUT
isnull
. -
IllegalArgumentException
- ifblueLUT
isnull
. -
IllegalArgumentException
- ifbits
is not one of 1, 2, 4, 8, or 16. -
IllegalArgumentException
- if the non-null
LUT parameters do not have lengths of exactly1 << bits
. -
IllegalArgumentException
- ifdataType
is not one ofDataBuffer.TYPE_BYTE
,DataBuffer.TYPE_SHORT
,DataBuffer.TYPE_USHORT
, orDataBuffer.TYPE_INT
. -
IllegalArgumentException
- ifbits
is larger than the bit size of the givendataType
.
createFromBufferedImageType
public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType)
Returns an ImageTypeSpecifier
that encodes one of the standard BufferedImage
types (other than TYPE_CUSTOM
).
- Parameters:
-
bufferedImageType
- an int representing one of the standardBufferedImage
types. - Returns:
- an
ImageTypeSpecifier
with the desired characteristics. - Throws:
-
IllegalArgumentException
- ifbufferedImageType
is not one of the standard types, or is equal toTYPE_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
createFromRenderedImage
public static ImageTypeSpecifier createFromRenderedImage(RenderedImage image)
Returns an ImageTypeSpecifier
that encodes the layout of a RenderedImage
(which may be a BufferedImage
).
- Parameters:
-
image
- aRenderedImage
. - Returns:
- an
ImageTypeSpecifier
with the desired characteristics. - Throws:
-
IllegalArgumentException
- ifimage
isnull
.
getBufferedImageType
public int getBufferedImageType()
Returns an int containing one of the enumerated constant values describing image formats from BufferedImage
.
- Returns:
- an
int
representing aBufferedImage
type. - 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
getNumComponents
public int getNumComponents()
Return the number of color components specified by this object. This is the same value as returned by ColorModel.getNumComponents
- Returns:
- the number of components in the image.
getNumBands
public int getNumBands()
Return the number of bands specified by this object. This is the same value as returned by SampleModel.getNumBands
- Returns:
- the number of bands in the image.
getBitsPerBand
public 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
- ifband
is negative or greater than the largest band index.
getSampleModel
public SampleModel getSampleModel()
Returns a SampleModel
based on the settings encapsulated within this object. The width and height of the SampleModel
will be set to arbitrary values.
- Returns:
- a
SampleModel
with arbitrary dimensions.
getSampleModel
public SampleModel getSampleModel(int width, int height)
Returns a SampleModel
based on the settings encapsulated within this object. The width and height of the SampleModel
will be set to the supplied values.
- Parameters:
-
width
- the desired width of the returnedSampleModel
. -
height
- the desired height of the returnedSampleModel
. - Returns:
- a
SampleModel
with the given dimensions. - Throws:
-
IllegalArgumentException
- if eitherwidth
orheight
are negative or zero. -
IllegalArgumentException
- if the product ofwidth
andheight
is greater thanInteger.MAX_VALUE
getColorModel
public ColorModel getColorModel()
Returns the ColorModel
specified by this object.
- Returns:
- a
ColorModel
.
createBufferedImage
public BufferedImage createBufferedImage(int width, int height)
Creates a BufferedImage
with a given width and height according to the specification embodied in this object.
- Parameters:
-
width
- the desired width of the returnedBufferedImage
. -
height
- the desired height of the returnedBufferedImage
. - Returns:
- a new
BufferedImage
- Throws:
-
IllegalArgumentException
- if eitherwidth
orheight
are negative or zero. -
IllegalArgumentException
- if the product ofwidth
andheight
is greater thanInteger.MAX_VALUE
, or if the number of array elements needed to store the image is greater thanInteger.MAX_VALUE
.
equals
public boolean equals(Object o)
Returns true
if the given Object
is an ImageTypeSpecifier
and has a SampleModel
and ColorModel
that are equal to those of this object.
- Overrides:
-
equals
in classObject
- Parameters:
-
o
- theObject
to be compared for equality. - Returns:
-
true
if the given object is an equivalentImageTypeSpecifier
. - See Also:
-
Object.hashCode()
,HashMap
hashCode
public int hashCode()
Returns the hash code for this ImageTypeSpecifier.
- Overrides:
-
hashCode
in classObject
- Returns:
- a hash code for this ImageTypeSpecifier
- See Also:
-
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)
© 1993, 2020, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/javase/8/docs/api/javax/imageio/ImageTypeSpecifier.html