public class ImageTool extends Object
Modifier and Type | Field and Description |
---|---|
static int |
ALPHA_LEVEL_ALL_FULLY_OPAQUE
A return value from checkAlphaLevel().
|
static int |
ALPHA_LEVEL_ALL_FULLY_OPAQUE_OR_FULLY_TRANSPARENT
A return value from checkAlphaLevel().
|
static int |
ALPHA_LEVEL_HAS_MIXED_TRANSPARENCY
A return value from checkAlphaLevel().
|
static int |
ALPHA_LEVEL_MASK
Can be used to mask off other bits to get the ALPHA_LEVEL_ALONE.
|
static int |
ALPHA_LEVEL_UNKNOWN
This value is 3 and is not returned by checkAlphaLevel() so you can use it to indicate that the alpha level
of an image has not yet been checked.
|
static int |
BEST_SCALED_SCALE_DOWN_ONLY |
static int |
BEST_SCALED_SCALE_UP_ONLY |
int[] |
createColorTable
This is the optional color map that will be used for createImage().
|
int |
createOptions
These are the options that will be used for createImage().
|
static int |
SCALE_KEEP_ASPECT_RATIO
An option for one of the scale() methods.
|
static int |
SCALE_ROUGH
An option for the scale() methods.
|
static int |
SCALE_USE_EXACT_TYPE
An option for one of the scale() methods.
|
Constructor and Description |
---|
ImageTool() |
ImageTool(int createOptions) |
ImageTool(int createOptions,
int[] createColorTable) |
Modifier and Type | Method and Description |
---|---|
static void |
adjustAreaAndScale(int originalWidth,
int originalHeight,
Rect srcArea,
Dimension newSize,
int createOptions)
Adjust an image srcArea to fit within the original size of the image
and adjust the newSize according to the scale options.
|
static void |
adjustScale(Dimension newSize,
int oldWidth,
int oldHeight,
int createOptions)
Adjust the newSize value such that scaling oldWidth and oldHeight
to newSize.width and newSize.height will
adhere to the options specified in createOptions.
|
static IImage |
changeBlack(IImage src,
int to)
Change a black/grayscale image to a color.
|
static Picture |
changeColor(IImage src,
int from,
int to) |
static IImage |
changeColor(IImage src,
int from,
int mask,
int to,
PixelBuffer dest)
Change colors pixel by pixel in a source IImage.
|
static int |
checkAlphaLevel(ImageData image,
int maxLinesToCheck,
boolean stopAtAnyNonOpaqueValue)
Check an ImageData to see what the alpha levels are.
|
static void |
copySection(ImageData src,
int x,
int y,
int width,
int height,
ImageData dest,
int destX,
int destY) |
static Image |
createCompatibleImage(ImageData source,
int newWidth,
int newHeight)
Create a new Image that is compatible with the source ImageData.
|
static Image |
createCompatibleImage(ImageData source,
int destinationImageDataType,
int newWidth,
int newHeight)
Create a new Image that is compatible with the source ImageData, given a specific destination ImageData type.
|
Image |
createImage(int width,
int height)
This creates an Image using the createOptions and createColorTable fields.
|
static Image |
createImageUsing(ImageTool it,
int width,
int height,
int defaultOptions)
If the specified ImageTool is null, then an image will be
created using the default options, otherwise the specified ImageTool is used to create the image.
|
static void |
drawScaled(ImageData d,
Graphics g,
int x,
int y,
int width,
int height,
int options) |
static Picture |
fillBackground(Drawable d,
Color background)
Create a picture that is an ImageData drawn over a background.
|
static void |
fromARGB(int[] argbData,
int argbOffset,
int argbScanLineLength,
ImageData destinationInfo,
Object destScanLines,
int destOffset,
int numScanLines) |
static ImageData |
getBestScaledIcon(Iterator availableImageData,
int forWidth,
int forHeight,
int options) |
static Image |
getCompatibleImagePoints(double widthInPoints,
double heightInPoints,
ISurface surface,
double assumeXdpi,
double assumeYdpi)
Get an Image for an ISurface even if the ISurface cannot determine its DPI.
|
static int[] |
getGrayScaleColorTable(int imageDataType)
Create and return a Gray scale color table.
|
static boolean |
getNontransparentArea(ImageData src,
Rect destination) |
static IImage |
getNontransparentSection(ImageData src) |
static PixelBuffer |
getNontransparentSection(ImageData src,
PixelBuffer destBuffer) |
static Object |
getScanLineBuffer(ImageData imageData,
int numScanLines,
Object oldBuffer)
Create an int[] or byte[] buffer to read/write scan lines from the specified ImageData,
re-using a previous buffer object if possible.
|
static void |
imprint(ImageData big,
ImageData small)
This method "imprints" the data in the small ImageData into the big ImageData
at the top left corner of the big ImageData.
|
static IImage |
insetImage(ImageData src,
int top,
int left,
int bottom,
int right,
boolean nonTransparentAreaOnly) |
static IImage |
insetImageByRatio(ImageData src,
double topRatio,
double leftRatio,
double bottomRatio,
double rightRatio,
boolean nonTransparentAreaOnly) |
static boolean |
isAGrayScaleImage(int imageDataType) |
static boolean |
isAnIndexedImage(int imageDataType) |
static int[] |
makeDefaultColorTable(int imageDataType)
Create and return a Color Table for one of the TYPE_INDEXED_XXX types.
|
static void |
scale(ImageData source,
ImageData destination)
Scale a source Image so that it fits exactly into the destination Image using smooth
scaling.
|
static void |
scale(ImageData source,
ImageData destination,
int options)
Scale a source Image so that it fits exactly into the destination Image.
|
static Image |
scale(ImageData source,
int newWidth,
int newHeight,
int scaleOptions)
Scale an image and return a new image.
|
static void |
scaleSection(ImageData source,
int newWidth,
int newHeight,
ImageData dest,
int destX,
int destY,
int options)
Scale an image and then place a section of the scaled image into an ImageData object.
|
static Image |
scaleSection(ImageData source,
int newWidth,
int newHeight,
Rect destinationArea,
int scaleOptions)
Scale an image and return a section of the scaled image.
|
static Image |
scaleSourceSection(ImageData source,
Rect sourceArea,
int newWidth,
int newHeight,
int scaleOptions)
Scale a section of an image and return a new image.
|
static void |
toARGB(ImageData sourceInfo,
Object sourceScanLines,
int sourceOffset,
int[] argbData,
int argbOffset,
int argbScanLineLength,
int numScanLines)
Set a rectangular section of an ImageData as ARGB pixel information in an int array.
|
static ImageData |
toImageData(IImage image)
Return the best ImageData implementation for the specified IImage.
|
static PixelBuffer |
toPixelBuffer(PixelBuffer dest,
IPointImage pi,
double xdpi,
double ydpi,
int options) |
static boolean |
usesColorTable(int imageDataType) |
static int[] |
validatePixelBuffer(boolean isGetBuffer,
ImageData image,
int[] buffer,
int offset,
int width,
int height,
int rowStride)
Checks the buffer to be used for getPixels() or setPixels() and throws any appropriate
exceptions.
|
static void |
validateRGBLine(int[] rgb,
int offset,
int width,
int rowStride,
int numLines) |
static void |
validateScanLine(ImageData dest,
Object data,
int offset,
int startScanLine,
int numScanLines,
int rowStride)
This checks that the Object holding scan line data is of the correct type to hold
scan lines for the specified source or destination ImageData, and that the array
is big enough to hold all the specified scan lines.
|
public static final int ALPHA_LEVEL_UNKNOWN
public static final int ALPHA_LEVEL_ALL_FULLY_OPAQUE
public static final int ALPHA_LEVEL_ALL_FULLY_OPAQUE_OR_FULLY_TRANSPARENT
public static final int ALPHA_LEVEL_HAS_MIXED_TRANSPARENCY
public static final int ALPHA_LEVEL_MASK
public int createOptions
public int[] createColorTable
public static final int SCALE_ROUGH
public static final int SCALE_KEEP_ASPECT_RATIO
public static final int SCALE_USE_EXACT_TYPE
public static final int BEST_SCALED_SCALE_UP_ONLY
public static final int BEST_SCALED_SCALE_DOWN_ONLY
public ImageTool()
public ImageTool(int createOptions)
public ImageTool(int createOptions, int[] createColorTable)
public static int checkAlphaLevel(ImageData image, int maxLinesToCheck, boolean stopAtAnyNonOpaqueValue)
image
- the image to check.maxLinesToCheck
- the maximum number of lines to check in the image before assuming the result is correct. If
this is 0 or less the method will check all lines in the image. Note that as soon as a single pixel is encountered
with a alpha byte value that is not 0 and not 255, then the method returns immediately with ALPHA_LEVEL_HAS_MIXED_TRANSPARENCY.stopAtAnyNonOpaqueValue
- if this is true the first pixel found with an alpha value that is not fully opaque,
i.e. the alpha byte value is not 255, will cause the method to return with ALPHA_LEVEL_ALL_FULLY_OPAQUE_OR_FULLY_TRANSPARENT
or ALPHA_LEVEL_HAS_MIXED_TRANSPARENCY.public static void adjustScale(Dimension newSize, int oldWidth, int oldHeight, int createOptions)
public static void adjustAreaAndScale(int originalWidth, int originalHeight, Rect srcArea, Dimension newSize, int createOptions)
originalWidth
- the original image width.originalHeight
- the original image height.srcArea
- the source area within the image.newSize
- the new size of the source area.createOptions
- - any of the ImageData.CREATE_OPTION_XXX values.public static boolean isAnIndexedImage(int imageDataType)
public static boolean isAGrayScaleImage(int imageDataType)
public static boolean usesColorTable(int imageDataType)
public Image createImage(int width, int height) throws SystemResourceException, ImageTypeNotSupportedException, IllegalArgumentException
public static Image createImageUsing(ImageTool it, int width, int height, int defaultOptions) throws SystemResourceException, ImageTypeNotSupportedException, IllegalArgumentException
public static Image createCompatibleImage(ImageData source, int destinationImageDataType, int newWidth, int newHeight) throws IllegalArgumentException, SystemResourceException, ImageTypeNotSupportedException
source
- The source ImageData.destinationImageDataType
- The desired new ImageData type. If this is one of the
TYPE_INDEXED_XXX values, then the source ImageData must be of the exact same type so that
the source color table can be transferred to the new image.newWidth
- The new width for the image.newHeight
- The new height for the image.IllegalArgumentException
ewe.sys.SystemResourceException
ImageTypeNotSupportedException
SystemResourceException
public static Image createCompatibleImage(ImageData source, int newWidth, int newHeight) throws IllegalArgumentException, SystemResourceException, ImageTypeNotSupportedException
source
- The source ImageData.newWidth
- The new width for the image.newHeight
- The new height for the image.IllegalArgumentException
ewe.sys.SystemResourceException
ImageTypeNotSupportedException
SystemResourceException
public static Image scale(ImageData source, int newWidth, int newHeight, int scaleOptions) throws IllegalArgumentException, SystemResourceException, ImageTypeNotSupportedException
source
- the source ImageDatanewWidth
- the new width for the image.newHeight
- the new height for the image.scaleOptions
- any of the SCALE_XXX options.IllegalArgumentException
ewe.sys.SystemResourceException
ImageTypeNotSupportedException
SystemResourceException
public static Image scaleSourceSection(ImageData source, Rect sourceArea, int newWidth, int newHeight, int scaleOptions) throws IllegalArgumentException, SystemResourceException, ImageTypeNotSupportedException
source
- the source ImageDatasourceArea
- the area within the source image to scale.newWidth
- the new width for the entire image.newHeight
- the new height for the entire image.scaleOptions
- any of the SCALE_XXX options.IllegalArgumentException
ewe.sys.SystemResourceException
ImageTypeNotSupportedException
SystemResourceException
public static Image scaleSection(ImageData source, int newWidth, int newHeight, Rect destinationArea, int scaleOptions) throws IllegalArgumentException, SystemResourceException, ImageTypeNotSupportedException
source
- the source ImageDatanewWidth
- the new width for the image.newHeight
- the new height for the image.destinationArea
- the area in the scaled image to return.scaleOptions
- any of the SCALE_XXX options.IllegalArgumentException
SystemResourceException
ImageTypeNotSupportedException
public static void scale(ImageData source, ImageData destination)
source
- The source ImageDatadestination
- The destination Image.public static void scale(ImageData source, ImageData destination, int options)
source
- The source ImageDatadestination
- The destination Image.options
- only SCALE_ROUGH or 0.public static ImageData toImageData(IImage image)
public static void scaleSection(ImageData source, int newWidth, int newHeight, ImageData dest, int destX, int destY, int options)
source
- The source image.newWidth
- The width of the complete image after scaling.newHeight
- The height of the complete image after scaling.dest
- The destination imageData.destX
- The x point within the scaled image that should go into the destination image.destY
- The y point within the scaled image that should go into the destination image.options
- Options for scaling - so far only the SCALE_ROUGH is supported.public static void copySection(ImageData src, int x, int y, int width, int height, ImageData dest, int destX, int destY)
public static void imprint(ImageData big, ImageData small)
public static int[] getGrayScaleColorTable(int imageDataType)
public static int[] makeDefaultColorTable(int imageDataType)
public static Object getScanLineBuffer(ImageData imageData, int numScanLines, Object oldBuffer)
imageData
- The imageData to read/write scan lines.numScanLines
- The number of scan lines to read/write.oldBuffer
- An object to be re-used if possible.public static void toARGB(ImageData sourceInfo, Object sourceScanLines, int sourceOffset, int[] argbData, int argbOffset, int argbScanLineLength, int numScanLines)
source
- the source ImageData.dest
- the destination for the pixels. If it is null a new one will be created.offset
- the offset for the first pixel in the destination array.x
- the x location within the source.y
- the y location within the source.iconWidth
- the number of pixels wide.iconHeight
- the number of pixels high.rowStride
- the number of int values between successive rows in the
destination array. If this is 0 it will default to the width value.public static void fromARGB(int[] argbData, int argbOffset, int argbScanLineLength, ImageData destinationInfo, Object destScanLines, int destOffset, int numScanLines)
public static void validateRGBLine(int[] rgb, int offset, int width, int rowStride, int numLines)
public static void validateScanLine(ImageData dest, Object data, int offset, int startScanLine, int numScanLines, int rowStride) throws IllegalArgumentException, IndexOutOfBoundsException
dest
- the destination or source ImageData.data
- the byte or int array holding scan line data.offset
- the start of the scan line data in the array.startScanLines
- the first scan line to be scanned.numScanLines
- the number of scan lines.rowStride
- the number of array elements for the destination data. If this
is zero it is assumed to be the same as the scan line length of the image data.IllegalArgumentException
- if the scan line is the wrong type.IndexOutOfBoundsException
- if any of the data is out of bounds for the image
or for the destination array.public static int[] validatePixelBuffer(boolean isGetBuffer, ImageData image, int[] buffer, int offset, int width, int height, int rowStride)
isGetBuffer
- image
- buffer
- offset
- width
- height
- public static void drawScaled(ImageData d, Graphics g, int x, int y, int width, int height, int options)
public static IImage changeColor(IImage src, int from, int mask, int to, PixelBuffer dest)
src
- the image source.from
- the color to look for which is used with the mask.mask
- the mask for the color to look for.to
- the color to change to.dest
- an optional destination PixelBuffer. If this is not null the new image is placed in it and then returned.
It CAN be the same as the src.public static IImage changeBlack(IImage src, int to)
src
- the source image.to
- the rgb color value. The alpha is ignored.public static Picture fillBackground(Drawable d, Color background)
d
- background
- public static Image getCompatibleImagePoints(double widthInPoints, double heightInPoints, ISurface surface, double assumeXdpi, double assumeYdpi) throws IllegalArgumentException
widthInPoints
- the width of the image int points (1/72 of an inch). This must be greater than 0.heightInPoints
- the height of the image int points (1/72 of an inch). This must be greater than 0.assumeXdpi
- as long as this is > 0 and assumeYdpi > 0 then an Image will be returned.assumeYdpi
- as long as this is > 0 and assumeYdpi > 0 then an Image will be returned.IllegalArgumentException
- if the width or height is less than or is zero.public static PixelBuffer toPixelBuffer(PixelBuffer dest, IPointImage pi, double xdpi, double ydpi, int options)
public static ImageData getBestScaledIcon(Iterator availableImageData, int forWidth, int forHeight, int options)
public static PixelBuffer getNontransparentSection(ImageData src, PixelBuffer destBuffer)
public static IImage insetImage(ImageData src, int top, int left, int bottom, int right, boolean nonTransparentAreaOnly)