public class AssetUtil
extends java.lang.Object
BufferedImage
objects and drawing them to
Graphics2D
canvases.Modifier and Type | Class and Description |
---|---|
static class |
AssetUtil.Effect
|
static class |
AssetUtil.FillEffect
A fill, defined by a paint.
|
static class |
AssetUtil.ShadowEffect
An inner or outer shadow.
|
Constructor and Description |
---|
AssetUtil() |
Modifier and Type | Method and Description |
---|---|
static java.awt.image.BufferedImage |
blurredImage(java.awt.image.BufferedImage source,
double radius)
Applies a gaussian blur of the given radius to the given
BufferedImage using a kernel
convolution. |
static void |
drawCenterCrop(java.awt.Graphics2D g,
java.awt.image.BufferedImage source,
java.awt.Rectangle dstRect)
Draws the given
BufferedImage to the canvas, centered and cropped to fill the
bounds defined by the destination rectangle, and with preserved aspect ratio. |
static void |
drawCenterInside(java.awt.Graphics2D g,
java.awt.image.BufferedImage source,
java.awt.Rectangle dstRect)
Draws the given
BufferedImage to the canvas, centered, wholly contained within the
bounds defined by the destination rectangle, and with preserved aspect ratio. |
static void |
drawEffects(java.awt.Graphics2D g,
java.awt.image.BufferedImage source,
int x,
int y,
AssetUtil.Effect[] effects)
Draws the given
BufferedImage to the canvas, at the given coordinates, with the given
AssetUtil.Effect s applied. |
static java.awt.image.BufferedImage |
filledImage(java.awt.image.BufferedImage source,
java.awt.Paint paint)
Fills the given
BufferedImage with a Paint , preserving its alpha channel. |
static java.awt.image.BufferedImage |
invertedAlphaImage(java.awt.image.BufferedImage source)
Inverts the alpha channel of the given
BufferedImage . |
static java.awt.image.BufferedImage |
newArgbBufferedImage(int width,
int height)
Creates a new ARGB
BufferedImage of the given width and height. |
static java.awt.image.BufferedImage |
operatedImage(java.awt.image.BufferedImage source,
java.awt.image.BufferedImageOp op)
Applies a
BufferedImageOp on the given BufferedImage . |
static java.awt.image.BufferedImage |
paddedImage(java.awt.image.BufferedImage source,
int padding)
Pads the given
BufferedImage on all sides by the given padding amount. |
static java.awt.image.BufferedImage |
scaledImage(java.awt.image.BufferedImage source,
int width,
int height)
Smoothly scales the given
BufferedImage to the given width and height using the
Image.SCALE_SMOOTH algorithm (generally bicubic resampling or bilinear filtering). |
static java.awt.Rectangle |
scaleRectangle(java.awt.Rectangle rect,
float scaleFactor)
Scales the given rectangle by the given scale factor.
|
static java.awt.image.BufferedImage |
trimmedImage(java.awt.image.BufferedImage source)
Trims the transparent pixels from the given
BufferedImage (returns a sub-image). |
public static java.awt.Rectangle scaleRectangle(java.awt.Rectangle rect, float scaleFactor)
rect
- The rectangle to scale.scaleFactor
- The factor to scale by.public static java.awt.image.BufferedImage newArgbBufferedImage(int width, int height)
BufferedImage
of the given width and height.width
- The width of the new image.height
- The height of the new image.public static java.awt.image.BufferedImage scaledImage(java.awt.image.BufferedImage source, int width, int height)
BufferedImage
to the given width and height using the
Image.SCALE_SMOOTH
algorithm (generally bicubic resampling or bilinear filtering).source
- The source image.width
- The destination width to scale to.height
- The destination height to scale to.public static java.awt.image.BufferedImage blurredImage(java.awt.image.BufferedImage source, double radius)
BufferedImage
using a kernel
convolution.source
- The source image.radius
- The blur radius, in pixels.public static java.awt.image.BufferedImage invertedAlphaImage(java.awt.image.BufferedImage source)
BufferedImage
. RGB data for the inverted area
are undefined, so it's generally best to fill the resulting image with a color.source
- The source image.public static java.awt.image.BufferedImage operatedImage(java.awt.image.BufferedImage source, java.awt.image.BufferedImageOp op)
BufferedImageOp
on the given BufferedImage
.source
- The source image.op
- The operation to perform.public static java.awt.image.BufferedImage filledImage(java.awt.image.BufferedImage source, java.awt.Paint paint)
BufferedImage
with a Paint
, preserving its alpha channel.source
- The source image.paint
- The paint to fill with.public static java.awt.image.BufferedImage paddedImage(java.awt.image.BufferedImage source, int padding)
BufferedImage
on all sides by the given padding amount.source
- The source image.padding
- The amount to pad on all sides, in pixels.public static java.awt.image.BufferedImage trimmedImage(java.awt.image.BufferedImage source)
BufferedImage
(returns a sub-image).source
- The source image.public static void drawEffects(java.awt.Graphics2D g, java.awt.image.BufferedImage source, int x, int y, AssetUtil.Effect[] effects)
BufferedImage
to the canvas, at the given coordinates, with the given
AssetUtil.Effect
s applied. Note that drawn effects may be outside the bounds of the source
image.g
- The destination canvas.source
- The source image.x
- The x offset at which to draw the image.y
- The y offset at which to draw the image.effects
- The list of effects to apply.public static void drawCenterInside(java.awt.Graphics2D g, java.awt.image.BufferedImage source, java.awt.Rectangle dstRect)
BufferedImage
to the canvas, centered, wholly contained within the
bounds defined by the destination rectangle, and with preserved aspect ratio.g
- The destination canvas.source
- The source image.dstRect
- The destination rectangle in the destination canvas into which to draw the
image.public static void drawCenterCrop(java.awt.Graphics2D g, java.awt.image.BufferedImage source, java.awt.Rectangle dstRect)
BufferedImage
to the canvas, centered and cropped to fill the
bounds defined by the destination rectangle, and with preserved aspect ratio.g
- The destination canvas.source
- The source image.dstRect
- The destination rectangle in the destination canvas into which to draw the
image.