public abstract class GraphicsContext2D extends Object
GraphicsContext2D
use:
public void initializeCanvasContext() { context =GraphicsContext2D
.getOrCreate("test"); } privateGraphicsContext2D
context;
Modifier and Type | Method and Description |
---|---|
abstract void |
arc(double centerX,
double centerY,
double radius,
double startAngle,
double endAngle,
boolean acw)
Adds path elements to the current path to make an arc
which is centered at (
centerX , centerY ) position
with radius starting at
startAngle and ending at endAngle
going in the given direction by anticlockwise. |
abstract void |
arcTo(double x1,
double y1,
double x2,
double y2,
double radius)
Adds segments to the current path
with the given control points and radius,
connected to the previous point by a straight line.
|
abstract void |
beginPath()
Starts a Path.
|
abstract void |
bezierCurveTo(double cp1x,
double cp1y,
double cp2x,
double cp2y,
double x,
double y)
Adds segments to the current path to make a cubic bezier curve.
|
abstract void |
clearRect(double x,
double y,
double width,
double height)
Clears a portion of the canvas with a transparent color value.
|
abstract void |
clip()
Clips using the current path
|
abstract void |
closePath()
Closes the path.
|
abstract Style.LinearGradient |
createLinearGradient(double x0,
double y0,
double x1,
double y1,
List<Style.Stop> stops)
Create a LinearGradient to use in Canvas.
|
abstract Style.Pattern |
createPattern(Image image,
String repeat)
Create an Image Pattern from a source Image and a repeat style.
|
abstract ImageData |
createPixelMap(double x,
double y)
Get a pixel array that you can manipulate, e.g.
|
abstract ImageData |
createPixelMap(double x,
double y,
int[] data)
Get a pixel array that you can manipulate, e.g.
|
abstract ImageData |
createPixelMap(ImageData pixelMap)
Create a new ImageData object with the same dimensions as the object
specified by imageData (this does not copy the image data)
|
abstract Style.RadialGradient |
createRadialGradient(double x0,
double y0,
double r0,
double x1,
double y1,
double r1,
List<Style.Stop> stops)
Create a RadialGradient
|
abstract void |
drawImage(Image image,
double x,
double y)
Draws an image at the given x, y position using the width and height of
the given image.
|
abstract void |
drawImage(Image image,
double x,
double y,
double width,
double height)
Draws an image into the given destination rectangle of the canvas.
|
abstract void |
drawImage(Image image,
double sx,
double sy,
double sw,
double sh,
double dx,
double dy,
double dw,
double dh)
Draws the current source rectangle of the given image to the given
destination rectangle of the Canvas.
|
abstract void |
drawPixelMap(ImageData pixelMap,
double x,
double y)
Render an ImageData Object at the specified position
|
abstract void |
fill()
Fills the path with the current fill paint.
|
abstract void |
fillCircle(float centerX,
float centerY,
float radius)
Fill a circle with a center position of centerX, centerY and the
specified radius.
|
abstract void |
fillPolygon(double[] x_coord,
double[] y_coord,
int vertexCount)
Fills a polygon with the given points using the currently set fill paint.
|
abstract void |
fillRect(double x,
double y,
double width,
double height)
Fills a rectangle using the current fill paint.
|
abstract void |
fillText(String text,
double x,
double y)
Renders the indicated String with current fill.
|
abstract void |
fillText(String text,
double x,
double y,
double maxWidth)
Renders the indicated String with current fill.
|
abstract Dimension |
getDimension(Image img)
Get the Dimension of an Image
|
abstract String |
getFont()
get the current font
|
abstract double |
getGlobalAlpha()
Gets the current global alpha.
|
abstract String |
getGlobalCompositeOperation()
Gets the global blend mode.
|
abstract int |
getHeight()
Get the height of this GraphicsContext2D (which should be the same as the
enclosing canvas height)
|
abstract String |
getLineCap()
Gets the current stroke line cap attribute.
|
abstract String |
getLineJoin()
Gets the current stroke line join attribute.
|
abstract double |
getLineWidth()
Gets the current line width attribute.
|
abstract double |
getMiterLimit()
Gets the current miter limit attribute.
|
static GraphicsContext2D |
getOrCreate(String canvasId)
Looks for the Canvas with the specified canvasID.
|
abstract ImageData |
getSnapshot(double x,
double y,
double width,
double height)
Get the pixels for a region of your GraphicsContext2D
|
abstract String |
getTextAlign()
Gets the current TextAlignment attribute
|
abstract String |
getTextBaseline()
Gets the current Text Baseline attribute.
|
abstract Style.Color |
getWebColor(String webColor)
Convert this String Representation of a Color to a Color Object.
|
abstract int |
getWidth()
Get the width of this GraphicsContext2D (which should be the same as the
enclosing canvas height)
|
abstract boolean |
isPointInPath(double x,
double y)
Returns true if the the given x,y point is inside the path.
|
abstract void |
lineTo(double x,
double y)
Adds segments to the current path to make a line at the given x,y
coordinate.
|
abstract Dimension |
measureText(String text)
Check the length of a text before writing it to the Canvas.
|
abstract Image |
merge(Image a,
Image b)
Merges two images drawing one on top of the other and returning the
result.
|
abstract void |
moveTo(double x,
double y)
Issues a move command for the current path to the given x,y coordinate.
|
abstract void |
quadraticCurveTo(double cpx,
double cpy,
double x,
double y)
Adds segments to the current path to make a quadratic curve.
|
abstract void |
rect(double x,
double y,
double width,
double height)
Clears a portion of the canvas with a transparent color value.
|
abstract void |
restore()
Pops the state off of the stack, setting the following attributes to
their value at the time when that state was pushed onto the stack.
|
abstract void |
rotate(double angle)
Rotates the current transform in degrees.
|
abstract void |
save()
Saves the following attributes onto a stack.
|
abstract void |
scale(double x,
double y)
Scales the current transform by x, y.
|
abstract void |
setFillStyle(Style style)
Sets the fill style.
|
abstract void |
setFont(String font)
Set the Font.
|
abstract void |
setGlobalAlpha(double alpha)
Sets the global alpha of the current state.
|
abstract void |
setGlobalCompositeOperation(String operation)
Sets the global blend mode.
|
abstract void |
setHeight(int height)
set the height of this GraphicsContext2D
|
abstract void |
setLineCap(String style)
Sets the current stroke line cap attribute.
|
abstract void |
setLineJoin(String style)
Sets the current stroke line join attribute.
|
abstract void |
setLineWidth(double width)
Sets the current line width attribute.
|
abstract void |
setMiterLimit(double limit)
Sets the current miter limit attribute.
|
abstract void |
setStrokeStyle(Style style)
sets the Style of the Stroke.
|
abstract void |
setTextAlign(String textAlign)
Defines horizontal text alignment, relative to the text
x origin. |
abstract void |
setTextBaseline(String textbaseline)
Sets the current Text Baseline attribute.
|
abstract void |
setTransform(double mxx,
double myx,
double mxy,
double myy,
double mxt,
double myt)
Concatenates the input with the current transform.
|
abstract void |
setWidth(int width)
Set the width of this GraphicsContext2D
|
abstract void |
stroke()
Strokes the path with the current stroke paint.
|
abstract void |
strokeRect(double x,
double y,
double width,
double height)
Strokes a rectangle using the current stroke paint.
|
abstract void |
strokeText(String text,
double x,
double y)
Renders the indicated String (with no fill)
|
abstract void |
strokeText(String text,
double x,
double y,
double maxWidth)
Renders the indicated String (with no fill)
|
abstract void |
transform(double mxx,
double myx,
double mxy,
double myy,
double mxt,
double myt)
Concatenates the input with the current transform.
|
abstract void |
translate(double x,
double y)
Translates the current transform by x, y.
|
public static GraphicsContext2D getOrCreate(String canvasId)
registered environments
and the first one that returns valid context is returned. In case there
is no valid provider, fallback is made to provider rendering on an
HTML canvas element. Use as:
public void initializeCanvasContext() { context =GraphicsContext2D
.getOrCreate("test"); } privateGraphicsContext2D
context;
canvasId
- The canvasId to look for.public abstract void arc(double centerX, double centerY, double radius, double startAngle, double endAngle, boolean acw)
centerX
, centerY
) position
with radius
starting at
startAngle
and ending at endAngle
going in the given direction by anticlockwise.centerX
- the center x position of the arc.centerY
- the center y position of the arc.startAngle
- the startAngle of the arcradius
- the radius of the arc.endAngle
- the endAngle of the arcacw
- the direction of the arc (anticlockwise)public abstract void arcTo(double x1, double y1, double x2, double y2, double radius)
x1
- the X coordinate of the first point of the arc.y1
- the Y coordinate of the first point of the arc.x2
- the X coordinate of the second point of the arc.y2
- the Y coordinate of the second point of the arc.radius
- the radius of the arc in the range {0.0-positive infinity}.public abstract boolean isPointInPath(double x, double y)
x
- the X coordinate to use for the check.y
- the Y coordinate to use for the check.public abstract void fill()
public abstract void stroke()
stroke()
:
context.setStrokeStyle(context.getWebColor("blue")); context.beginPath(); context.moveTo(10, 10); context.lineTo(10, 20); context.lineTo(20, 20); context.lineTo(20, 10); context.closePath(); context.stroke();
public abstract void beginPath()
beginPath()
and then:
context.setStrokeStyle(context.getWebColor("blue")); context.beginPath(); context.moveTo(10, 10); context.lineTo(10, 20); context.lineTo(20, 20); context.lineTo(20, 10); context.closePath(); context.stroke();
public abstract void closePath()
begining
of the path. To draw a path use:
context.setStrokeStyle(context.getWebColor("blue")); context.beginPath(); context.moveTo(10, 10); context.lineTo(10, 20); context.lineTo(20, 20); context.lineTo(20, 10); context.closePath(); context.stroke();
public abstract void clip()
public abstract void moveTo(double x, double y)
context.setStrokeStyle(context.getWebColor("blue")); context.beginPath(); context.moveTo(10, 10); context.lineTo(10, 20); context.lineTo(20, 20); context.lineTo(20, 10); context.closePath(); context.stroke();
x
- the X position for the move to command.y
- the Y position for the move to command.public abstract void lineTo(double x, double y)
context.setStrokeStyle(context.getWebColor("blue")); context.beginPath(); context.moveTo(10, 10); context.lineTo(10, 20); context.lineTo(20, 20); context.lineTo(20, 10); context.closePath(); context.stroke();
x
- the X coordinate of the ending point of the line.y
- the Y coordinate of the ending point of the line.public abstract void quadraticCurveTo(double cpx, double cpy, double x, double y)
cpx
- the X coordinate of the control pointcpy
- the Y coordinate of the control pointx
- the X coordinate of the end pointy
- the Y coordinate of the end pointpublic abstract void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)
cp1x
- the X coordinate of first bezier control point.cp1y
- the Y coordinate of the first bezier control point.cp2x
- the X coordinate of the second bezier control point.cp2y
- the Y coordinate of the second bezier control point.x
- the X coordinate of the end point.y
- the Y coordinate of the end point.public abstract void fillRect(double x, double y, double width, double height)
x
- the X position of the upper left corner of the rectangle.y
- the Y position of the upper left corner of the rectangle.width
- the width of the rectangle.height
- the height of the rectangle.public abstract void strokeRect(double x, double y, double width, double height)
x
- the X position of the upper left corner of the rectangle.y
- the Y position of the upper left corner of the rectangle.width
- the width of the rectangle.height
- the height of the rectangle.public abstract void clearRect(double x, double y, double width, double height)
x
- X position of the upper left corner of the rectangle.y
- Y position of the upper left corner of the rectangle.width
- width of the rectangle.height
- height of the rectangle.public abstract void rect(double x, double y, double width, double height)
x
- X position of the upper left corner of the rectangle.y
- Y position of the upper left corner of the rectangle.width
- width of the rectangle.height
- height of the rectangle.public abstract void save()
public abstract void restore()
public abstract void rotate(double angle)
angle
- value in degrees to rotate the current transform.public abstract void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt)
mxx
- - the X coordinate scaling element of the 3x4 matrixmyx
- - the Y coordinate shearing element of the 3x4 matrixmxy
- - the X coordinate shearing element of the 3x4 matrixmyy
- - the Y coordinate scaling element of the 3x4 matrixmxt
- - the X coordinate translation element of the 3x4 matrixmyt
- - the Y coordinate translation element of the 3x4 matrixpublic abstract void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt)
mxx
- - the X coordinate scaling element of the 3x4 matrixmyx
- - the Y coordinate shearing element of the 3x4 matrixmxy
- - the X coordinate shearing element of the 3x4 matrixmyy
- - the Y coordinate scaling element of the 3x4 matrixmxt
- - the X coordinate translation element of the 3x4 matrixmyt
- - the Y coordinate translation element of the 3x4 matrixpublic abstract void translate(double x, double y)
x
- value to translate along the x axis.y
- value to translate along the y axis.public abstract void scale(double x, double y)
x
- value to scale in the x axis.y
- value to scale in the y axis.public abstract void drawImage(Image image, double x, double y)
image
- the image to be drawn.x
- the X coordinate on the destination for the upper left of the
image.y
- the Y coordinate on the destination for the upper left of the
image.public abstract void drawImage(Image image, double x, double y, double width, double height)
image
- the image to be drawn.x
- the X coordinate on the destination for the upper left of the
image.y
- the Y coordinate on the destination for the upper left of the
image.width
- the width of the destination rectangle.height
- the height of the destination rectangle.public abstract void drawImage(Image image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)
image
- the image to be drawn.sx
- the source rectangle's X coordinate position.sy
- the source rectangle's Y coordinate position.sw
- the source rectangle's width.sh
- the source rectangle's height.dx
- the destination rectangle's X coordinate position.dy
- the destination rectangle's Y coordinate position.dw
- the destination rectangle's width.dh
- the destination rectangle's height.public abstract Image merge(Image a, Image b)
a
- the lower Imageb
- the upper Imagepublic abstract String getLineCap()
public abstract void setLineCap(String style)
style
- a value of butt,round,square.public abstract String getLineJoin()
public abstract void setLineJoin(String style)
style
- a value of miter, bevel, or round.public abstract double getLineWidth()
public abstract void setLineWidth(double width)
width
- value between 0 and infinity, with any other value being
ignored and leaving the value unchanged.public abstract double getMiterLimit()
public abstract void setMiterLimit(double limit)
limit
- miter limit value between 0 and positive infinity with any
other value being ignored and leaving the value unchanged.public abstract void setFillStyle(Style style)
style
- the desired fill stylepublic abstract String getFont()
public abstract void setFont(String font)
font
- the desired font as a Stringpublic abstract void setStrokeStyle(Style style)
style
- the style to usepublic abstract String getTextAlign()
public abstract void setTextAlign(String textAlign)
x
origin.
Let horizontal bounds represent the logical width of a single line of text. Where each line of text has a separate horizontal bounds.
Then TextAlignment is specified as:
x
.
x
.
x
.
Note: Canvas does not support line wrapping, therefore the text alignment Justify is identical to left aligned text.
textAlign
- with values of left, center, right.public abstract String getTextBaseline()
public abstract void setTextBaseline(String textbaseline)
textbaseline
- with values of top, center, baseline, or bottompublic abstract void fillText(String text, double x, double y)
text
- the text to strokex
- x coordinate of start positiony
- y coordinate of start positionpublic abstract void fillText(String text, double x, double y, double maxWidth)
text
- the text to strokex
- x coordinate of start positiony
- y coordinate of start positionmaxWidth
- maximum width of textpublic abstract Dimension measureText(String text)
text
- the text to measurepublic abstract void strokeText(String text, double x, double y)
text
- the text to strokex
- x coordinate of start positiony
- y coordinate of start positionpublic abstract void strokeText(String text, double x, double y, double maxWidth)
text
- the text to strokex
- x coordinate of start positiony
- y coordinate of start positionmaxWidth
- maximum width of textpublic abstract ImageData createPixelMap(double x, double y)
x
- widthy
- heightpublic abstract ImageData createPixelMap(double x, double y, int[] data)
x
- widthy
- heightdata
- initial datapublic abstract ImageData createPixelMap(ImageData pixelMap)
pixelMap
- the ImageData to copy the Dimensions frompublic abstract ImageData getSnapshot(double x, double y, double width, double height)
x
- start x coordinatey
- start y coordinatewidth
- widthheight
- heightpublic abstract void drawPixelMap(ImageData pixelMap, double x, double y)
pixelMap
- the Pixel arrayx
- start x coordinatey
- start y coordinatepublic abstract void setGlobalAlpha(double alpha)
alpha
- value in the range 0.0-1.0
. The value is clamped if
it is out of range.public abstract double getGlobalAlpha()
public abstract void setGlobalCompositeOperation(String operation)
operation
- the BlendMode that will be set.public abstract String getGlobalCompositeOperation()
public abstract Style.LinearGradient createLinearGradient(double x0, double y0, double x1, double y1, List<Style.Stop> stops)
x0
- x coordinate of start pointy0
- y coordinate of start pointx1
- x coordinate of end pointy1
- y coordinate of end pointstops
- The Stop(s) definig this Gradientpublic abstract Style.Pattern createPattern(Image image, String repeat)
image
- the Imagerepeat
- the repeat stylepublic abstract Style.RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1, List<Style.Stop> stops)
x0
- x Coordinate of starting circley0
- y Coordinate of starting circler0
- radius of starting circlex1
- x coordinate of ending circley1
- y coordinate of ending circler1
- radius of ending circlestops
- the Stops defining this Gradientpublic abstract Style.Color getWebColor(String webColor)
webColor
- the String describing the color, e.g. #ff0000 for red.public abstract int getHeight()
public abstract int getWidth()
public abstract void fillCircle(float centerX, float centerY, float radius)
centerX
- center x coordinatecenterY
- center y coordinateradius
- the radiuspublic abstract void fillPolygon(double[] x_coord, double[] y_coord, int vertexCount)
x_coord
- array containing the x coordinates of the polygon's
points.y_coord
- array containing the y coordinates of the polygon's
points.vertexCount
- the number of points that make the polygon.public abstract Dimension getDimension(Image img)
img
- the Image to measurepublic abstract void setWidth(int width)
width
- target width for this GraphicsContext2Dpublic abstract void setHeight(int height)
height
- target height for this GraphicsContext2DCopyright © 2018. All Rights Reserved.