Class ImageBuilder
java.lang.Object
org.apache.commons.imaging.common.ImageBuilder
A utility class primary intended for storing data obtained by reading image files.
-
Constructor Summary
ConstructorsConstructorDescriptionImageBuilder
(int width, int height, boolean hasAlpha) Constructs an ImageBuilder instance.ImageBuilder
(int width, int height, boolean hasAlpha, boolean isAlphaPremultiplied) Constructs an ImageBuilder instance. -
Method Summary
Modifier and TypeMethodDescriptionCreate a BufferedImage using the data stored in the ImageBuilder.int
Gets the height of the ImageBuilder pixel fieldint
getRgb
(int x, int y) Gets the RGB or ARGB value for the pixel at the position (x,y) within the image builder pixel field.getSubimage
(int x, int y, int w, int h) Gets a subimage from the ImageBuilder using the specified parameters.getSubset
(int x, int y, int w, int h) Gets a subset of the ImageBuilder content using the specified parameters to indicate an area of interest.int
getWidth()
Gets the width of the ImageBuilder pixel fieldvoid
setRgb
(int x, int y, int argb) Sets the RGB or ARGB value for the pixel at position (x,y) within the image builder pixel field.
-
Constructor Details
-
ImageBuilder
Constructs an ImageBuilder instance.- Parameters:
width
- the width of the image to be builtheight
- the height of the image to be builthasAlpha
- indicates whether the image has an alpha channel (the selection of alpha channel does not change the memory requirements for the ImageBuilder or resulting BufferedImage.- Throws:
RasterFormatException
- ifwidth
orheight
are equal or less than zero
-
ImageBuilder
Constructs an ImageBuilder instance.- Parameters:
width
- the width of the image to be builtheight
- the height of the image to be builthasAlpha
- indicates whether the image has an alpha channel (the selection of alpha channel does not change the memory requirements for the ImageBuilder or resulting BufferedImage.isAlphaPremultiplied
- indicates whether alpha values are pre-multiplied; this setting is relevant only if alpha is true.- Throws:
RasterFormatException
- ifwidth
orheight
are equal or less than zero
-
-
Method Details
-
getBufferedImage
Create a BufferedImage using the data stored in the ImageBuilder.- Returns:
- a valid BufferedImage.
-
getHeight
Gets the height of the ImageBuilder pixel field- Returns:
- a positive integer
-
getRgb
Gets the RGB or ARGB value for the pixel at the position (x,y) within the image builder pixel field. For performance reasons no bounds checking is applied.- Parameters:
x
- the X coordinate of the pixel to be ready
- the Y coordinate of the pixel to be read- Returns:
- the RGB or ARGB pixel value
-
getSubimage
Gets a subimage from the ImageBuilder using the specified parameters. If the parameters specify a rectangular region that is not entirely contained within the bounds defined by the ImageBuilder, this method will throw a RasterFormatException. This runtime-exception behavior is consistent with the behavior of the getSubimage method provided by BufferedImage.- Parameters:
x
- the X coordinate of the upper-left corner of the specified rectangular regiony
- the Y coordinate of the upper-left corner of the specified rectangular regionw
- the width of the specified rectangular regionh
- the height of the specified rectangular region- Returns:
- a BufferedImage that constructed from the data within the specified rectangular region
- Throws:
RasterFormatException
- f the specified area is not contained within this ImageBuilder
-
getSubset
Gets a subset of the ImageBuilder content using the specified parameters to indicate an area of interest. If the parameters specify a rectangular region that is not entirely contained within the bounds defined by the ImageBuilder, this method will throw a RasterFormatException. This run- time exception is consistent with the behavior of the getSubimage method provided by BufferedImage.- Parameters:
x
- the X coordinate of the upper-left corner of the specified rectangular regiony
- the Y coordinate of the upper-left corner of the specified rectangular regionw
- the width of the specified rectangular regionh
- the height of the specified rectangular region- Returns:
- a valid instance of the specified width and height.
- Throws:
RasterFormatException
- if the specified area is not contained within this ImageBuilder
-
getWidth
Gets the width of the ImageBuilder pixel field- Returns:
- a positive integer
-
setRgb
Sets the RGB or ARGB value for the pixel at position (x,y) within the image builder pixel field. For performance reasons, no bounds checking is applied.- Parameters:
x
- the X coordinate of the pixel to be set.y
- the Y coordinate of the pixel to be set.argb
- the RGB or ARGB value to be stored.- Throws:
ArithmeticException
- if the index computation overflows an int.IllegalArgumentException
- if the resulting index is illegal.
-