public final class ImageUtil extends Object
| Modifier and Type | Field | Description |
|---|---|---|
static int |
COLOR_SELECTION_DEFAULT |
Default color selection
|
static int |
COLOR_SELECTION_FAST |
Prioritize speed
|
static int |
COLOR_SELECTION_QUALITY |
Prioritize quality
|
static int |
DITHER_DEFAULT |
Java default dither
|
static int |
DITHER_DIFFUSION |
Error diffusion dither
|
static int |
DITHER_DIFFUSION_ALTSCANS |
Error diffusion dither with alternating scans
|
static int |
DITHER_NONE |
No dither
|
static int |
EDGE_NO_OP |
Alias for
ConvolveOp.EDGE_NO_OP. |
static int |
EDGE_REFLECT |
Adds a border to the image while convolving.
|
static int |
EDGE_WRAP |
Adds a border to the image while convolving.
|
static int |
EDGE_ZERO_FILL |
Alias for
ConvolveOp.EDGE_ZERO_FILL. |
static int |
FLIP_HORIZONTAL |
|
static int |
FLIP_VERTICAL |
|
protected static AffineTransform |
IDENTITY_TRANSFORM |
|
protected static Point |
LOCATION_UPPER_LEFT |
|
static int |
ROTATE_180 |
|
static int |
ROTATE_90_CCW |
|
static int |
ROTATE_90_CW |
|
static int |
TRANSPARENCY_BITMASK |
Convert alpha to bitmask
|
static int |
TRANSPARENCY_DEFAULT |
Default transparency (none)
|
static int |
TRANSPARENCY_OPAQUE |
Discard any alpha information
|
protected static int |
TRANSPARENCY_TRANSLUCENT |
Keep original alpha (not supported yet)
|
| Modifier and Type | Method | Description |
|---|---|---|
static BufferedImage |
accelerate(Image pImage) |
Tries to use H/W-accelerated code for an image for display purposes.
|
static BufferedImage |
accelerate(Image pImage,
GraphicsConfiguration pConfiguration) |
Tries to use H/W-accelerated code for an image for display purposes.
|
static Color |
blend(Color pColor,
Color pOther) |
Blends two colors half and half, to create a tone in between.
|
static Color |
blend(Color pColor,
Color pOther,
float pBlendFactor) |
Blends two colors, controlled by the blending factor.
|
static BufferedImage |
blur(BufferedImage pOriginal) |
Creates a blurred version of the given image.
|
static BufferedImage |
blur(BufferedImage pOriginal,
float pRadius) |
Creates a blurred version of the given image.
|
static Image |
brightness(Image pOriginal,
float pAmount) |
Changes the brightness of the original image.
|
static Image |
contrast(Image pOriginal) |
Adds contrast
|
static Image |
contrast(Image pOriginal,
float pAmount) |
Changes the contrast of the image
|
static BufferedImage |
convolve(BufferedImage pOriginal,
Kernel pKernel,
int pEdgeOperation) |
Convolves an image, using a convolution matrix.
|
static BufferedImage |
createClear(int pWidth,
int pHeight,
int pType,
Color pBackground) |
Creates a clear image with the given background color.
|
static BufferedImage |
createClear(int pWidth,
int pHeight,
Color pBackground) |
Creates a clear image with the given background color.
|
static BufferedImage |
createCopy(BufferedImage pImage) |
Creates a deep copy of the given image.
|
static BufferedImage |
createFlipped(Image pImage,
int pAxis) |
Creates a flipped version of the given image.
|
static BufferedImage |
createIndexed(Image pImage) |
Creates an indexed version of the given image (a
BufferedImage
with an IndexColorModel. |
static BufferedImage |
createIndexed(Image pImage,
int pColors,
Color pMatte,
int pHints) |
Creates an indexed version of the given image (a
BufferedImage
with an IndexColorModel. |
static BufferedImage |
createIndexed(Image pImage,
IndexColorModel pColors,
Color pMatte,
int pHints) |
Creates an indexed version of the given image (a
BufferedImage
with an IndexColorModel. |
static BufferedImage |
createIndexed(Image pImage,
Image pColors,
Color pMatte,
int pHints) |
Creates an indexed version of the given image (a
BufferedImage
with an IndexColorModel. |
static BufferedImage |
createResampled(BufferedImage pImage,
int pWidth,
int pHeight,
int pHints) |
Creates a scaled instance of the given
BufferedImage. |
static BufferedImage |
createResampled(RenderedImage pImage,
int pWidth,
int pHeight,
int pHints) |
Creates a scaled instance of the given
RenderedImage, and
converts it to a BufferedImage if needed. |
static BufferedImage |
createResampled(Image pImage,
int pWidth,
int pHeight,
int pHints) |
Creates a scaled instance of the given
Image, and converts it to
a BufferedImage if needed. |
static BufferedImage |
createRotated(Image pImage,
double pAngle) |
Rotates the image to the given angle.
|
static BufferedImage |
createRotated(Image pImage,
int pDirection) |
Rotates the image 90 degrees, clockwise (aka "rotate right"),
counter-clockwise (aka "rotate left") or 180 degrees, depending on the
pDirection argument. |
static BufferedImage |
createScaled(Image pImage,
int pWidth,
int pHeight,
int pHints) |
Creates a scaled instance of the given
Image, and converts it to
a BufferedImage if needed. |
static Color |
createTranslucent(Color pColor,
int pTransparency) |
Creates a translucent version of the given color.
|
static BufferedImage |
createTransparent(int pWidth,
int pHeight) |
Creates a transparent image.
|
static BufferedImage |
createTransparent(int pWidth,
int pHeight,
int pType) |
Creates a transparent image.
|
static Image |
filter(Image pOriginal,
ImageFilter pFilter) |
Filters an image, using the given
ImageFilter. |
static int |
getHeight(Image pImage) |
Gets the height of an Image.
|
static IndexColorModel |
getIndexColorModel(Image pImage,
int pColors,
int pHints) |
Extracts an
IndexColorModel from the given image. |
static int |
getWidth(Image pImage) |
Gets the width of an Image.
|
static Image |
grayscale(Image pOriginal) |
Converts an image to grayscale.
|
static boolean |
hasTransparentPixels(RenderedImage pImage,
boolean pFast) |
Tests whether the image has any transparent or semi-transparent pixels.
|
static BufferedImage |
sharpen(BufferedImage pOriginal) |
Sharpens an image using a convolution matrix.
|
static BufferedImage |
sharpen(BufferedImage pOriginal,
float pAmount) |
Sharpens an image using a convolution matrix.
|
static BufferedImage |
toBuffered(Image pOriginal) |
Converts the
Image to a BufferedImage. |
static BufferedImage |
toBuffered(BufferedImage pOriginal,
int pType) |
Converts the
BufferedImage to a BufferedImage of the
given type. |
static BufferedImage |
toBuffered(RenderedImage pOriginal) |
Converts the
RenderedImage to a BufferedImage. |
static BufferedImage |
toBuffered(RenderedImage pOriginal,
int pType) |
Converts the
RenderedImage to a BufferedImage of the
given type. |
static BufferedImage |
toBuffered(Image pOriginal,
int pType) |
Converts the
Image to a BufferedImage of the given type. |
static boolean |
waitForImage(Image pImage) |
Waits for an image to load completely.
|
static boolean |
waitForImage(Image pImage,
long pTimeOut) |
Waits for an image to load completely.
|
static boolean |
waitForImages(Image[] pImages) |
Waits for a number of images to load completely.
|
static boolean |
waitForImages(Image[] pImages,
long pTimeOut) |
Waits for a number of images to load completely.
|
public static final int ROTATE_90_CCW
public static final int ROTATE_90_CW
public static final int ROTATE_180
public static final int FLIP_VERTICAL
public static final int FLIP_HORIZONTAL
public static final int EDGE_ZERO_FILL
ConvolveOp.EDGE_ZERO_FILL.public static final int EDGE_NO_OP
ConvolveOp.EDGE_NO_OP.public static final int EDGE_REFLECT
EDGE_ZERO_FILL and EDGE_NO_OP, it does so
at the expense of higher memory consumption and considerable more computation.public static final int EDGE_WRAP
EDGE_ZERO_FILL and EDGE_NO_OP, it does so
at the expense of higher memory consumption and considerable more computation.public static final int DITHER_DEFAULT
public static final int DITHER_NONE
public static final int DITHER_DIFFUSION
public static final int DITHER_DIFFUSION_ALTSCANS
public static final int COLOR_SELECTION_DEFAULT
public static final int COLOR_SELECTION_FAST
public static final int COLOR_SELECTION_QUALITY
public static final int TRANSPARENCY_DEFAULT
public static final int TRANSPARENCY_OPAQUE
public static final int TRANSPARENCY_BITMASK
protected static final int TRANSPARENCY_TRANSLUCENT
protected static final AffineTransform IDENTITY_TRANSFORM
protected static final Point LOCATION_UPPER_LEFT
public static BufferedImage toBuffered(RenderedImage pOriginal)
RenderedImage to a BufferedImage.
The new image will have the same ColorModel,
Raster and properties as the original image, if possible.
If the image is already a BufferedImage, it is simply returned
and no conversion takes place.pOriginal - the image to convert.BufferedImagepublic static BufferedImage toBuffered(RenderedImage pOriginal, int pType)
RenderedImage to a BufferedImage of the
given type.
If the image is already a BufferedImage of the given type, it
is simply returned and no conversion takes place.pOriginal - the image to convert.pType - the type of buffered imageBufferedImageIllegalArgumentException - if pOriginal == null
or pType is not a valid type for BufferedImageBufferedImage.getType()public static BufferedImage toBuffered(BufferedImage pOriginal, int pType)
BufferedImage to a BufferedImage of the
given type. The new image will have the same ColorModel,
Raster and properties as the original image, if possible.
If the image is already a BufferedImage of the given type, it
is simply returned and no conversion takes place.
This method simply invokes
toBuffered((RenderedImage) pOriginal, pType).pOriginal - the image to convert.pType - the type of buffered imageBufferedImageIllegalArgumentException - if pOriginal == null
or if pType is not a valid type for BufferedImageBufferedImage.getType()public static BufferedImage toBuffered(Image pOriginal)
Image to a BufferedImage.
The new image will have the same ColorModel, Raster and
properties as the original image, if possible.
If the image is already a BufferedImage, it is simply returned
and no conversion takes place.pOriginal - the image to convert.BufferedImageIllegalArgumentException - if pOriginal == nullImageConversionException - if the image cannot be convertedpublic static BufferedImage createCopy(BufferedImage pImage)
pImage - the image to clone.BufferedImageIllegalArgumentException - if pImage is nullpublic static BufferedImage toBuffered(Image pOriginal, int pType)
Image to a BufferedImage of the given type.
The new image will have the same ColorModel, Raster and
properties as the original image, if possible.
If the image is already a BufferedImage of the given type, it
is simply returned and no conversion takes place.pOriginal - the image to convert.pType - the type of buffered imageBufferedImageIllegalArgumentException - if pOriginal == null
or if pType is not a valid type for BufferedImageBufferedImage.getType()public static BufferedImage createFlipped(Image pImage, int pAxis)
pImage - the image to flippAxis - the axis to flip aroundBufferedImagepublic static BufferedImage createRotated(Image pImage, int pDirection)
pDirection argument.
The new image will be completely covered with pixels from the source
image.pImage - the source image.pDirection - the direction, must be either ROTATE_90_CW,
ROTATE_90_CCW or ROTATE_180BufferedImagepublic static BufferedImage createRotated(Image pImage, double pAngle)
pImage - the source imagepAngle - the angle of rotation, in radiansBufferedImage, unless pAngle == 0.0public static BufferedImage createScaled(Image pImage, int pWidth, int pHeight, int pHints)
Image, and converts it to
a BufferedImage if needed.
If the original image is a BufferedImage the result will have
same type and color model. Note that this implies overhead, and is
probably not useful for anything but IndexColorModel images.pImage - the Image to scalepWidth - width in pixelspHeight - height in pixelspHints - scaling intsBufferedImageNullPointerException - if pImage is null.createResampled(java.awt.Image, int, int, int),
Image.getScaledInstance(int,int,int),
Image.SCALE_AREA_AVERAGING,
Image.SCALE_DEFAULT,
Image.SCALE_FAST,
Image.SCALE_REPLICATE,
Image.SCALE_SMOOTHpublic static BufferedImage createResampled(Image pImage, int pWidth, int pHeight, int pHints)
Image, and converts it to
a BufferedImage if needed.pImage - the Image to scalepWidth - width in pixelspHeight - height in pixelspHints - scaling mHintsBufferedImageNullPointerException - if pImage is null.Image.SCALE_AREA_AVERAGING,
Image.SCALE_DEFAULT,
Image.SCALE_FAST,
Image.SCALE_REPLICATE,
Image.SCALE_SMOOTH,
ResampleOppublic static BufferedImage createResampled(RenderedImage pImage, int pWidth, int pHeight, int pHints)
RenderedImage, and
converts it to a BufferedImage if needed.pImage - the RenderedImage to scalepWidth - width in pixelspHeight - height in pixelspHints - scaling mHintsBufferedImageNullPointerException - if pImage is null.Image.SCALE_AREA_AVERAGING,
Image.SCALE_DEFAULT,
Image.SCALE_FAST,
Image.SCALE_REPLICATE,
Image.SCALE_SMOOTH,
ResampleOppublic static BufferedImage createResampled(BufferedImage pImage, int pWidth, int pHeight, int pHints)
BufferedImage.pImage - the BufferedImage to scalepWidth - width in pixelspHeight - height in pixelspHints - scaling mHintsBufferedImageNullPointerException - if pImage is null.Image.SCALE_AREA_AVERAGING,
Image.SCALE_DEFAULT,
Image.SCALE_FAST,
Image.SCALE_REPLICATE,
Image.SCALE_SMOOTH,
ResampleOppublic static IndexColorModel getIndexColorModel(Image pImage, int pColors, int pHints)
IndexColorModel from the given image.pImage - the image to get the color model frompColors - the maximum number of colors in the resulting color modelpHints - hints controlling transparency and color selectionIndexColorModelCOLOR_SELECTION_DEFAULT,
COLOR_SELECTION_FAST,
COLOR_SELECTION_QUALITY,
TRANSPARENCY_DEFAULT,
TRANSPARENCY_OPAQUE,
TRANSPARENCY_BITMASK,
TRANSPARENCY_TRANSLUCENTpublic static BufferedImage createIndexed(Image pImage)
BufferedImage
with an IndexColorModel.
The resulting image will have a maximum of 256 different colors.
Transparent parts of the original will be replaced with solid black.
Default (possibly HW accelerated) dither will be used.pImage - the image to convertpublic static BufferedImage createIndexed(Image pImage, int pColors, Color pMatte, int pHints)
BufferedImage
with an IndexColorModel.pImage - the image to convertpColors - number of colors in the resulting imagepMatte - color to replace transparent parts of the original.pHints - hints controlling dither, transparency and color selectionCOLOR_SELECTION_DEFAULT,
COLOR_SELECTION_FAST,
COLOR_SELECTION_QUALITY,
DITHER_NONE,
DITHER_DEFAULT,
DITHER_DIFFUSION,
DITHER_DIFFUSION_ALTSCANS,
TRANSPARENCY_DEFAULT,
TRANSPARENCY_OPAQUE,
TRANSPARENCY_BITMASK,
TRANSPARENCY_TRANSLUCENTpublic static BufferedImage createIndexed(Image pImage, IndexColorModel pColors, Color pMatte, int pHints)
BufferedImage
with an IndexColorModel.pImage - the image to convertpColors - the IndexColorModel to be used in the resulting
image.pMatte - color to replace transparent parts of the original.pHints - hints controlling dither, transparency and color selectionCOLOR_SELECTION_DEFAULT,
COLOR_SELECTION_FAST,
COLOR_SELECTION_QUALITY,
DITHER_NONE,
DITHER_DEFAULT,
DITHER_DIFFUSION,
DITHER_DIFFUSION_ALTSCANS,
TRANSPARENCY_DEFAULT,
TRANSPARENCY_OPAQUE,
TRANSPARENCY_BITMASK,
TRANSPARENCY_TRANSLUCENTpublic static BufferedImage createIndexed(Image pImage, Image pColors, Color pMatte, int pHints)
BufferedImage
with an IndexColorModel.pImage - the image to convertpColors - an Image used to get colors from. If the image is
has an IndexColorModel, it will be uesd, otherwise an
IndexColorModel is created from the image.pMatte - color to replace transparent parts of the original.pHints - hints controlling dither, transparency and color selectionCOLOR_SELECTION_DEFAULT,
COLOR_SELECTION_FAST,
COLOR_SELECTION_QUALITY,
DITHER_NONE,
DITHER_DEFAULT,
DITHER_DIFFUSION,
DITHER_DIFFUSION_ALTSCANS,
TRANSPARENCY_DEFAULT,
TRANSPARENCY_OPAQUE,
TRANSPARENCY_BITMASK,
TRANSPARENCY_TRANSLUCENTpublic static BufferedImage sharpen(BufferedImage pOriginal)
| 0.0 | -0.3 | 0.0 |
| -0.3 | 2.2 | -0.3 |
| 0.0 | -0.3 | 0.0 |
sharpen(pOriginal, 0.3f).pOriginal - the BufferedImage to sharpenpublic static BufferedImage sharpen(BufferedImage pOriginal, float pAmount)
| 0.0 | -pAmount | 0.0 |
-pAmount |
4.0 * pAmount + 1.0 |
-pAmount |
| 0.0 | -pAmount | 0.0 |
pOriginal - the BufferedImage to sharpenpAmount - the amount of sharpeningpublic static BufferedImage blur(BufferedImage pOriginal)
pOriginal - the original imageBufferedImage with a blurred version of the given imagepublic static BufferedImage blur(BufferedImage pOriginal, float pRadius)
pOriginal - the original imagepRadius - the amount to blurBufferedImage with a blurred version of the given imagepublic static BufferedImage convolve(BufferedImage pOriginal, Kernel pKernel, int pEdgeOperation)
pOriginal - the BufferedImage to sharpenpKernel - the kernelpEdgeOperation - the edge operation. Must be one of EDGE_NO_OP,
EDGE_ZERO_FILL, EDGE_REFLECT or EDGE_WRAPpublic static Image contrast(Image pOriginal)
pOriginal - the BufferedImage to add contrast toImage, containing the contrasted image.public static Image contrast(Image pOriginal, float pAmount)
pOriginal - the Image to changepAmount - the amount of contrast in the range [-1.0..1.0].Image, containing the contrasted image.public static Image brightness(Image pOriginal, float pAmount)
pOriginal - the Image to changepAmount - the amount of brightness in the range [-2.0..2.0].Imagepublic static Image grayscale(Image pOriginal)
pOriginal - the image to convert.GrayFilter,
RGBImageFilterpublic static Image filter(Image pOriginal, ImageFilter pFilter)
ImageFilter.pOriginal - the original imagepFilter - the filter to applyImagepublic static BufferedImage accelerate(Image pImage)
pImage - any ImageBufferedImagepublic static BufferedImage accelerate(Image pImage, GraphicsConfiguration pConfiguration)
pImage - any ImagepConfiguration - the GraphicsConfiguration to accelerate
forBufferedImagepublic static BufferedImage createTransparent(int pWidth, int pHeight)
pWidth - the requested width of the imagepHeight - the requested height of the imageIllegalArgumentException - if pType is not a valid type
for BufferedImagepublic static BufferedImage createTransparent(int pWidth, int pHeight, int pType)
pWidth - the requested width of the imagepHeight - the requested height of the imagepType - the type of BufferedImage to createIllegalArgumentException - if pType is not a valid type
for BufferedImageBufferedImage(int,int,int)public static BufferedImage createClear(int pWidth, int pHeight, Color pBackground)
pWidth - the requested width of the imagepHeight - the requested height of the imagepBackground - the background color. The color may be translucent.
May be null, in such case the color is undefined.IllegalArgumentException - if pType is not a valid type
for BufferedImageBufferedImage(int,int,int)public static BufferedImage createClear(int pWidth, int pHeight, int pType, Color pBackground)
pWidth - the width of the image to createpHeight - the height of the image to createpType - the type of image to create (one of the constants from
BufferedImage or BI_TYPE_ANY)pBackground - the background color. The color may be translucent.
May be null, in such case the color is undefined.IllegalArgumentException - if pType is not a valid type
for BufferedImageBufferedImage(int,int,int)public static int getWidth(Image pImage)
pImage - an image.public static int getHeight(Image pImage)
pImage - an image.public static boolean waitForImage(Image pImage)
pImage - an Image object to wait for.waitForImage(Image,long)public static boolean waitForImage(Image pImage, long pTimeOut)
pImage - an Image object to wait for.pTimeOut - the time to wait, in milliseconds.waitForImages(Image[],long)public static boolean waitForImages(Image[] pImages)
pImages - an array of Image objects to wait for.waitForImages(Image[],long)public static boolean waitForImages(Image[] pImages, long pTimeOut)
pImages - an array of Image objects to wait forpTimeOut - the time to wait, in millisecondspublic static boolean hasTransparentPixels(RenderedImage pImage, boolean pFast)
pImage - the imagepFast - if true, the method tests maximum 10 x 10 pixels,
evenly spaced out in the image.true if transparent pixels are found, otherwise
false.public static Color createTranslucent(Color pColor, int pTransparency)
pColor - the original colorpTransparency - the transparency level (0 - 255)NullPointerException - if pColor is nullpublic static Color blend(Color pColor, Color pOther)
pColor - color 1pOther - color 2Colorpublic static Color blend(Color pColor, Color pOther, float pBlendFactor)
0.0 will return the first color,
a factor of 1.0 will return the second.pColor - color 1pOther - color 2pBlendFactor - [0...1]ColorCopyright © 2018. All rights reserved.