Package de.gurkenlabs.litiengine.util
Class Imaging
java.lang.Object
de.gurkenlabs.litiengine.util.Imaging
The type Imaging.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageaddShadow(BufferedImage image, int xOffset, int yOffset) Adds a shadow effect by executing the following steps: 1.static BufferedImageapplyAlphaChannel(BufferedImage img, Color color) All pixels that have the specified color are rendered transparent.static booleanareEqual(BufferedImage image1, BufferedImage image2) Checks whether two BufferedImages are equal.static BufferedImageborderAlpha(BufferedImage image, Color strokeColor, boolean borderOnly) Draw a stroke around an image in the given color.static BufferedImagecopy(BufferedImage image) Creates a newBufferedImageinstance from the specified image.static BufferedImagecrop(BufferedImage image, int cropAlignment, int cropVerticlaAlignment, int width, int height) Crops a sub image from the specified image.static BufferedImageflashVisiblePixels(Image image, Color flashColor) All pixels that are not transparent are replaced by a pixel of the specified flashColor.static BufferedImageflipSpritesHorizontally(Spritesheet sprite) Flip the individual sprites in aSpritesheethorizontally and return an image from which a newSpritesheetcan be created.static BufferedImageflipSpritesVertically(Spritesheet sprite) Flip the individual sprites in aSpritesheetvertically and return an image from which a newSpritesheetcan be created.static BufferedImagegetCompatibleImage(int width, int height) Gets an emptyBufferedImagewith the given size.static BufferedImage[][]getSubImages(BufferedImage image, int rows, int columns) Gets a two dimensional grid that contains parts of the specified image.static BufferedImageFlips the specified image horizontally.static booleanisEmpty(BufferedImage image) Checks whether a given BufferedImage only has transparent pixels.static BufferedImagenineSlice(Spritesheet spritesheet, int targetWidth, int targetHeight, float scaleFactor) Generates a 9-slice scaled image from a given spritesheet in the given dimensions.static BufferedImagenineSlice(BufferedImage image, int sliceWidth, int sliceHeight, int targetWidth, int targetHeight, float scaleFactor) Generates a 9-slice scaled image from a given image in the given dimensions.static BufferedImagereplaceColors(BufferedImage bufferedImage, Map<Color, Color> colorMappings) Replace colors in an image according to a Map containing source colors and target colors, then return the result.static BufferedImagerotate(BufferedImage bufferedImage, double radians) Rotate aBufferedImageby a given rotation.static BufferedImagerotate(BufferedImage bufferedImage, Rotation rotation) Rotate a givenBufferedImageby a givenRotation.static BufferedImagescale(BufferedImage image, double factor) Scale buffered image by multiplying its width and height with a given factor.static BufferedImagescale(BufferedImage image, double factor, int interpolation) Scale buffered image by multiplying its width and height with a given factor.static BufferedImagescale(BufferedImage image, int max) Scale buffered image so that the longer edge of the image will be set to a given maximum.static BufferedImagescale(BufferedImage image, int width, int height) Scale buffered image.static BufferedImagescale(BufferedImage image, int width, int height, boolean keepRatio) Scale buffered image.static BufferedImagescale(BufferedImage image, int width, int height, boolean keepRatio, boolean fill) Scale buffered image.static BufferedImagescale(BufferedImage image, int width, int height, int interpolation) Scale buffered image.static BufferedImagescale(BufferedImage image, int width, int height, int interpolation, boolean keepRatio) Scale buffered image.static BufferedImagescale(BufferedImage image, int width, int height, int interpolation, boolean keepRatio, boolean fill) Scale buffered image.static BufferedImageSets the opacity of a given image.static BufferedImagetoBufferedImage(Image img) Converts a givenImageinstance to aBufferedImage.static BufferedImagetoCompatibleImage(BufferedImage image) Creates a compatible buffered image that contains the source image.static BufferedImageFlips the specified image vertically.
-
Field Details
-
CROP_ALIGN_CENTER
public static final int CROP_ALIGN_CENTER- See Also:
-
CROP_ALIGN_LEFT
public static final int CROP_ALIGN_LEFT- See Also:
-
CROP_ALIGN_RIGHT
public static final int CROP_ALIGN_RIGHT- See Also:
-
CROP_VALIGN_BOTTOM
public static final int CROP_VALIGN_BOTTOM- See Also:
-
CROP_VALIGN_CENTER
public static final int CROP_VALIGN_CENTER- See Also:
-
CROP_VALIGN_TOP
public static final int CROP_VALIGN_TOP- See Also:
-
CROP_VALIGN_TOPCENTER
public static final int CROP_VALIGN_TOPCENTER- See Also:
-
-
Method Details
-
addShadow
Adds a shadow effect by executing the following steps: 1. Transform visible pixels to a semi-transparent black 2. Flip the image vertically 3. Scale it down 4. Render original image and shadow on a buffered image- Parameters:
image- the imagexOffset- the x offsetyOffset- the y offset- Returns:
- the buffered image
-
applyAlphaChannel
All pixels that have the specified color are rendered transparent.- Parameters:
img- the imgcolor- the color- Returns:
- the image
-
borderAlpha
Draw a stroke around an image in the given color.- Parameters:
image- the input imagestrokeColor- the stroke colorborderOnly- decide whether only the border of the given image will be drawn- Returns:
- the buffered image with a border drawn around it
-
isEmpty
Checks whether a given BufferedImage only has transparent pixels.- Parameters:
image- the image- Returns:
- true if there are no coloured pixels in the image.
-
areEqual
Checks whether two BufferedImages are equal.- Parameters:
image1- the image 1image2- the image 2- Returns:
- true if the images are equal
-
crop
public static BufferedImage crop(BufferedImage image, int cropAlignment, int cropVerticlaAlignment, int width, int height) Crops a sub image from the specified image.- Parameters:
image- The image to crop the sub-image from.cropAlignment- use the following consts:
cropVerticlaAlignment- use the following consts:
width- The width to crop.height- The height to crop.- Returns:
- The cropped image or the original image if it is smaller than the specified dimensions.
-
flashVisiblePixels
All pixels that are not transparent are replaced by a pixel of the specified flashColor.- Parameters:
image- the imageflashColor- the flash color- Returns:
- the buffered image
-
flipSpritesHorizontally
Flip the individual sprites in aSpritesheethorizontally and return an image from which a newSpritesheetcan be created.- Parameters:
sprite- the spritesheet- Returns:
- a
BufferedImagecontaining the horizontally flipped sprites
-
flipSpritesVertically
Flip the individual sprites in aSpritesheetvertically and return an image from which a newSpritesheetcan be created.- Parameters:
sprite- the spritesheet- Returns:
- a
BufferedImagecontaining the vertically flipped sprites
-
nineSlice
public static BufferedImage nineSlice(BufferedImage image, int sliceWidth, int sliceHeight, int targetWidth, int targetHeight, float scaleFactor) Generates a 9-slice scaled image from a given image in the given dimensions.- Parameters:
image- the input image used for slicing. Will be sliced into 3 rows and 3 columns (@see 9-slice scaling).sliceWidth- the slice width of the input imagesliceHeight- the slice width of the input imagetargetWidth- the target width of the output imagetargetHeight- the target height of the output imagescaleFactor- the factor by which the individual slices will be resized- Returns:
- a new BufferedImage with the scaled slices put together
-
nineSlice
public static BufferedImage nineSlice(Spritesheet spritesheet, int targetWidth, int targetHeight, float scaleFactor) Generates a 9-slice scaled image from a given spritesheet in the given dimensions.- Parameters:
spritesheet- the spritesheet used for slicing. Will be sliced into 3 rows and 3 columns (@see 9-slice scaling).targetWidth- the target width of the output imagetargetHeight- the target height of the output imagescaleFactor- the factor by which the individual slices will be resized- Returns:
- a new BufferedImage with the scaled slices put together
-
copy
Creates a newBufferedImageinstance from the specified image.- Parameters:
image- The image to be copied.- Returns:
- A
BufferedImagethat is a copy of the input image.
-
getCompatibleImage
Gets an emptyBufferedImagewith the given size.- Parameters:
width- the widthheight- the height- Returns:
- an empty
BufferedImagewith the given size
-
getSubImages
Gets a two dimensional grid that contains parts of the specified image. Splits up the specified image into a grid with the defined number of rows and columns.- Parameters:
image- The base image that will be split up.rows- The number of rows.columns- The number or columns.- Returns:
- A two dimensional array with all the sub-images.
-
horizontalFlip
Flips the specified image horizontally.- Parameters:
img- The image to be flipped.- Returns:
- The horizontally flipped image.
-
verticalFlip
Flips the specified image vertically.- Parameters:
img- The image to be flipped.- Returns:
- The vertically flipped image.
-
replaceColors
public static BufferedImage replaceColors(BufferedImage bufferedImage, Map<Color, Color> colorMappings) Replace colors in an image according to a Map containing source colors and target colors, then return the result.- Parameters:
bufferedImage- the original imagecolorMappings- a Map with source colors as keys and target colors as values- Returns:
- a new version of the original image, where the source colors are replaced with the target colors.
-
rotate
Rotate a givenBufferedImageby a givenRotation.- Parameters:
bufferedImage- the input imagerotation- the amount ofRotation- Returns:
- the rotated
BufferedImage
-
rotate
Rotate aBufferedImageby a given rotation.- Parameters:
bufferedImage- the input imageradians- the amount of rotation in radians.- Returns:
- the rotated
BufferedImage
-
scale
Scale buffered image so that the longer edge of the image will be set to a given maximum.- Parameters:
image- the inputBufferedImageto be scaledmax- the maximum length of the longer image edge- Returns:
- the scaled
BufferedImage.
-
scale
Scale buffered image by multiplying its width and height with a given factor. By default,AffineTransformOp.TYPE_NEAREST_NEIGHBORis used for scaling. If you want smooth interpolation, use one of the method overloads with a custom interpolation parameter.- Parameters:
image- the inputBufferedImageto be scaledfactor- the factor by which the image width and height will be multiplied- Returns:
- the scaled
BufferedImage.
-
scale
Scale buffered image by multiplying its width and height with a given factor. This default overload will not generate white space around the scaled image to match the full target dimensions.- Parameters:
image- the inputBufferedImageto be scaledfactor- the factor by which the image width and height will be multipliedinterpolation- the interpolation mode used for scaling. Choose one of the following:- Returns:
- the scaled
BufferedImage.
-
scale
Scale buffered image. The original image ratio will be kept. By default,AffineTransformOp.TYPE_NEAREST_NEIGHBORis used for scaling. If you want smooth interpolation, use one of the method overloads with a custom interpolation parameter. This default overload will not generate white space around the scaled image to match the full target dimensions.- Parameters:
image- the inputBufferedImageto be scaledwidth- the width of the scaled image in pixelsheight- the height of the scaled image in pixels- Returns:
- the scaled
BufferedImage.
-
scale
Scale buffered image. By default,AffineTransformOp.TYPE_NEAREST_NEIGHBORis used for scaling. If you want smooth interpolation, use one of the method overloads with a custom interpolation parameter. This default overload will not generate white space around the scaled image to match the full target dimensions.- Parameters:
image- the inputBufferedImageto be scaledwidth- the width of the scaled image in pixelsheight- the height of the scaled image in pixelskeepRatio- determines whether the original image ratio should be kept while scaling.- Returns:
- the scaled
BufferedImage.
-
scale
public static BufferedImage scale(BufferedImage image, int width, int height, boolean keepRatio, boolean fill) Scale buffered image. By default,AffineTransformOp.TYPE_NEAREST_NEIGHBORis used for scaling. If you want smooth interpolation, use one of the method overloads with a custom interpolation parameter.- Parameters:
image- the inputBufferedImageto be scaledwidth- the width of the scaled image in pixelsheight- the height of the scaled image in pixelskeepRatio- determines whether the original image ratio should be kept while scaling.fill- determines whether the target image should contain the transparent space around the scaled image to fill the full target dimensions.- Returns:
- the scaled
BufferedImage.
-
scale
public static BufferedImage scale(BufferedImage image, int width, int height, int interpolation, boolean keepRatio) Scale buffered image. This default overload will not generate white space around the scaled image to match the full target dimensions.- Parameters:
image- the inputBufferedImageto be scaledwidth- the width of the scaled image in pixelsheight- the height of the scaled image in pixelsinterpolation- the interpolation mode used for scaling. Choose one of the following:keepRatio- determines whether the original image ratio should be kept while scaling.- Returns:
- the scaled
BufferedImage.
-
scale
Scale buffered image. This default overload will keep the original image ratio and not generate white space around the scaled image to match the full target dimensions.- Parameters:
image- the inputBufferedImageto be scaledwidth- the width of the scaled image in pixelsheight- the height of the scaled image in pixelsinterpolation- the interpolation mode used for scaling. Choose one of the following:- Returns:
- the scaled
BufferedImage.
-
scale
public static BufferedImage scale(BufferedImage image, int width, int height, int interpolation, boolean keepRatio, boolean fill) Scale buffered image.- Parameters:
image- the inputBufferedImageto be scaledwidth- the width of the scaled image in pixelsheight- the height of the scaled image in pixelsinterpolation- the interpolation mode used for scaling. Choose one of the following:keepRatio- determines whether the original image ratio should be kept while scaling.fill- determines whether the target image should contain the transparent space around the scaled image to fill the full target dimensions.- Returns:
- the scaled
BufferedImage.
-
setAlpha
Sets the opacity of a given image.- Parameters:
img- the originalImagealpha- the constant alpha to be multiplied with the alpha of the source. alpha must be a floating point number in the inclusive range [0.0, 1.0].- Returns:
- the
BufferedImageproduced by applying the given alpha on the source image
-
toBufferedImage
Converts a givenImageinstance to aBufferedImage.- Parameters:
img- the originalImage- Returns:
- the
BufferedImageproduced from the originalImage
-
toCompatibleImage
Creates a compatible buffered image that contains the source image.- Parameters:
image- the source image- Returns:
- the compatible buffered image
-