- 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 Summary
Fields Modifier and Type Field and Description protected ColorModelcolorModelTheColorModelto be used as a prototype.protected SampleModelsampleModelASampleModelto be used as a prototype.
-
Constructor Summary
Constructors Constructor and Description ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel)Constructs anImageTypeSpecifierdirectly from aColorModeland aSampleModel.ImageTypeSpecifier(RenderedImage image)Constructs anImageTypeSpecifierfrom aRenderedImage.
-
Method Summary
Methods Modifier and Type Method and 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
-
colorModel
protected ColorModel colorModel
TheColorModelto be used as a prototype.
-
sampleModel
protected SampleModel sampleModel
ASampleModelto be used as a prototype.
-
-
Constructor Detail
-
ImageTypeSpecifier
public ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel)
Constructs anImageTypeSpecifierdirectly from aColorModeland aSampleModel. It is the caller's responsibility to supply compatible parameters.- Parameters:
colorModel- aColorModel.sampleModel- aSampleModel.- Throws:
IllegalArgumentException- if either parameter isnull.IllegalArgumentException- ifsampleModelis not compatible withcolorModel.
-
ImageTypeSpecifier
public 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- aRenderedImage.- Throws:
IllegalArgumentException- if the argument isnull.
-
-
Method Detail
-
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 aDirectColorModeland a packedSampleModelto 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 desiredSampleModeltransfer type.isAlphaPremultiplied-trueif the color channels will be premultipled by the alpha channel.- Returns:
- an
ImageTypeSpecifierwith the desired characteristics. - Throws:
IllegalArgumentException- ifcolorSpaceisnull.IllegalArgumentException- ifcolorSpaceis not of typeTYPE_RGB.IllegalArgumentException- if no mask has at least 1 bit set.IllegalArgumentException- iftransferTypeif 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 aComponentColorModeland aPixelInterleavedSampleModelto store each pixel component in a separate byte, short, or int.- Parameters:
colorSpace- the desiredColorSpace.bandOffsets- an array ofints indicating the offsets for each band.dataType- the desired data type, as one of the enumerations from theDataBufferclass.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- ifcolorSpaceisnull.IllegalArgumentException- ifbandOffsetsisnull.IllegalArgumentException- ifdataTypeis not one of the legalDataBuffer.TYPE_*constants.IllegalArgumentException- ifbandOffsets.lengthdoes not equal the number of color space components, plus 1 ifhasAlphaistrue.
-
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 aComponentColorModeland aBandedSampleModelto store each channel in a separate array.- Parameters:
colorSpace- the desiredColorSpace.bankIndices- an array ofints indicating the bank in which each band will be stored.bandOffsets- an array ofints indicating the starting offset of each band within its bank.dataType- the desired data type, as one of the enumerations from theDataBufferclass.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- ifcolorSpaceisnull.IllegalArgumentException- ifbankIndicesisnull.IllegalArgumentException- ifbandOffsetsisnull.IllegalArgumentException- if the lengths ofbankIndicesandbandOffsetsdiffer.IllegalArgumentException- ifbandOffsets.lengthdoes not equal the number of color space components, plus 1 ifhasAlphaistrue.IllegalArgumentException- ifdataTypeis 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 theDataBufferclass.isSigned-trueif negative values are to be represented.- Returns:
- an
ImageTypeSpecifierwith the desired characteristics. - Throws:
IllegalArgumentException- ifbitsis not one of 1, 2, 4, 8, or 16.IllegalArgumentException- ifdataTypeis not one ofDataBuffer.TYPE_BYTE,DataBuffer.TYPE_SHORT, orDataBuffer.TYPE_USHORT.IllegalArgumentException- ifbitsis 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 theDataBufferclass.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- ifbitsis not one of 1, 2, 4, 8, or 16.IllegalArgumentException- ifdataTypeis not one ofDataBuffer.TYPE_BYTE,DataBuffer.TYPE_SHORT, orDataBuffer.TYPE_USHORT.IllegalArgumentException- ifbitsis 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 ofbytes containing the red values for each index.greenLUT- an array ofbytes containing * the green values for each index.blueLUT- an array ofbytes containing the blue values for each index.alphaLUT- an array ofbytes containing the alpha values for each index, ornullto create a fully opaque LUT.bits- the number of bits in each index.dataType- the desired output type, as one of the enumerations from theDataBufferclass.- Returns:
- an
ImageTypeSpecifierwith the desired characteristics. - Throws:
IllegalArgumentException- ifredLUTisnull.IllegalArgumentException- ifgreenLUTisnull.IllegalArgumentException- ifblueLUTisnull.IllegalArgumentException- ifbitsis not one of 1, 2, 4, 8, or 16.IllegalArgumentException- if the non-nullLUT parameters do not have lengths of exactly1 << bits.IllegalArgumentException- ifdataTypeis not one ofDataBuffer.TYPE_BYTE,DataBuffer.TYPE_SHORT,DataBuffer.TYPE_USHORT, orDataBuffer.TYPE_INT.IllegalArgumentException- ifbitsis larger than the bit size of the givendataType.
-
createFromBufferedImageType
public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType)
Returns anImageTypeSpecifierthat encodes one of the standardBufferedImagetypes (other thanTYPE_CUSTOM).- Parameters:
bufferedImageType- an int representing one of the standardBufferedImagetypes.- Returns:
- an
ImageTypeSpecifierwith the desired characteristics. - Throws:
IllegalArgumentException- ifbufferedImageTypeis 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 anImageTypeSpecifierthat encodes the layout of aRenderedImage(which may be aBufferedImage).- Parameters:
image- aRenderedImage.- Returns:
- an
ImageTypeSpecifierwith the desired characteristics. - Throws:
IllegalArgumentException- ifimageisnull.
-
getBufferedImageType
public 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
-
getNumComponents
public 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.
-
getNumBands
public 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.
-
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- ifbandis negative or greater than the largest band index.
-
getSampleModel
public 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.
-
getSampleModel
public 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 returnedSampleModel.height- the desired height of the returnedSampleModel.- Returns:
- a
SampleModelwith the given dimensions. - Throws:
IllegalArgumentException- if eitherwidthorheightare negative or zero.IllegalArgumentException- if the product ofwidthandheightis greater thanInteger.MAX_VALUE
-
getColorModel
public ColorModel getColorModel()
Returns theColorModelspecified by this object.- Returns:
- a
ColorModel.
-
createBufferedImage
public 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 returnedBufferedImage.height- the desired height of the returnedBufferedImage.- Returns:
- a new
BufferedImage - Throws:
IllegalArgumentException- if eitherwidthorheightare negative or zero.IllegalArgumentException- if the product ofwidthandheightis 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)
Returnstrueif the givenObjectis anImageTypeSpecifierand has aSampleModelandColorModelthat are equal to those of this object.- Overrides:
equalsin classObject- Parameters:
o- theObjectto be compared for equality.- Returns:
trueif the given object is an equivalentImageTypeSpecifier.- See Also:
Object.hashCode(),HashMap
-
hashCode
public int hashCode()
Returns the hash code for this ImageTypeSpecifier.- Overrides:
hashCodein classObject- Returns:
- a hash code for this ImageTypeSpecifier
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
10/10/2025 09:28:54 Cette version de la page est en cache (à la date du 10/10/2025 09:28:54) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 30/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/imageio/ImageTypeSpecifier.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.