Class TransformPainter
- java.lang.Object
-
- ej.drawing.TransformPainter
-
public class TransformPainter extends Object
TheTransformPainterclass offers a set of static methods to render elements (image, renderable character) with a transformation.The transformation (rotate, scale etc.) is applied during the drawing: the source element is not updated (for instance the source image is not rotated: this is its rendering on the graphics context which is rotated).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTransformPainter.FlipSpecify the flip to apply when drawing an image.
-
Constructor Summary
Constructors Constructor Description TransformPainter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddrawDeformedImage(GraphicsContext gc, Image image, int x, int y, int[] xys)Draws a deformed image at the given anchor top-left point.
The deformed image is identified by its four corner points.static voiddrawFlippedImage(GraphicsContext gc, Image image, int x, int y, TransformPainter.Flip flip)Draws the image in the graphics context at given anchor top-left position, using the given flip.static voiddrawFlippedImage(GraphicsContext gc, Image image, int x, int y, TransformPainter.Flip flip, int alpha)Draws the image in the graphics context at given anchor top-left position, using the given flip and opacity level.static voiddrawRotatedCharBilinear(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle)Draws the character applying the given rotation.static voiddrawRotatedCharBilinear(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle, int alpha)Draws the character applying the given rotation and opacicity level.static voiddrawRotatedCharNearestNeighbor(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle)Draws the character applying the given rotation.static voiddrawRotatedCharNearestNeighbor(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle, int alpha)Draws the character applying the given rotation and opacity level.static voiddrawRotatedImageBilinear(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle)Draws the image applying the given rotation.static voiddrawRotatedImageBilinear(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle, int alpha)Draws the image applying the given rotation fixing the opacity level.static voiddrawRotatedImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle)Draws the image applying the given rotation.static voiddrawRotatedImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle, int alpha)Draws the image applying the given rotation and opacity level.static voiddrawScaledCharBilinear(GraphicsContext gc, char character, Font font, int x, int y, float factorX, float factorY)Draws the character in the graphics context at given anchor top-left position and using the given scaling factor.static voiddrawScaledImageBilinear(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY)Draws the image in the graphics context at given anchor top-left position and using the given scaling factor.static voiddrawScaledImageBilinear(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY, int alpha)Draws the image in the graphics context at given anchor top-left position and using the given scaling factor and opacity level.static voiddrawScaledImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY)Draws the image in the graphics context at given anchor top-left position and using the given scaling factor.static voiddrawScaledImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY, int alpha)Draws the image in the graphics context at given anchor top-left position and using the given scaling factor and opacity level.static voiddrawScaledRenderableStringBilinear(GraphicsContext gc, RenderableString string, int x, int y, float factorX, float factorY)Draws the renderable string in the graphics context at given anchor top-left position and using the given scaling factor.static voiddrawScaledStringBilinear(GraphicsContext gc, String string, Font font, int x, int y, float factorX, float factorY)Draws the string in the graphics context at given anchor top-left position and using the given scaling factor.static voiddrawScaledSubstringBilinear(GraphicsContext gc, String string, int offset, int length, Font font, int x, int y, float factorX, float factorY)Draws the substring in the graphics context at given anchor top-left position and using the given scaling factor.
-
-
-
Method Detail
-
drawFlippedImage
public static void drawFlippedImage(GraphicsContext gc, Image image, int x, int y, TransformPainter.Flip flip)
Draws the image in the graphics context at given anchor top-left position, using the given flip.Equivalent to calling
drawFlippedImage(GraphicsContext, Image, int, int, Flip, int)withGraphicsContext.OPAQUEas alpha.- Parameters:
gc- the graphics context where to render the drawing.image- the image to drawx- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointflip- the flip to apply.
-
drawFlippedImage
public static void drawFlippedImage(GraphicsContext gc, Image image, int x, int y, TransformPainter.Flip flip, int alpha)
Draws the image in the graphics context at given anchor top-left position, using the given flip and opacity level.In addition with
drawFlippedImage(GraphicsContext, Image, int, int, Flip), this method allows to specify the global opacity value to apply during the image rendering.- Parameters:
gc- the graphics context where to render the drawing.image- the image to drawx- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointflip- the flip to apply.alpha- the global opacity rendering value.- Throws:
IllegalArgumentException- if the given alpha is not a value betweenGraphicsContext.TRANSPARENTandGraphicsContext.OPAQUE.
-
drawDeformedImage
public static void drawDeformedImage(GraphicsContext gc, Image image, int x, int y, int[] xys)
Draws a deformed image at the given anchor top-left point.
The deformed image is identified by its four corner points. These points are defined by the array of integer coordinates and they must respect the following order: first is the top-left corner, second is the top-right, third is the bottom-right and fourth is the bottom-left.
Examples with img an image and imgWidth and imgHeight its size.
- To draw normal img, the array should be : {0, 0, imgWidth-1, 0, imgWidth-1, imgHeight-1, 0, imgHeight-1}.
- To draw img with a rotation clockwise by 90 degrees, the array should be : {imgHeight-1, 0, imgHeight-1, imgWidth-1, 0, imgWidth-1, 0, 0}.
- To draw img mirrored about the vertical axis, the array should be : {0, 0, -(imgWidth-1), 0, -(imgWidth-1), -(imgHeight-1), 0, -(imgHeight-1)}.
- To draw img with a double scale, the array should be : {0, 0, (imgWidth-1)*2, 0, (imgWidth-1)*2, (imgHeight-1)*2, 0, (imgHeight-1)*2}.
- Parameters:
gc- the graphics context where to render the drawing.image- the image to drawx- the x coordinate of the anchor top-left pointy- the y coordinate of the anchor top-left pointxys- the array of coordinates : x1,y1,x2,y2,x3,y3,x4,y4.- Throws:
IllegalArgumentException- if the @{code xys} length is different than 2*4.
-
drawRotatedImageBilinear
public static void drawRotatedImageBilinear(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle)
Draws the image applying the given rotation. This method uses thebilinearalgorithm to render the content. This algorithm performs better rendering thannearest neighboralgorithm but it is slower to apply.The rotation is specified by the center and the angle. The reference point is the graphical object top-left corner. The rotation point is relative to the current translation of the graphics context where the graphical object will be drawn.
To rotate an image on itself, use the following lines:
int rx = x + image.getWidth() / 2;
int ry = y + image.getHeight() / 2;
TransformPainter.drawRotatedImageBilinear(gc, image, x, y, rx, ry, 78);
To rotate an image around a circle, use the following lines:
for (int i = 0; i < 360; i += 45) {
TransformPainter.drawRotatedImageBilinear(gc, image, rx - diameter / 2, ry - diameter / 2, rx, ry, i);
}
Equivalent to calling
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float, int)withGraphicsContext.OPAQUEas alpha.- Parameters:
gc- the graphics context where to render the drawing.image- the image to draw.x- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointrx- the rotation center X coordinate.ry- the rotation center Y coordinate.angle- the rotation angle.- See Also:
drawRotatedImageNearestNeighbor(GraphicsContext, Image, int, int, int, int, float)
-
drawRotatedImageBilinear
public static void drawRotatedImageBilinear(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle, int alpha)
Draws the image applying the given rotation fixing the opacity level. This method uses thebilinearalgorithm to render the content. This algorithm performs better rendering thannearest neighboralgorithm but it is slower to apply.Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float).In addition with
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float), this method allows to specify the global opacity value to apply during the image rendering.- Parameters:
gc- the graphics context where to render the drawing.image- the image to draw.x- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointrx- the rotation center X coordinate.ry- the rotation center Y coordinate.angle- the rotation angle.alpha- the global opacity rendering value.- Throws:
IllegalArgumentException- if the given alpha is not a value betweenGraphicsContext.TRANSPARENTandGraphicsContext.OPAQUE.- See Also:
drawRotatedImageNearestNeighbor(GraphicsContext, Image, int, int, int, int, float, int)
-
drawRotatedImageNearestNeighbor
public static void drawRotatedImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle)
Draws the image applying the given rotation. This method uses thenearest neighboralgorithm to render the content. This algorithm is faster thanbilinearalgorithm but its rendering is more simple.Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float).Equivalent to calling
drawRotatedImageNearestNeighbor(GraphicsContext, Image, int, int, int, int, float, int)withGraphicsContext.OPAQUEas alpha.- Parameters:
gc- the graphics context where render the drawing.image- the image to draw.x- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointrx- the rotation center X coordinate.ry- the rotation center Y coordinate.angle- the rotation angle.- See Also:
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float)
-
drawRotatedImageNearestNeighbor
public static void drawRotatedImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, int rx, int ry, float angle, int alpha)
Draws the image applying the given rotation and opacity level. This method uses thenearest neighboralgorithm to render the content. This algorithm is faster thanbilinearalgorithm but its rendering is more simple.Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float).In addition with
drawRotatedImageNearestNeighbor(GraphicsContext, Image, int, int, int, int, float), this method allows to specify the global opacity value to apply during the image rendering.- Parameters:
gc- the graphics context where render the drawing.image- the image to draw.x- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointrx- the rotation center X coordinate.ry- the rotation center Y coordinate.angle- the rotation angle.alpha- the global opacity rendering value.- Throws:
IllegalArgumentException- if the given alpha is not a value betweenGraphicsContext.TRANSPARENTandGraphicsContext.OPAQUE.- See Also:
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float, int)
-
drawRotatedCharBilinear
public static void drawRotatedCharBilinear(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle)
Draws the character applying the given rotation. This method uses thebilinearalgorithm to render the content. This algorithm performs better rendering thannearest neighboralgorithm but it is slower to apply.This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float).Equivalent to calling
drawRotatedCharBilinear(GraphicsContext, Font, char, int, int, int, int, float, int)withGraphicsContext.OPAQUEas alpha.- Parameters:
gc- the graphics context where to render the drawing.font- the font to use.c- the character to draw.x- the x coordinate of the character reference anchor top-left pointy- the y coordinate of the character reference anchor top-left pointrx- the rotation center X coordinate.ry- the rotation center Y coordinate.angle- the rotation angle.- See Also:
drawRotatedCharNearestNeighbor(GraphicsContext, Font, char, int, int, int, int, float)
-
drawRotatedCharBilinear
public static void drawRotatedCharBilinear(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle, int alpha)
Draws the character applying the given rotation and opacicity level. This method uses thebilinearalgorithm to render the content. This algorithm performs better rendering thannearest neighboralgorithm but it is slower to apply.This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float).In addition with
drawRotatedCharBilinear(GraphicsContext, Font, char, int, int, int, int, float), this method allows to specify the global opacity value to apply during the image rendering.- Parameters:
gc- the graphics context where to render the drawing.font- the font to use.c- the character to draw.x- the x coordinate of the character reference anchor top-left pointy- the y coordinate of the character reference anchor top-left pointrx- the rotation center X coordinate.ry- the rotation center Y coordinate.angle- the rotation angle.alpha- the global opacity rendering value.- Throws:
IllegalArgumentException- if the given alpha is not a value betweenGraphicsContext.TRANSPARENTandGraphicsContext.OPAQUE.- See Also:
drawRotatedCharNearestNeighbor(GraphicsContext, Font, char, int, int, int, int, float, int)
-
drawRotatedCharNearestNeighbor
public static void drawRotatedCharNearestNeighbor(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle)
Draws the character applying the given rotation. This method uses thenearest neighboralgorithm to render the content. This algorithm is faster thanbilinearalgorithm but its rendering is more simple.This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float).Equivalent to calling
drawRotatedCharNearestNeighbor(GraphicsContext, Font, char, int, int, int, int, float, int)withGraphicsContext.OPAQUEas alpha.- Parameters:
gc- the graphics context where render the drawing.font- the font to use.c- the character to draw.x- the x coordinate of the character reference anchor top-left pointy- the y coordinate of the character reference anchor top-left pointrx- the rotation center X coordinate.ry- the rotation center Y coordinate.angle- the rotation angle.- See Also:
drawRotatedCharBilinear(GraphicsContext, Font, char, int, int, int, int, float)
-
drawRotatedCharNearestNeighbor
public static void drawRotatedCharNearestNeighbor(GraphicsContext gc, Font font, char c, int x, int y, int rx, int ry, float angle, int alpha)
Draws the character applying the given rotation and opacity level. This method uses thenearest neighboralgorithm to render the content. This algorithm is faster thanbilinearalgorithm but its rendering is more simple.This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
Some rotation samples are described in method comment
drawRotatedImageBilinear(GraphicsContext, Image, int, int, int, int, float).In addition with
drawRotatedCharNearestNeighbor(GraphicsContext, Font, char, int, int, int, int, float), this method allows to specify the global opacity value to apply during the image rendering.- Parameters:
gc- the graphics context where render the drawing.font- the font to use.c- the character to draw.x- the x coordinate of the character reference anchor top-left pointy- the y coordinate of the character reference anchor top-left pointrx- the rotation center X coordinate.ry- the rotation center Y coordinate.angle- the rotation angle.alpha- the global opacity rendering value.- Throws:
IllegalArgumentException- if the given alpha is not a value betweenGraphicsContext.TRANSPARENTandGraphicsContext.OPAQUE.- See Also:
drawRotatedCharBilinear(GraphicsContext, Font, char, int, int, int, int, float, int)
-
drawScaledImageBilinear
public static void drawScaledImageBilinear(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY)
Draws the image in the graphics context at given anchor top-left position and using the given scaling factor. This method uses thebilinearalgorithm to render the image. This algorithm performs better rendering thannearest neighboralgorithm but it is slower to apply.Equivalent to calling
drawScaledImageBilinear(GraphicsContext, Image, int, int, float, float, int)withGraphicsContext.OPAQUEas alpha.- Parameters:
gc- the graphics context where to render the drawing.image- the image to drawx- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointfactorX- the scaling X factor.factorY- the scaling Y factor.- Throws:
IllegalArgumentException- if a factor is lower than to zero.
-
drawScaledImageBilinear
public static void drawScaledImageBilinear(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY, int alpha)
Draws the image in the graphics context at given anchor top-left position and using the given scaling factor and opacity level. This method uses thebilinearalgorithm to render the image. This algorithm performs better rendering thannearest neighboralgorithm but it is slower to apply.In addition with
drawScaledImageBilinear(GraphicsContext, Image, int, int, float, float), this method allows to specify the global opacity value to apply during the image rendering.- Parameters:
gc- the graphics context where to render the drawing.image- the image to drawx- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointfactorX- the scaling X factor.factorY- the scaling Y factor.alpha- the global opacity rendering value.- Throws:
IllegalArgumentException- if the given alpha is not a value betweenGraphicsContext.TRANSPARENTandGraphicsContext.OPAQUEor if a factor is lower than to zero.
-
drawScaledImageNearestNeighbor
public static void drawScaledImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY)
Draws the image in the graphics context at given anchor top-left position and using the given scaling factor. This method uses thenearest neighboralgorithm to render the image. This algorithm is faster thanbilinearalgorithm but its rendering is more simple.Equivalent to calling
drawScaledImageNearestNeighbor(GraphicsContext, Image, int, int, float, float, int)withGraphicsContext.OPAQUEas alpha.- Parameters:
gc- the graphics context where to render the drawing.image- the image to drawx- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointfactorX- the scaling X factor.factorY- the scaling Y factor.- Throws:
IllegalArgumentException- if a factor is lower than to zero.
-
drawScaledImageNearestNeighbor
public static void drawScaledImageNearestNeighbor(GraphicsContext gc, Image image, int x, int y, float factorX, float factorY, int alpha)
Draws the image in the graphics context at given anchor top-left position and using the given scaling factor and opacity level. This method uses thenearest neighboralgorithm to render the image. This algorithm is faster thanbilinearalgorithm but its rendering is more simple.In addition with
drawScaledImageNearestNeighbor(GraphicsContext, Image, int, int, float, float), this method allows to specify the global opacity value to apply during the image rendering.- Parameters:
gc- the graphics context where to render the drawing.image- the image to drawx- the x coordinate of the image reference anchor top-left pointy- the y coordinate of the image reference anchor top-left pointfactorX- the scaling X factor.factorY- the scaling Y factor.alpha- the global opacity rendering value.- Throws:
IllegalArgumentException- if the given alpha is not a value betweenGraphicsContext.TRANSPARENTandGraphicsContext.OPAQUEor if a factor is lower than to zero.
-
drawScaledCharBilinear
public static void drawScaledCharBilinear(GraphicsContext gc, char character, Font font, int x, int y, float factorX, float factorY)
Draws the character in the graphics context at given anchor top-left position and using the given scaling factor. This method uses thebilinearalgorithm to render the character.This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").
- Parameters:
gc- the graphics context where to render the drawing.character- the character to drawfont- the font to use.x- the x coordinate of the character reference anchor top-left pointy- the y coordinate of the character reference anchor top-left pointfactorX- the scaling X factor.factorY- the scaling Y factor.- Throws:
IllegalArgumentException- if a factor is lower than to zero.
-
drawScaledStringBilinear
public static void drawScaledStringBilinear(GraphicsContext gc, String string, Font font, int x, int y, float factorX, float factorY)
Draws the string in the graphics context at given anchor top-left position and using the given scaling factor. This method uses thebilinearalgorithm to render the string.- Parameters:
gc- the graphics context where to render the drawing.string- the string to drawfont- the font to use.x- the x coordinate of the character reference anchor top-left pointy- the y coordinate of the character reference anchor top-left pointfactorX- the scaling X factor.factorY- the scaling Y factor.- Throws:
IllegalArgumentException- if a factor is lower than to zero.
-
drawScaledSubstringBilinear
public static void drawScaledSubstringBilinear(GraphicsContext gc, String string, int offset, int length, Font font, int x, int y, float factorX, float factorY)
Draws the substring in the graphics context at given anchor top-left position and using the given scaling factor. This method uses thebilinearalgorithm to render the string.- Parameters:
gc- the graphics context where to render the drawing.string- the string to drawoffset- the index of the first character of the string.length- the number of characters of the string.font- the font to use.x- the x coordinate of the character reference anchor top-left pointy- the y coordinate of the character reference anchor top-left pointfactorX- the scaling X factor.factorY- the scaling Y factor.- Throws:
IllegalArgumentException- if a factor is lower than to zero.StringIndexOutOfBoundsException- if the given offset and length do not specify a valid range within the given string.
-
drawScaledRenderableStringBilinear
public static void drawScaledRenderableStringBilinear(GraphicsContext gc, RenderableString string, int x, int y, float factorX, float factorY)
Draws the renderable string in the graphics context at given anchor top-left position and using the given scaling factor. This method uses thebilinearalgorithm to render the renderable string.- Parameters:
gc- the graphics context where to render the drawing.string- the renderable string to drawx- the x coordinate of the character reference anchor top-left pointy- the y coordinate of the character reference anchor top-left pointfactorX- the scaling X factor.factorY- the scaling Y factor.- Throws:
IllegalArgumentException- if a factor is lower than to zero.
-
-