Class ImageUtil
- Version:
- $Id: common/common-image/src/main/java/com/twelvemonkeys/image/ImageUtil.java#3 $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intPassed to the createXxx methods, to indicate that the type does not matterstatic final intDefault color selectionstatic final intPrioritize speedstatic final intPrioritize qualityprivate static final GraphicsConfigurationstatic final intJava default ditherstatic final intError diffusion ditherstatic final intError diffusion dither with alternating scansstatic final intNo ditherstatic final intAlias forConvolveOp.EDGE_NO_OP.static final intAdds a border to the image while convolving.static final intAdds a border to the image while convolving.static final intAlias forConvolveOp.EDGE_ZERO_FILL.static final intstatic final intprotected static final AffineTransformprotected static final Pointprivate static final ComponentComponent that can be used with the MediaTracker etc.static final intstatic final intstatic final intprivate static final KernelThe sharpen kernel.private static final float[]The sharpen matrixprivate static MediaTrackerOur static image trackerstatic final intConvert alpha to bitmaskstatic final intDefault transparency (none)static final intDiscard any alpha informationprotected static final intKeep original alpha (not supported yet)private static booleanTells wether this WM may support acceleration of some images -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageaccelerate(Image pImage) Tries to use H/W-accelerated code for an image for display purposes.(package private) static BufferedImageaccelerate(Image pImage, Color pBackgroundColor, GraphicsConfiguration pConfiguration) Tries to use H/W-accelerated code for an image for display purposes.static BufferedImageaccelerate(Image pImage, GraphicsConfiguration pConfiguration) Tries to use H/W-accelerated code for an image for display purposes.private static BufferedImageaddBorder(BufferedImage pOriginal, int pBorderX, int pBorderY, int pEdgeOperation) (package private) static intblend(int pRGB1, int pRGB2) Blends two ARGB values half and half, to create a tone in between.static ColorBlends two colors half and half, to create a tone in between.static ColorBlends two colors, controlled by the blending factor.static BufferedImageblur(BufferedImage pOriginal) Creates a blurred version of the given image.static BufferedImageblur(BufferedImage pOriginal, float pRadius) Creates a blurred version of the given image.static Imagebrightness(Image pOriginal, float pAmount) Changes the brightness of the original image.private static intclamp(float f) static ImageAdds contraststatic ImageChanges the contrast of the imageprivate static intconvertAWTHints(int pHints) static BufferedImageconvolve(BufferedImage pOriginal, Kernel pKernel, int pEdgeOperation) Convolves an image, using a convolution matrix.private static BufferedImagecreateBuffered(int pWidth, int pHeight, int pType, int pTransparency) Creates aBufferedImageof the given size and type.(package private) static BufferedImagecreateBuffered(int pWidth, int pHeight, int pType, int pTransparency, GraphicsConfiguration pConfiguration) (package private) static BufferedImagecreateClear(int pWidth, int pHeight, int pType, int pTransparency, Color pBackground, GraphicsConfiguration pConfiguration) static BufferedImagecreateClear(int pWidth, int pHeight, int pType, Color pBackground) Creates a clear image with the given background color.static BufferedImagecreateClear(int pWidth, int pHeight, Color pBackground) Creates a clear image with the given background color.(package private) static WritableRastercreateCompatibleWritableRaster(BufferedImage pOriginal, ColorModel pModel, int width, int height) Workaround for bug: TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR and TYPE_4BYTE_ABGR_PRE are all converted to TYPE_CUSTOM when using the default createCompatibleWritableRaster from ComponentColorModel.static BufferedImagecreateCopy(BufferedImage pImage) Creates a deep copy of the given image.static BufferedImagecreateFlipped(Image pImage, int pAxis) Creates a flipped version of the given image.static BufferedImagecreateIndexed(Image pImage) Creates an indexed version of the given image (aBufferedImagewith anIndexColorModel.static BufferedImagecreateIndexed(Image pImage, int pColors, Color pMatte, int pHints) Creates an indexed version of the given image (aBufferedImagewith anIndexColorModel.static BufferedImagecreateIndexed(Image pImage, IndexColorModel pColors, Color pMatte, int pHints) Creates an indexed version of the given image (aBufferedImagewith anIndexColorModel.static BufferedImagecreateIndexed(Image pImage, Image pColors, Color pMatte, int pHints) Creates an indexed version of the given image (aBufferedImagewith anIndexColorModel.(package private) static WritableRastercreateRaster(int pWidth, int pHeight, Object pPixels, ColorModel pColorModel) Creates aWritableRasterfor the givenColorModeland pixel data.static BufferedImagecreateResampled(BufferedImage pImage, int pWidth, int pHeight, int pHints) Creates a scaled instance of the givenBufferedImage.static BufferedImagecreateResampled(RenderedImage pImage, int pWidth, int pHeight, int pHints) Creates a scaled instance of the givenRenderedImage, and converts it to aBufferedImageif needed.static BufferedImagecreateResampled(Image pImage, int pWidth, int pHeight, int pHints) Creates a scaled instance of the givenImage, and converts it to aBufferedImageif needed.static BufferedImagecreateRotated(Image pImage, double pAngle) Rotates the image to the given angle.static BufferedImagecreateRotated(Image pImage, int pDirection) Rotates the image 90 degrees, clockwise (aka "rotate right"), counter-clockwise (aka "rotate left") or 180 degrees, depending on thepDirectionargument.private static BufferedImagecreateRotated0(BufferedImage pSource, double pAngle) static BufferedImagecreateScaled(Image pImage, int pWidth, int pHeight, int pHints) Creates a scaled instance of the givenImage, and converts it to aBufferedImageif needed.static ColorcreateTranslucent(Color pColor, int pTransparency) Creates a translucent version of the given color.static BufferedImagecreateTransparent(int pWidth, int pHeight) Creates a transparent image.static BufferedImagecreateTransparent(int pWidth, int pHeight, int pType) Creates a transparent image.(package private) static voiddrawOnto(BufferedImage pDestination, Image pSource) Draws the source image onto the buffered image, usingAlphaComposite.Srcand coordinates0, 0.private static booleanequals(ColorModel pLeft, ColorModel pRight) static Imagefilter(Image pOriginal, ImageFilter pFilter) Filters an image, using the givenImageFilter.private static GraphicsConfigurationgetConfiguration(GraphicsConfiguration pConfiguration) private static GraphicsConfigurationstatic intGets the height of an Image.private static intgetImageType(int pType, int pTransparency) static IndexColorModelgetIndexColorModel(Image pImage, int pColors, int pHints) Extracts anIndexColorModelfrom the given image.private static intgetTransparency(Image pImage) static intGets the width of an Image.static ImageConverts an image to grayscale.static booleanhasTransparentPixels(RenderedImage pImage, boolean pFast) Tests whether the image has any transparent or semi-transparent pixels.private static booleanisIndexedPacked(IndexColorModel pColorModel) private static KernelmakeKernel(float radius) Make a Gaussian blurKernel.static BufferedImagesharpen(BufferedImage pOriginal) Sharpens an image using a convolution matrix.static BufferedImagesharpen(BufferedImage pOriginal, float pAmount) Sharpens an image using a convolution matrix.private static booleanTests if the givenGraphicsEnvironmentsupports accellerationstatic BufferedImagetoBuffered(Image pOriginal) Converts theImageto aBufferedImage.static BufferedImagetoBuffered(BufferedImage pOriginal, int pType) Converts theBufferedImageto aBufferedImageof the given type.static BufferedImagetoBuffered(RenderedImage pOriginal) Converts theRenderedImageto aBufferedImage.static BufferedImagetoBuffered(RenderedImage pOriginal, int pType) Converts theRenderedImageto aBufferedImageof the given type.static BufferedImagetoBuffered(Image pOriginal, int pType) Converts theImageto aBufferedImageof the given type.private static BufferedImagetoBuffered(Image pOriginal, int pType, IndexColorModel pICM) static booleanwaitForImage(Image pImage) Waits for an image to load completely.static booleanwaitForImage(Image pImage, long pTimeOut) Waits for an image to load completely.static booleanwaitForImages(Image[] pImages) Waits for a number of images to load completely.static booleanwaitForImages(Image[] pImages, long pTimeOut) Waits for a number of images to load completely.
-
Field Details
-
ROTATE_90_CCW
public static final int ROTATE_90_CCW- See Also:
-
ROTATE_90_CW
public static final int ROTATE_90_CW- See Also:
-
ROTATE_180
public static final int ROTATE_180- See Also:
-
FLIP_VERTICAL
public static final int FLIP_VERTICAL- See Also:
-
FLIP_HORIZONTAL
public static final int FLIP_HORIZONTAL- See Also:
-
EDGE_ZERO_FILL
-
EDGE_NO_OP
-
EDGE_REFLECT
public static final int EDGE_REFLECTAdds a border to the image while convolving. The border will reflect the edges of the original image. This is usually a good default. Note that while this mode typically provides better quality than the standard modesEDGE_ZERO_FILLandEDGE_NO_OP, it does so at the expense of higher memory consumption and considerable more computation.- See Also:
-
EDGE_WRAP
public static final int EDGE_WRAPAdds a border to the image while convolving. The border will wrap the edges of the original image. This is usually the best choice for tiles. Note that while this mode typically provides better quality than the standard modesEDGE_ZERO_FILLandEDGE_NO_OP, it does so at the expense of higher memory consumption and considerable more computation.- See Also:
-
DITHER_DEFAULT
public static final int DITHER_DEFAULTJava default dither- See Also:
-
DITHER_NONE
public static final int DITHER_NONENo dither- See Also:
-
DITHER_DIFFUSION
public static final int DITHER_DIFFUSIONError diffusion dither- See Also:
-
DITHER_DIFFUSION_ALTSCANS
public static final int DITHER_DIFFUSION_ALTSCANSError diffusion dither with alternating scans- See Also:
-
COLOR_SELECTION_DEFAULT
public static final int COLOR_SELECTION_DEFAULTDefault color selection- See Also:
-
COLOR_SELECTION_FAST
public static final int COLOR_SELECTION_FASTPrioritize speed- See Also:
-
COLOR_SELECTION_QUALITY
public static final int COLOR_SELECTION_QUALITYPrioritize quality- See Also:
-
TRANSPARENCY_DEFAULT
public static final int TRANSPARENCY_DEFAULTDefault transparency (none)- See Also:
-
TRANSPARENCY_OPAQUE
public static final int TRANSPARENCY_OPAQUEDiscard any alpha information- See Also:
-
TRANSPARENCY_BITMASK
public static final int TRANSPARENCY_BITMASKConvert alpha to bitmask- See Also:
-
TRANSPARENCY_TRANSLUCENT
protected static final int TRANSPARENCY_TRANSLUCENTKeep original alpha (not supported yet)- See Also:
-
BI_TYPE_ANY
private static final int BI_TYPE_ANYPassed to the createXxx methods, to indicate that the type does not matter- See Also:
-
VM_SUPPORTS_ACCELERATION
private static boolean VM_SUPPORTS_ACCELERATIONTells wether this WM may support acceleration of some images -
SHARPEN_MATRIX
private static final float[] SHARPEN_MATRIXThe sharpen matrix -
SHARPEN_KERNEL
The sharpen kernel. Uses the following 3 by 3 matrix:Sharpen Kernel Matrix 0.0 -0.3 0.0 -0.3 2.2 -0.3 0.0 -0.3 0.0 -
NULL_COMPONENT
Component that can be used with the MediaTracker etc. -
sTracker
Our static image tracker -
IDENTITY_TRANSFORM
-
LOCATION_UPPER_LEFT
-
DEFAULT_CONFIGURATION
-
-
Constructor Details
-
ImageUtil
private ImageUtil()Creates an ImageUtil. Private constructor.
-
-
Method Details
-
getDefaultGraphicsConfiguration
-
toBuffered
Converts theRenderedImageto aBufferedImage. The new image will have the sameColorModel,Rasterand properties as the original image, if possible.If the image is already a
BufferedImage, it is simply returned and no conversion takes place.- Parameters:
pOriginal- the image to convert.- Returns:
- a
BufferedImage
-
toBuffered
Converts theRenderedImageto aBufferedImageof the given type.If the image is already a
BufferedImageof the given type, it is simply returned and no conversion takes place.- Parameters:
pOriginal- the image to convert.pType- the type of buffered image- Returns:
- a
BufferedImage - Throws:
IllegalArgumentException- ifpOriginal == nullorpTypeis not a valid type forBufferedImage- See Also:
-
toBuffered
Converts theBufferedImageto aBufferedImageof the given type. The new image will have the sameColorModel,Rasterand properties as the original image, if possible.If the image is already a
BufferedImageof the given type, it is simply returned and no conversion takes place.This method simply invokes
toBuffered((RenderedImage) pOriginal, pType).- Parameters:
pOriginal- the image to convert.pType- the type of buffered image- Returns:
- a
BufferedImage - Throws:
IllegalArgumentException- ifpOriginal == nullor ifpTypeis not a valid type forBufferedImage- See Also:
-
toBuffered
Converts theImageto aBufferedImage. The new image will have the sameColorModel,Rasterand properties as the original image, if possible.If the image is already a
BufferedImage, it is simply returned and no conversion takes place.- Parameters:
pOriginal- the image to convert.- Returns:
- a
BufferedImage - Throws:
IllegalArgumentException- ifpOriginal == nullImageConversionException- if the image cannot be converted
-
createCopy
Creates a deep copy of the given image. The image will have the same color model and raster type, but will not share image (pixel) data with the input image.- Parameters:
pImage- the image to clone.- Returns:
- a new
BufferedImage - Throws:
IllegalArgumentException- ifpImageisnull
-
createRaster
Creates aWritableRasterfor the givenColorModeland pixel data.This method is optimized for the most common cases of
ColorModeland pixel data combinations. The raster's backingDataBufferis created directly from the pixel data, as this is faster and more resource-friendly than usingColorModel.createCompatibleWritableRaster(w, h).For uncommon combinations, the method will fallback to using
ColorModel.createCompatibleWritableRaster(w, h)andWritableRaster.setDataElements(w, h, pixels)Note that the
ColorModeland pixel data are not cloned (in most cases).- Parameters:
pWidth- the requested raster widthpHeight- the requested raster heightpPixels- the pixels, as an array, of a type supported by the differentDataBufferpColorModel- the color model to use- Returns:
- a new
WritableRaster - Throws:
NullPointerException- if eitherpColorModelorpPixelsarenull.RuntimeException- ifpWidthandpHeightdoes not match the pixel data inpPixels.- See Also:
-
isIndexedPacked
-
createCompatibleWritableRaster
static WritableRaster createCompatibleWritableRaster(BufferedImage pOriginal, ColorModel pModel, int width, int height) Workaround for bug: TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR and TYPE_4BYTE_ABGR_PRE are all converted to TYPE_CUSTOM when using the default createCompatibleWritableRaster from ComponentColorModel.- Parameters:
pOriginal- the orignal imagepModel- the original color modelwidth- the requested width of the rasterheight- the requested height of the raster- Returns:
- a new WritableRaster
-
toBuffered
Converts theImageto aBufferedImageof the given type. The new image will have the sameColorModel,Rasterand properties as the original image, if possible.If the image is already a
BufferedImageof the given type, it is simply returned and no conversion takes place.- Parameters:
pOriginal- the image to convert.pType- the type of buffered image- Returns:
- a
BufferedImage - Throws:
IllegalArgumentException- ifpOriginal == nullor ifpTypeis not a valid type forBufferedImage- See Also:
-
toBuffered
- Parameters:
pOriginal- the original imagepType- the type ofBufferedImageto createpICM- the optionalIndexColorModelto use. If notnullthepTypemust be compatible with the color model- Returns:
- a
BufferedImage - Throws:
IllegalArgumentException- ifpTypeis not compatible with the color model
-
drawOnto
Draws the source image onto the buffered image, usingAlphaComposite.Srcand coordinates0, 0.- Parameters:
pDestination- the image to draw onpSource- the source image to draw- Throws:
NullPointerException- ifpDestinationorpSourceisnull
-
createFlipped
Creates a flipped version of the given image.- Parameters:
pImage- the image to flippAxis- the axis to flip around- Returns:
- a new
BufferedImage
-
createRotated
Rotates the image 90 degrees, clockwise (aka "rotate right"), counter-clockwise (aka "rotate left") or 180 degrees, depending on thepDirectionargument.The new image will be completely covered with pixels from the source image.
- Parameters:
pImage- the source image.pDirection- the direction, must be eitherROTATE_90_CW,ROTATE_90_CCWorROTATE_180- Returns:
- a new
BufferedImage
-
createRotated
Rotates the image to the given angle. Areas not covered with pixels from the source image will be left transparent, if possible.- Parameters:
pImage- the source imagepAngle- the angle of rotation, in radians- Returns:
- a new
BufferedImage, unlesspAngle == 0.0
-
createRotated0
-
createScaled
Creates a scaled instance of the givenImage, and converts it to aBufferedImageif needed. If the original image is aBufferedImagethe result will have same type and color model. Note that this implies overhead, and is probably not useful for anything butIndexColorModelimages.- Parameters:
pImage- theImageto scalepWidth- width in pixelspHeight- height in pixelspHints- scaling ints- Returns:
- a
BufferedImage - Throws:
NullPointerException- ifpImageisnull.- See Also:
-
equals
-
createResampled
Creates a scaled instance of the givenImage, and converts it to aBufferedImageif needed.- Parameters:
pImage- theImageto scalepWidth- width in pixelspHeight- height in pixelspHints- scaling mHints- Returns:
- a
BufferedImage - Throws:
NullPointerException- ifpImageisnull.- See Also:
-
createResampled
public static BufferedImage createResampled(RenderedImage pImage, int pWidth, int pHeight, int pHints) Creates a scaled instance of the givenRenderedImage, and converts it to aBufferedImageif needed.- Parameters:
pImage- theRenderedImageto scalepWidth- width in pixelspHeight- height in pixelspHints- scaling mHints- Returns:
- a
BufferedImage - Throws:
NullPointerException- ifpImageisnull.- See Also:
-
createResampled
public static BufferedImage createResampled(BufferedImage pImage, int pWidth, int pHeight, int pHints) Creates a scaled instance of the givenBufferedImage.- Parameters:
pImage- theBufferedImageto scalepWidth- width in pixelspHeight- height in pixelspHints- scaling mHints- Returns:
- a
BufferedImage - Throws:
NullPointerException- ifpImageisnull.- See Also:
-
convertAWTHints
private static int convertAWTHints(int pHints) -
getIndexColorModel
Extracts anIndexColorModelfrom the given image.- Parameters:
pImage- the image to get the color model frompColors- the maximum number of colors in the resulting color modelpHints- hints controlling transparency and color selection- Returns:
- the extracted
IndexColorModel - See Also:
-
createIndexed
Creates an indexed version of the given image (aBufferedImagewith anIndexColorModel. 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.- Parameters:
pImage- the image to convert- Returns:
- an indexed version of the given image
-
createIndexed
Creates an indexed version of the given image (aBufferedImagewith anIndexColorModel.- Parameters:
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 selection- Returns:
- an indexed version of the given image
- See Also:
-
createIndexed
public static BufferedImage createIndexed(Image pImage, IndexColorModel pColors, Color pMatte, int pHints) Creates an indexed version of the given image (aBufferedImagewith anIndexColorModel.- Parameters:
pImage- the image to convertpColors- theIndexColorModelto be used in the resulting image.pMatte- color to replace transparent parts of the original.pHints- hints controlling dither, transparency and color selection- Returns:
- an indexed version of the given image
- See Also:
-
createIndexed
Creates an indexed version of the given image (aBufferedImagewith anIndexColorModel.- Parameters:
pImage- the image to convertpColors- anImageused to get colors from. If the image is has anIndexColorModel, it will be uesd, otherwise anIndexColorModelis created from the image.pMatte- color to replace transparent parts of the original.pHints- hints controlling dither, transparency and color selection- Returns:
- an indexed version of the given image
- See Also:
-
sharpen
Sharpens an image using a convolution matrix. The sharpen kernel used, is defined by the following 3 by 3 matrix:Sharpen Kernel Matrix 0.0 -0.3 0.0 -0.3 2.2 -0.3 0.0 -0.3 0.0 This is the same result returned as
sharpen(pOriginal, 0.3f).- Parameters:
pOriginal- the BufferedImage to sharpen- Returns:
- a new BufferedImage, containing the sharpened image.
-
sharpen
Sharpens an image using a convolution matrix. The sharpen kernel used, is defined by the following 3 by 3 matrix:Sharpen Kernel Matrix 0.0 - pAmount0.0 - pAmount4.0 * pAmount+ 1.0- pAmount0.0 - pAmount0.0 - Parameters:
pOriginal- the BufferedImage to sharpenpAmount- the amount of sharpening- Returns:
- a BufferedImage, containing the sharpened image.
-
blur
Creates a blurred version of the given image.- Parameters:
pOriginal- the original image- Returns:
- a new
BufferedImagewith a blurred version of the given image
-
blur
Creates a blurred version of the given image.- Parameters:
pOriginal- the original imagepRadius- the amount to blur- Returns:
- a new
BufferedImagewith a blurred version of the given image
-
makeKernel
-
convolve
Convolves an image, using a convolution matrix.- Parameters:
pOriginal- the BufferedImage to sharpenpKernel- the kernelpEdgeOperation- the edge operation. Must be one ofEDGE_NO_OP,EDGE_ZERO_FILL,EDGE_REFLECTorEDGE_WRAP- Returns:
- a new BufferedImage, containing the sharpened image.
-
addBorder
private static BufferedImage addBorder(BufferedImage pOriginal, int pBorderX, int pBorderY, int pEdgeOperation) -
contrast
-
contrast
-
brightness
-
grayscale
-
filter
Filters an image, using the givenImageFilter.- Parameters:
pOriginal- the original imagepFilter- the filter to apply- Returns:
- the new
Image
-
accelerate
Tries to use H/W-accelerated code for an image for display purposes. Note that transparent parts of the image might be replaced by solid color. Additional image information not used by the current diplay hardware may be discarded, like extra bith depth etc.- Parameters:
pImage- anyImage- Returns:
- a
BufferedImage
-
accelerate
Tries to use H/W-accelerated code for an image for display purposes. Note that transparent parts of the image might be replaced by solid color. Additional image information not used by the current diplay hardware may be discarded, like extra bith depth etc.- Parameters:
pImage- anyImagepConfiguration- theGraphicsConfigurationto accelerate for- Returns:
- a
BufferedImage
-
accelerate
static BufferedImage accelerate(Image pImage, Color pBackgroundColor, GraphicsConfiguration pConfiguration) Tries to use H/W-accelerated code for an image for display purposes. Note that transparent parts of the image will be replaced by solid color. Additional image information not used by the current diplay hardware may be discarded, like extra bith depth etc.- Parameters:
pImage- anyImagepBackgroundColor- the background color to replace any transparent parts of the image. May benull, in such case the color is undefined.pConfiguration- the graphics configuration May benull, in such case the color is undefined.- Returns:
- a
BufferedImage
-
getTransparency
-
createTransparent
Creates a transparent image.- Parameters:
pWidth- the requested width of the imagepHeight- the requested height of the image- Returns:
- the new image
- Throws:
IllegalArgumentException- ifpTypeis not a valid type forBufferedImage
-
createTransparent
Creates a transparent image.- Parameters:
pWidth- the requested width of the imagepHeight- the requested height of the imagepType- the type ofBufferedImageto create- Returns:
- the new image
- Throws:
IllegalArgumentException- ifpTypeis not a valid type forBufferedImage- See Also:
-
createClear
Creates a clear image with the given background color.- Parameters:
pWidth- the requested width of the imagepHeight- the requested height of the imagepBackground- the background color. The color may be translucent. May benull, in such case the color is undefined.- Returns:
- the new image
- Throws:
IllegalArgumentException- ifpTypeis not a valid type forBufferedImage- See Also:
-
createClear
Creates a clear image with the given background color.- Parameters:
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 fromBufferedImageorBI_TYPE_ANY)pBackground- the background color. The color may be translucent. May benull, in such case the color is undefined.- Returns:
- the new image
- Throws:
IllegalArgumentException- ifpTypeis not a valid type forBufferedImage- See Also:
-
createClear
static BufferedImage createClear(int pWidth, int pHeight, int pType, int pTransparency, Color pBackground, GraphicsConfiguration pConfiguration) -
createBuffered
Creates aBufferedImageof the given size and type. If possible, uses accelerated versions of BufferedImage from GraphicsConfiguration.- Parameters:
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 fromBufferedImageorBI_TYPE_ANY)pTransparency- the transparency type (fromTransparency)- Returns:
- a
BufferedImage
-
createBuffered
static BufferedImage createBuffered(int pWidth, int pHeight, int pType, int pTransparency, GraphicsConfiguration pConfiguration) -
getConfiguration
-
getImageType
private static int getImageType(int pType, int pTransparency) -
supportsAcceleration
Tests if the givenGraphicsEnvironmentsupports accelleration- Parameters:
pEnv- the environment- Returns:
trueif theGraphicsEnvironmentsupports acceleration
-
getWidth
Gets the width of an Image. This method has the side-effect of completely loading the image.- Parameters:
pImage- an image.- Returns:
- the width of the image, or -1 if the width could not be determined (i.e. an error occured while waiting for the image to load).
-
getHeight
Gets the height of an Image. This method has the side-effect of completely loading the image.- Parameters:
pImage- an image.- Returns:
- the height of the image, or -1 if the height could not be determined (i.e. an error occured while waiting for the image to load).
-
waitForImage
Waits for an image to load completely. Will wait forever.- Parameters:
pImage- an Image object to wait for.- Returns:
- true if the image was loaded successfully, false if an error occured, or the wait was interrupted.
- See Also:
-
waitForImage
Waits for an image to load completely. Will wait the specified time.- Parameters:
pImage- an Image object to wait for.pTimeOut- the time to wait, in milliseconds.- Returns:
- true if the image was loaded successfully, false if an error occurred, or the wait was interrupted.
- See Also:
-
waitForImages
Waits for a number of images to load completely. Will wait forever.- Parameters:
pImages- an array of Image objects to wait for.- Returns:
- true if the images was loaded successfully, false if an error occurred, or the wait was interrupted.
- See Also:
-
waitForImages
Waits for a number of images to load completely. Will wait the specified time.- Parameters:
pImages- an array of Image objects to wait forpTimeOut- the time to wait, in milliseconds- Returns:
- true if the images was loaded successfully, false if an error occurred, or the wait was interrupted.
-
hasTransparentPixels
Tests whether the image has any transparent or semi-transparent pixels.- Parameters:
pImage- the imagepFast- iftrue, the method tests maximum 10 x 10 pixels, evenly spaced out in the image.- Returns:
trueif transparent pixels are found, otherwisefalse.
-
createTranslucent
Creates a translucent version of the given color.- Parameters:
pColor- the original colorpTransparency- the transparency level (0 - 255)- Returns:
- a translucent color
- Throws:
NullPointerException- ifpColorisnull
-
blend
static int blend(int pRGB1, int pRGB2) Blends two ARGB values half and half, to create a tone in between.- Parameters:
pRGB1- color 1pRGB2- color 2- Returns:
- the new rgb value
-
blend
-
blend
Blends two colors, controlled by the blending factor. A factor of0.0will return the first color, a factor of1.0will return the second.- Parameters:
pColor- color 1pOther- color 2pBlendFactor-[0...1]- Returns:
- a new
Color
-
clamp
private static int clamp(float f)
-