public class Simapi
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.awt.Color |
COLOR_TRANSPARENT
Constant to identify a transparent background fill color.
|
static int |
POS_CENTER
Position indicator: Center (default).
|
static int |
POS_DOWN_LEFT
Position indicator: Down left.
|
static int |
POS_DOWN_RIGHT
Position indicator: Down right.
|
static int |
POS_STRAIGHT_DOWN
Position indicator: Straight down.
|
static int |
POS_STRAIGHT_LEFT
Position indicator: Straight left.
|
static int |
POS_STRAIGHT_RIGHT
Position indicator: Straight right.
|
static int |
POS_STRAIGHT_UP
Position indicator: Straight up.
|
static int |
POS_UP_LEFT
Position indicator: Up left.
|
static int |
POS_UP_RIGHT
Position indicator: Up right.
|
static int |
RENDER_MEDIUM
Indicates to use the
MEDIUM render settings. |
static int |
RENDER_QUALITY
Indicates to use the
QUALITY render settings (default). |
static int |
RENDER_QUALITY_BICUBIC
Indicates to use alternative
BICUBIC quality render settings. |
static int |
RENDER_QUALITY_SOFT
Indicates to use alternative
SOFT quality render settings. |
static int |
RENDER_SPEED
Indicates to use the
SPEED render settings. |
static java.lang.String |
TYPE_BMP
Constant to identify the
BMP image type. |
static java.lang.String |
TYPE_GIF
Constant to identify the
GIF image type. |
static java.lang.String |
TYPE_JPEG
Constant to identify the
JPEG image type. |
static java.lang.String |
TYPE_PNG
Constant to identify the
PNG image type. |
static java.lang.String |
TYPE_PNM
Constant to identify the
PNM image type. |
static java.lang.String |
TYPE_TIFF
Constant to identify the
TIFF image type. |
| Constructor and Description |
|---|
Simapi()
Creates a new simapi instance using the default render settings (
RENDER_QUALITY). |
Simapi(RenderSettings renderSettings)
Creates a new simapi instance with the specified render settings.
|
| Modifier and Type | Method and Description |
|---|---|
java.awt.image.BufferedImage |
applyFilter(java.awt.image.BufferedImage image,
java.awt.image.ImageFilter filter)
Applies the given filter to the image.
|
java.awt.Rectangle |
applyFilterDimensions(int width,
int height)
Calculates the image size for an image after all filters returned by
RenderSettings.getImageFilters()
have been applied. |
java.awt.image.BufferedImage |
applyFilters(java.awt.image.BufferedImage image)
Applies all filters returned by
RenderSettings.getImageFilters() to the given image. |
protected java.awt.image.BufferedImage |
createImage(java.awt.image.ColorModel colorModel,
int width,
int height)
Creates a buffered image that has the given dimensions and uses the given color model.
|
java.awt.image.BufferedImage |
crop(java.awt.image.BufferedImage image,
int width,
int height,
int cropPosition)
Crops an image according to the width and height specified.
|
java.awt.image.BufferedImage |
crop(java.awt.image.BufferedImage image,
int x,
int y,
int width,
int height)
Crops a part of the given image from the specified
x,y point to the given width,height. |
java.awt.image.BufferedImage |
crop(java.awt.image.BufferedImage image,
int x,
int y,
int width,
int height,
java.awt.Color backgroundColor)
Crops a part of the given image from the specified
x,y point to the given width,height. |
java.awt.image.BufferedImage |
cropPointToSize(java.awt.image.BufferedImage image,
int x,
int y,
boolean scale,
int targetWidth,
int targetHeight)
Crops a part of the given image around the specified
x,y point
to the dimensions specified in targetWidth,targetHeight. |
java.awt.image.BufferedImage |
cropToSize(java.awt.image.BufferedImage image,
int x,
int y,
int width,
int height,
int targetWidth,
int targetHeight)
Crops a part of the given image from the specified
x,y point to the given width,height,
and then resizes this cropped image to the dimensions specified in targetWidth,targetHeight. |
java.awt.image.BufferedImage |
cropToSize(java.awt.image.BufferedImage image,
int x,
int y,
int width,
int height,
int targetWidth,
int targetHeight,
java.awt.Color backgroundColor)
Crops a part of the given image from the specified
x,y point to the given width,height,
and then resizes this cropped image to the dimensions specified in targetWidth,targetHeight. |
protected static java.awt.image.BufferedImage |
ensureImageIsSystemType(java.awt.image.BufferedImage image,
boolean allowTransparent)
Returns an image that is ensured the be of either
BufferedImage.TYPE_INT_RGB or
BufferedImage.TYPE_INT_ARGB. |
byte[] |
getBytes(java.awt.image.BufferedImage image,
java.lang.String type)
Returns the byte contents of the given image.
|
static byte[] |
getImageBytes(java.awt.image.BufferedImage image,
java.lang.String type)
Returns the byte contents of the given image, based on the QUALITY settings.
|
static java.lang.String |
getImageType(java.lang.String filename)
Returns the image type from the given file name based on the file suffix (extension)
and the available image writers.
|
static java.awt.image.BufferedImage |
read(byte[] source)
Loads an image from a byte array
|
static java.awt.image.BufferedImage |
read(java.io.File source)
Loads an image from a local file.
|
static java.awt.image.BufferedImage |
read(java.io.InputStream source)
Loads an image from an InputStream.
|
static java.awt.image.BufferedImage |
read(java.lang.String source)
Loads an image from a local file whose path is supplied as a String
|
static java.awt.image.BufferedImage |
read(java.net.URL source)
Loads an image from a URL.
|
java.awt.image.BufferedImage |
reduceColors(java.awt.image.BufferedImage image,
int maxColors,
boolean alphaToBitmask)
Reduces the colors in the given image to the given maximum color number.
|
java.awt.image.BufferedImage |
resize(java.awt.image.BufferedImage image,
int width,
int height)
Resizes an image according to the width and height specified.
|
java.awt.image.BufferedImage |
resize(java.awt.image.BufferedImage image,
int width,
int height,
boolean bestfit)
Resizes an image according to the width and height specified,
keeping the aspect ratio if required.
|
java.awt.image.BufferedImage |
resize(java.awt.image.BufferedImage image,
int width,
int height,
boolean bestfit,
boolean blowup)
Resizes an image according to the width and height specified,
keeping the aspect ratio if required.
|
java.awt.image.BufferedImage |
resize(java.awt.image.BufferedImage image,
int width,
int height,
java.awt.Color backgroundColor,
int position)
Resizes the given image to best fit into the given dimensions (only if it does not already
fit in the dimensions), placing the scaled image
at the indicated position on a background with the given color.
|
java.awt.image.BufferedImage |
resize(java.awt.image.BufferedImage image,
int width,
int height,
java.awt.Color backgroundColor,
int position,
boolean blowup)
Resizes the given image to best fit into the given dimensions (only if it does not already
fit in the dimensions), placing the scaled image
at the indicated position on a background with the given color.
|
java.awt.image.BufferedImage |
resize(java.awt.image.BufferedImage image,
int width,
int height,
int position)
Resizes an image according to the width and height specified,
cropping the image along the sides in case the required height and width can not be reached without
changing the apsect ratio of the image.
|
java.awt.image.BufferedImage |
scale(java.awt.image.BufferedImage image,
float scale)
Scales an image according to the given scale factor.
|
java.awt.image.BufferedImage |
scale(java.awt.image.BufferedImage image,
float widthScale,
float heightScale)
Scale the image with different ratios along the width and height.
|
java.awt.image.BufferedImage |
scale(java.awt.image.BufferedImage image,
float widthScale,
float heightScale,
int targetWidth,
int targetHeight)
Scale the image with different ratios along the width and height to the given target dimensions.
|
java.awt.image.BufferedImage |
scale(java.awt.image.BufferedImage image,
int targetWidth,
int targetHeight)
Scale the image to the width and height to the given target dimensions.
|
void |
write(java.awt.image.BufferedImage image,
java.io.File destination,
java.lang.String type)
Writes an image to a local file.
|
protected void |
write(java.awt.image.BufferedImage im,
java.lang.Object output,
java.lang.String formatName)
Writes an image to the given output object, using the the given quality.
|
void |
write(java.awt.image.BufferedImage image,
java.io.OutputStream destination,
java.lang.String type)
Writes an image to an output stream.
|
void |
write(java.awt.image.BufferedImage image,
java.lang.String destination,
java.lang.String type)
Writes an image to a local file.
|
public static final java.awt.Color COLOR_TRANSPARENT
public static final int POS_CENTER
public static final int POS_DOWN_LEFT
public static final int POS_DOWN_RIGHT
public static final int POS_STRAIGHT_DOWN
public static final int POS_STRAIGHT_LEFT
public static final int POS_STRAIGHT_RIGHT
public static final int POS_STRAIGHT_UP
public static final int POS_UP_LEFT
public static final int POS_UP_RIGHT
public static final int RENDER_MEDIUM
MEDIUM render settings.public static final int RENDER_QUALITY
QUALITY render settings (default).public static final int RENDER_QUALITY_BICUBIC
BICUBIC quality render settings.
The difference to RENDER_QUALITY is that bicubic (instead of bilinear)
scaling is used. Also blurring of the image in advance is not applied.
public static final int RENDER_QUALITY_SOFT
SOFT quality render settings.
The difference to RENDER_QUALITY is that the blur factor applied to the image
is higher, resulting in softer images when scaling down.
This is useful for scaling down "hard" images like screen shots, otherwise scaled font letters
may look jagged.
public static final int RENDER_SPEED
SPEED render settings.public static final java.lang.String TYPE_BMP
BMP image type.public static final java.lang.String TYPE_GIF
GIF image type.public static final java.lang.String TYPE_JPEG
JPEG image type.public static final java.lang.String TYPE_PNG
PNG image type.public static final java.lang.String TYPE_PNM
PNM image type.public static final java.lang.String TYPE_TIFF
TIFF image type.public Simapi()
RENDER_QUALITY).*
public Simapi(RenderSettings renderSettings)
renderSettings - the render settings to usepublic static byte[] getImageBytes(java.awt.image.BufferedImage image,
java.lang.String type)
throws java.io.IOException
image - the image to get the byte contents fortype - the type of the image to get the byte contents forjava.io.IOException - in case the image could not be converted to bytespublic static java.lang.String getImageType(java.lang.String filename)
For example, for the file name "alkacon.gif" the type is GIF, for "alkacon.jpeg" is is "JPEG" etc.
In case the input filename has no suffix, or there is no known image writer for the format defined
by the suffix, null is returned.
Any non-null result can be used if an image type input value is required.
filename - the file name to get the type forpublic static java.awt.image.BufferedImage read(byte[] source)
throws java.io.IOException
source - the byte array to read the image fromjava.io.IOException - in case the image could not be loadedpublic static java.awt.image.BufferedImage read(java.io.File source)
throws java.io.IOException
source - the file to read the input image fromjava.io.IOException - in case the image could not be loadedpublic static java.awt.image.BufferedImage read(java.io.InputStream source)
throws java.io.IOException
source - the input stream to read the input image fromjava.io.IOException - in case the image could not be loadedpublic static java.awt.image.BufferedImage read(java.lang.String source)
throws java.io.IOException
source - the path to the local file to read the input image fromjava.io.IOException - in case the image could not be loadedpublic static java.awt.image.BufferedImage read(java.net.URL source)
throws java.io.IOException
source - the URL to read the input image fromjava.io.IOException - in case the image could not be loadedprotected static java.awt.image.BufferedImage ensureImageIsSystemType(java.awt.image.BufferedImage image,
boolean allowTransparent)
BufferedImage.TYPE_INT_RGB or
BufferedImage.TYPE_INT_ARGB.Ensuring the image is of one of the possible return types is done before applying an image filter transformation since if the image is of a different (not native) type, the transformation can take very long and consume a lot of resources.
image - the original imageallowTransparent - if true, transparent (alpha layer) pixels is allowedpublic java.awt.image.BufferedImage applyFilter(java.awt.image.BufferedImage image,
java.awt.image.ImageFilter filter)
image - the image to apply the filter tofilter - the filter to applypublic java.awt.Rectangle applyFilterDimensions(int width,
int height)
RenderSettings.getImageFilters()
have been applied.width - the image widthheight - the image heightpublic java.awt.image.BufferedImage applyFilters(java.awt.image.BufferedImage image)
RenderSettings.getImageFilters() to the given image.image - the image to apply the filters topublic java.awt.image.BufferedImage crop(java.awt.image.BufferedImage image,
int width,
int height,
int cropPosition)
Use the constants etc. to indicate the crop position.POS_CENTER
image - the image to cropwidth - the width of the target imageheight - the height of the target imagecropPosition - the position to crop the image atpublic java.awt.image.BufferedImage crop(java.awt.image.BufferedImage image,
int x,
int y,
int width,
int height)
x,y point to the given width,height.
Should the target image rectangle be outside of the source image, the source image is enlarged and
the transparent color is used for the additional background pixels.
If the image does not support transparent pixels, the transparent replacement color (whit by default)
will be used.image - the image to cropx - the x position where the crop startsy - the y position where the crop startswidth - the width of the cropped target imageheight - the height of the cropped target imagex,y point to the given width,heightcrop(BufferedImage, int, int, int, int, Color)public java.awt.image.BufferedImage crop(java.awt.image.BufferedImage image,
int x,
int y,
int width,
int height,
java.awt.Color backgroundColor)
x,y point to the given width,height.
Should the target image rectangle be outside of the source image, the source image is enlarged and
the given background replace color is used for the additional pixels.image - the image to cropx - the x position where the crop startsy - the y position where the crop startswidth - the width of the cropped target imageheight - the height of the cropped target imagebackgroundColor - the color to use if the background must be enlargedx,y point to the given width,heightcrop(BufferedImage, int, int, int, int)public java.awt.image.BufferedImage cropPointToSize(java.awt.image.BufferedImage image,
int x,
int y,
boolean scale,
int targetWidth,
int targetHeight)
x,y point
to the dimensions specified in targetWidth,targetHeight.In case the target dimensions are larger then the original image, the cropped image part is upscaled to the target size.
In case the target dimensions are smaller, the downScale parameter can be used
to control the crop: if false the the cropped image is taken from the original pixels,
if true then the image is rist downscaled to the target dimensions and then cropped.
The aspect ratio of the target image is not kept.
image - the image to cropx - the x position where the crop startsy - the y position where the crop startsscale - indicates if a large image should be downscaled firsttargetWidth - the width of the target imagetargetHeight - the width of the target imagex,y point
to the given width,height, resized to the dimensions specified in targetWidth,targetHeightcropToSize(BufferedImage, int, int, int, int, int, int, Color)public java.awt.image.BufferedImage cropToSize(java.awt.image.BufferedImage image,
int x,
int y,
int width,
int height,
int targetWidth,
int targetHeight)
x,y point to the given width,height,
and then resizes this cropped image to the dimensions specified in targetWidth,targetHeight.
Should the target image rectangle be outside of the source image, the source image is enlarged and
the transparent color is used for the additional background pixels.
If the image does not support transparent pixels, the transparent replacement color (white by default)
will be used.The aspect ratio of the target image is not kept.
image - the image to cropx - the x position where the crop startsy - the y position where the crop startswidth - the width of the cropped area from the source imageheight - the height of the cropped area from the source imagetargetWidth - the width of the target imagetargetHeight - the width of the target imagex,y point
to the given width,height, resized to the dimensions specified in targetWidth,targetHeightcropToSize(BufferedImage, int, int, int, int, int, int, Color)public java.awt.image.BufferedImage cropToSize(java.awt.image.BufferedImage image,
int x,
int y,
int width,
int height,
int targetWidth,
int targetHeight,
java.awt.Color backgroundColor)
x,y point to the given width,height,
and then resizes this cropped image to the dimensions specified in targetWidth,targetHeight.
Should the target image rectangle be outside of the source image, the source image is enlarged and
the given background replace color is used for the additional pixels.The aspect ratio of the target image is not kept.
image - the image to cropx - the x position where the crop startsy - the y position where the crop startswidth - the width of the cropped area from the source imageheight - the height of the cropped area from the source imagetargetWidth - the width of the target imagetargetHeight - the width of the target imagebackgroundColor - the color to use if the background must be enlargedx,y point
to the given width,height, resized to the dimensions specified in targetWidth,targetHeightcropToSize(BufferedImage, int, int, int, int, int, int)public byte[] getBytes(java.awt.image.BufferedImage image,
java.lang.String type)
throws java.io.IOException
image - the image to get the byte contents fortype - the type of the image to get the byte contents forjava.io.IOException - in case the image could not be converted to bytespublic java.awt.image.BufferedImage reduceColors(java.awt.image.BufferedImage image,
int maxColors,
boolean alphaToBitmask)
image - the image to reduce the colors frommaxColors - the maximum number of allowed colors in the output image (usually 256)alphaToBitmask - indicates if alpha information should be convertedpublic java.awt.image.BufferedImage resize(java.awt.image.BufferedImage image,
int width,
int height)
image - the image to resizewidth - the width of the target imageheight - the height of the target imagepublic java.awt.image.BufferedImage resize(java.awt.image.BufferedImage image,
int width,
int height,
boolean bestfit)
If set to true, the bestfit option will keep the image within the dimensions specified
without losing the aspect ratio.
image - the image to resizewidth - the width of the target imageheight - the height of the target imagebestfit - if true, the aspect ratio of the image will be keptpublic java.awt.image.BufferedImage resize(java.awt.image.BufferedImage image,
int width,
int height,
boolean bestfit,
boolean blowup)
If set to true, the bestfit option will keep the image within the dimensions specified
without losing the aspect ratio.
If set to false, the blowup option will not enlarge an image that is already smaller
then the sepcified target dimensions.
image - the image to resizewidth - the width of the target imageheight - the height of the target imagebestfit - if true, the aspect ratio of the image will be keptblowup - if false, smaller images will not be enlarged to fit in the target dimensionspublic java.awt.image.BufferedImage resize(java.awt.image.BufferedImage image,
int width,
int height,
java.awt.Color backgroundColor,
int position)
image - the image to resizewidth - the width of the target imageheight - the height of the target imagebackgroundColor - the background color to useposition - the position to place the scaled image atpublic java.awt.image.BufferedImage resize(java.awt.image.BufferedImage image,
int width,
int height,
java.awt.Color backgroundColor,
int position,
boolean blowup)
image - the image to resizewidth - the width of the target imageheight - the height of the target imagebackgroundColor - the background color to useposition - the position to place the scaled image atblowup - if false, smaller images will not be enlarged to fit in the target dimensionspublic java.awt.image.BufferedImage resize(java.awt.image.BufferedImage image,
int width,
int height,
int position)
Use the constants etc. to indicate the crop position.POS_CENTER
image - the image to resizewidth - the width of the target imageheight - the height of the target imageposition - the position to place the cropped image atpublic java.awt.image.BufferedImage scale(java.awt.image.BufferedImage image,
float scale)
If the scale is 2.0, the result image will be twice as large as the original, if the scale is 0.5, the result image will be half as large as the original.
image - the image to scalescale - the scale factorpublic java.awt.image.BufferedImage scale(java.awt.image.BufferedImage image,
float widthScale,
float heightScale)
image - the image to scalewidthScale - the scale factor for the widthheightScale - the scale factor for the heightpublic java.awt.image.BufferedImage scale(java.awt.image.BufferedImage image,
float widthScale,
float heightScale,
int targetWidth,
int targetHeight)
Giving both scale factor and target dimensions is required to avoid rounding errors that lead to the "missing line" issue.
image - the image to scalewidthScale - the scale factor for the widthheightScale - the scale factor for the heighttargetWidth - the width of the target imagetargetHeight - the height of the target imagepublic java.awt.image.BufferedImage scale(java.awt.image.BufferedImage image,
int targetWidth,
int targetHeight)
image - the image to scaletargetWidth - the width of the target imagetargetHeight - the height of the target imagepublic void write(java.awt.image.BufferedImage image,
java.io.File destination,
java.lang.String type)
throws java.io.IOException
image - the image to writedestination - the destination filetype - the type of the image to writejava.io.IOException - in case the image could not be writtenpublic void write(java.awt.image.BufferedImage image,
java.io.OutputStream destination,
java.lang.String type)
throws java.io.IOException
image - the image to writedestination - the output stream to write the image totype - the type of the image to writejava.io.IOException - in case the image could not be writtenpublic void write(java.awt.image.BufferedImage image,
java.lang.String destination,
java.lang.String type)
throws java.io.IOException
image - the image to writedestination - the destination file nametype - the type of the image to writejava.io.IOException - in case the image could not be writtenprotected java.awt.image.BufferedImage createImage(java.awt.image.ColorModel colorModel,
int width,
int height)
colorModel - the color model to usewidth - the width of the image to createheight - the height of the image to createprotected void write(java.awt.image.BufferedImage im,
java.lang.Object output,
java.lang.String formatName)
throws java.io.IOException
The quality is used only if the image type supports different qualities.
For example, this it is used when writing JPEG images.
A quality of 0.1 is very poor, 0.75 is ok, 1.0 is maximum.
im - the image to writeoutput - the destination to write the image toformatName - the type of the image to writejava.io.IOException - in case the image could not be written