public final class Effects

  1. Object
  2. Effects
Static utility class useful for simple visual effects that don’t quite fit anywhere else in the core API.

Methods

public static Image reflectionImage(Image source)Takes the given image and appends an effect of reflection below it that is similar to the way elements appear in water beneath them.
public static Image reflectionImage(Image source, float mirrorRatio, int alphaRatio)Takes the given image and appends an effect of reflection below it that is similar to the way elements appear in water beneath them.
public static Image reflectionImage(Image source, float mirrorRatio, int alphaRatio, int spacing)Takes the given image and appends an effect of reflection below it that is similar to the way elements appear in water beneath them.
public static void growShrink(Component c, int duration)Deprecated Grows or shrinks the given component to its new preferred size, this method essentially takes a component whose preferred size has changed and creates a “growing” effect that lasts for the duration.
public static Image verticalPerspective(Image i, float topScaleRatio, float bottomScaleRatio, float verticalShrink)Skews an image in a faux perspective transform on the vertical axis, this is effectively a fast scale algorithm that both shrinks the image vertically and reduces the width
public static Image gaussianBlurImage(Image image, float radius)Create a blur image from the given image.
public static boolean isGaussianBlurSupported()Returns true if gaussian blur is supported on this platform
public static Image dropshadow(Image source, int blurRadius, float opacity, int xDistance, int yDistance)Generates a shadow for the source image and returns a new larger image containing the shadow
public static Image dropshadow(Image source, int blurRadius, float opacity)Generates a shadow for the source image and returns either the shadow itself or the image merged with the shadow.
public static Image squareShadow(int width, int height, int blurRadius, float opacity)Generates a square shadow and returns it

Inherited methods

Method details

reflectionImage

public static Image reflectionImage(Image source)
Takes the given image and appends an effect of reflection below it that is similar to the way elements appear in water beneath them. This method shouldn’t be used when numAlpha is very low.

Parameters

source Image
image to add the reflection effect to

Returns

new image with a reflection effect for the source image

reflectionImage

public static Image reflectionImage(Image source, float mirrorRatio, int alphaRatio)
Takes the given image and appends an effect of reflection below it that is similar to the way elements appear in water beneath them. This method shouldn’t be used when numAlpha is very low.

Parameters

source Image
image to add the reflection effect to
mirrorRatio float
generally less than 1, a mirror ration of 0.5f will create a mirror image half the height of the image, 0.75f will create a 3 quarter height mirror etc.
alphaRatio int
starting point for the alpha value in the mirror, this should be a number between 0 - 255 (recommended larger than 0) indicating the opacity of the closest pixel. For a mirror thats completely opaque use 255. A recommended value would be between 128 to 90.

Returns

new image with a reflection effect for the source image

reflectionImage

public static Image reflectionImage(Image source, float mirrorRatio, int alphaRatio, int spacing)
Takes the given image and appends an effect of reflection below it that is similar to the way elements appear in water beneath them. This method shouldn’t be used when numAlpha is very low.

Parameters

source Image
image to add the reflection effect to
mirrorRatio float
generally less than 1, a mirror ration of 0.5f will create a mirror image half the height of the image, 0.75f will create a 3 quarter height mirror etc.
alphaRatio int
starting point for the alpha value in the mirror, this should be a number between 0 - 255 (recommended larger than 0) indicating the opacity of the closest pixel. For a mirror thats completely opaque use 255. A recommended value would be between 128 to 90.
spacing int
the distance in pixels between the image and its reflection

Returns

new image with a reflection effect for the source image

growShrink

public static void growShrink(Component c, int duration)
Deprecated. use Component.growShrink instead
Grows or shrinks the given component to its new preferred size, this method essentially takes a component whose preferred size has changed and creates a “growing” effect that lasts for the duration. Notice that some components (such as text areas) don’t report proper preferred size untill they are laid out once. Hence the first time around a text area (or container containing a text area) will not produce the expected effect. This can be solved by invoking revalidate before the call to this method only the first time around!

Parameters

c Component
the component to grow/shrink, its size must be different from its preferred size
duration int
the duration in milliseconds for the grow/shrink animation

verticalPerspective

public static Image verticalPerspective(Image i, float topScaleRatio, float bottomScaleRatio, float verticalShrink)
Skews an image in a faux perspective transform on the vertical axis, this is effectively a fast scale algorithm that both shrinks the image vertically and reduces the width

Parameters

i Image
Not documented.
topScaleRatio float
the amount by which the top portion should be scaled where 1.0 means none
bottomScaleRatio float
the amount by which the bottom portion should be scaled where 1.0 means none
verticalShrink float
the scale ratio for the image height where 1.0 means none

Returns

the perspective translated image

gaussianBlurImage

public static Image gaussianBlurImage(Image image, float radius)
Create a blur image from the given image. The algorithm is gaussian blur - https://en.wikipedia.org/wiki/Gaussian_blur

Parameters

image Image
the image to blur
radius float
the radius to be used in the algorithm

isGaussianBlurSupported

public static boolean isGaussianBlurSupported()
Returns true if gaussian blur is supported on this platform

Returns

true if gaussian blur is supported.

dropshadow

public static Image dropshadow(Image source, int blurRadius, float opacity, int xDistance, int yDistance)
Generates a shadow for the source image and returns a new larger image containing the shadow

Parameters

source Image
the source image for whom the shadow should be generated
blurRadius int
a shadow is blurred using a gaussian blur when available, a value of 10 is often satisfactory
opacity float
the opacity of the shadow between 0 - 1 where 1 is completely opaque
xDistance int
the distance on the x axis from the main image body in pixels e.g. a negative value will represent a lightsource from the right (shadow on the left)
yDistance int
the distance on the y axis from the main image body in pixels e.g. a negative value will represent a lightsource from the bottom (shadow on top)

Returns

a new image whose size incorporates x/yDistance

dropshadow

public static Image dropshadow(Image source, int blurRadius, float opacity)
Generates a shadow for the source image and returns either the shadow itself or the image merged with the shadow.

Parameters

source Image
the source image for whom the shadow should be generated
blurRadius int
a shadow is blurred using a gaussian blur when available, a value of 10 is often satisfactory
opacity float
the opacity of the shadow between 0 - 1 where 1 is completely opaque

Returns

an image containing the shadow for source

squareShadow

public static Image squareShadow(int width, int height, int blurRadius, float opacity)
Generates a square shadow and returns it

Parameters

width int
the width of the shadow image
height int
the height of the shadow image
blurRadius int
a shadow is blurred using a gaussian blur when available, a value of 10 is often satisfactory
opacity float
the opacity of the shadow between 0 - 1 where 1 is completely opaque

Returns

an image containing the shadow for source