public final class GraphicsContext extends Object
Canvas
using a buffer.
Each call pushes the necessary parameters onto the buffer
where they will be later rendered onto the image of the Canvas
node
by the rendering thread at the end of a pulse.
A Canvas
only contains one GraphicsContext
, and only one buffer.
If it is not attached to any scene, then it can be modified by any thread,
as long as it is only used from one thread at a time. Once a Canvas
node is attached to a scene, it must be modified on the JavaFX Application
Thread.
Calling any method on the GraphicsContext
is considered modifying
its corresponding Canvas
and is subject to the same threading
rules.
A GraphicsContext
also manages a stack of state objects that can
be saved or restored at anytime.
The GraphicsContext
maintains the following rendering attributes
which affect various subsets of the rendering methods:
Attribute | Save/Restore? | Default value | Description |
---|---|---|---|
Common Rendering Attributes | |||
Clip |
Yes | No clipping | An anti-aliased intersection of various clip paths to which rendering is restricted. |
Global Alpha |
Yes | 1.0 |
An opacity value that controls the visibility or fading of each rendering operation. |
Global Blend Mode |
Yes | SRC_OVER |
A BlendMode enum value that controls how pixels from each rendering
operation are composited into the existing image.
|
Transform |
Yes | Identity |
A 3x2 2D affine transformation matrix that controls how coordinates are mapped onto the logical pixels of the canvas image. |
Effect |
Yes | null |
An Effect applied individually to each rendering operation.
|
Fill Attributes | |||
Fill Paint |
Yes | BLACK |
The Paint to be applied to the interior of shapes in a
fill operation.
|
Stroke Attributes | |||
Stroke Paint |
Yes | BLACK |
The Paint to be applied to the boundary of shapes in a
stroke operation.
|
Line Width |
Yes | 1.0 |
The width of the stroke applied to the boundary of shapes in a stroke operation. |
Line Cap |
Yes | SQUARE |
The style of the end caps applied to the beginnings and ends of each dash and/or subpath in a stroke operation. |
Line Join |
Yes | MITER |
The style of the joins applied between individual segments in the boundary paths of shapes in a stroke operation. |
Miter Limit |
Yes | 10.0 |
The ratio limit of how far a MITER line join
may extend in the direction of a sharp corner between segments in the
boundary path of a shape, relative to the line width, before it is truncated
to a BEVEL join in a stroke operation.
|
Dashes |
Yes | null |
The array of dash lengths to be applied to the segments in the boundary of shapes in a stroke operation. |
Dash Offset |
Yes | 0.0 |
The distance offset into the array of dash lengths at which to start the dashing of the segments in the boundary of shapes in a stroke operation. |
Text Attributes | |||
Font |
Yes | Default Font |
The font used for all fill and stroke text operations. |
Text Align |
Yes | LEFT |
The horizontal alignment of text with respect to the X coordinate
specified in the text operation.
|
Text Baseline |
Yes | BASELINE |
The vertical position of the text relative to the Y coordinate
specified in the text operation.
|
Font Smoothing |
Yes | GRAY |
The type of smoothing (antialiasing) applied to the glyphs in the font for all fill text operations. |
Path Attributes | |||
Current Path |
No | Empty path | The path constructed using various path construction methods to be used in various path filling, stroking, or clipping operations. |
Fill Rule |
Yes | NON_ZERO |
The method used to determine the interior of paths for a path fill or clip operation. |
The various rendering methods on the GraphicsContext
use the
following sets of rendering attributes:
Method | Common Rendering Attributes | Fill Attributes | Stroke Attributes | Text Attributes | Path Attributes |
---|---|---|---|---|---|
Basic Shape Rendering | |||||
fillRect() ,
fillRoundRect() ,
fillOval() ,
fillArc()
|
Yes | Yes | No | No | No |
strokeLine() ,
strokeRect() ,
strokeRoundRect() ,
strokeOval() ,
strokeArc()
|
Yes | No | Yes | No | No |
clearRect()
|
Yes [1] | No | No | No | No |
fillPolygon()
|
Yes | Yes | No | No | Yes [2] |
strokePolygon() ,
strokePolyline()
|
Yes | No | Yes | No | No |
[1] Only the Transform, Clip, and Effect apply to clearRect() | |||||
Text Rendering | |||||
fillText() ,
fillText(with maxWidth)
|
Yes | Yes | No | Yes [3] | No |
strokeText() ,
strokeText(with maxWidth)
|
Yes | No | Yes | Yes [3] | No |
[3] The Font Smoothing attribute only applies to filled text | |||||
Path Rendering | |||||
beginPath() ,
moveTo() ,
lineTo() ,
quadraticCurveTo() ,
bezierCurveTo() ,
arc() ,
arcTo() ,
appendSVGPath() ,
closePath() ,
rect()
|
Yes [4] | No | No | No | No |
fill()
|
Yes [4] | Yes | No | No | Yes |
stroke()
|
Yes [4] | No | Yes | No | Yes [5] |
clip()
|
No | No | No | No | Yes |
[4] Transform applied only during path construction | |||||
Image Rendering | |||||
drawImage(all forms)
|
Yes | No | No | No | No |
Miscellaneous | |||||
applyEffect() ,
PixelWriter methods
|
No | No | No | No | No |
Example:
import javafx.scene.*; import javafx.scene.paint.*; import javafx.scene.canvas.*; Group root = new Group(); Scene s = new Scene(root, 300, 300, Color.BLACK); final Canvas canvas = new Canvas(250,250); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setFill(Color.BLUE); gc.fillRect(75,75,100,100); root.getChildren().add(canvas);
Modifier and Type | Method and Description |
---|---|
void |
appendSVGPath(String svgpath)
Appends an SVG Path string to the current path.
|
void |
applyEffect(Effect e)
Applies the given effect to the entire bounds of the canvas and stores
the result back into the same canvas.
|
void |
arc(double centerX,
double centerY,
double radiusX,
double radiusY,
double startAngle,
double length)
Adds path elements to the current path to make an arc that uses Euclidean
degrees.
|
void |
arcTo(double x1,
double y1,
double x2,
double y2,
double radius)
Adds segments to the current path to make an arc.
|
void |
beginPath()
Resets the current path to empty.
|
void |
bezierCurveTo(double xc1,
double yc1,
double xc2,
double yc2,
double x1,
double y1)
Adds segments to the current path to make a cubic Bezier curve.
|
void |
clearRect(double x,
double y,
double w,
double h)
Clears a portion of the canvas with a transparent color value.
|
void |
clip()
Intersects the current clip with the current path and applies it to
subsequent rendering operation as an anti-aliased mask.
|
void |
closePath()
Closes the path.
|
void |
drawImage(Image img,
double x,
double y)
Draws an image at the given x, y position using the width
and height of the given image.
|
void |
drawImage(Image img,
double x,
double y,
double w,
double h)
Draws an image into the given destination rectangle of the canvas.
|
void |
drawImage(Image img,
double sx,
double sy,
double sw,
double sh,
double dx,
double dy,
double dw,
double dh)
Draws the specified source rectangle of the given image to the given
destination rectangle of the Canvas.
|
void |
fill()
Fills the path with the current fill paint.
|
void |
fillArc(double x,
double y,
double w,
double h,
double startAngle,
double arcExtent,
ArcType closure)
Fills an arc using the current fill paint.
|
void |
fillOval(double x,
double y,
double w,
double h)
Fills an oval using the current fill paint.
|
void |
fillPolygon(double[] xPoints,
double[] yPoints,
int nPoints)
Fills a polygon with the given points using the currently set fill paint.
|
void |
fillRect(double x,
double y,
double w,
double h)
Fills a rectangle using the current fill paint.
|
void |
fillRoundRect(double x,
double y,
double w,
double h,
double arcWidth,
double arcHeight)
Fills a rounded rectangle using the current fill paint.
|
void |
fillText(String text,
double x,
double y)
Fills the given string of text at position x, y
with the current fill paint attribute.
|
void |
fillText(String text,
double x,
double y,
double maxWidth)
Fills text and includes a maximum width of the string.
|
Canvas |
getCanvas()
Gets the
Canvas that the GraphicsContext is issuing draw
commands to. |
Effect |
getEffect(Effect e)
Gets a copy of the effect to be applied after the next draw call.
|
Paint |
getFill()
Gets the current fill paint attribute.
|
FillRule |
getFillRule()
Get the filling rule attribute for determining the interior of paths
in fill and clip operations.
|
Font |
getFont()
Gets the current Font.
|
FontSmoothingType |
getFontSmoothingType()
Gets the current Font Smoothing Type.
|
double |
getGlobalAlpha()
Gets the current global alpha.
|
BlendMode |
getGlobalBlendMode()
Gets the global blend mode.
|
StrokeLineCap |
getLineCap()
Gets the current stroke line cap.
|
double[] |
getLineDashes()
Gets a copy of the current line dash array.
|
double |
getLineDashOffset()
Gets the current line dash offset.
|
StrokeLineJoin |
getLineJoin()
Gets the current stroke line join.
|
double |
getLineWidth()
Gets the current line width.
|
double |
getMiterLimit()
Gets the current miter limit.
|
PixelWriter |
getPixelWriter()
Returns a
PixelWriter object that can be used to modify
the pixels of the Canvas associated with this
GraphicsContext . |
Paint |
getStroke()
Gets the current stroke.
|
TextAlignment |
getTextAlign()
Gets the current
TextAlignment . |
VPos |
getTextBaseline()
Gets the current Text Baseline.
|
Affine |
getTransform()
Returns a copy of the current transform.
|
Affine |
getTransform(Affine xform)
Copies the current transform into the supplied object, creating
a new
Affine object if it is null, and returns the object
containing the copy. |
boolean |
isPointInPath(double x,
double y)
Returns true if the the given x,y point is inside the path.
|
void |
lineTo(double x1,
double y1)
Adds segments to the current path to make a line to the given x,y
coordinate.
|
void |
moveTo(double x0,
double y0)
Issues a move command for the current path to the given x,y coordinate.
|
void |
quadraticCurveTo(double xc,
double yc,
double x1,
double y1)
Adds segments to the current path to make a quadratic Bezier curve.
|
void |
rect(double x,
double y,
double w,
double h)
Adds path elements to the current path to make a rectangle.
|
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.
|
void |
rotate(double degrees)
Rotates the current transform in degrees.
|
void |
save()
Saves the following attributes onto a stack.
|
void |
scale(double x,
double y)
Scales the current transform by x, y.
|
void |
setEffect(Effect e)
Sets the effect to be applied after the next draw call, or null to
disable effects.
|
void |
setFill(Paint p)
Sets the current fill paint attribute.
|
void |
setFillRule(FillRule fillRule)
Set the filling rule attribute for determining the interior of paths
in fill or clip operations.
|
void |
setFont(Font f)
Sets the current Font.
|
void |
setFontSmoothingType(FontSmoothingType fontsmoothing)
Sets the current Font Smoothing Type.
|
void |
setGlobalAlpha(double alpha)
Sets the global alpha of the current state.
|
void |
setGlobalBlendMode(BlendMode op)
Sets the global blend mode.
|
void |
setLineCap(StrokeLineCap cap)
Sets the current stroke line cap.
|
void |
setLineDashes(double... dashes)
Sets the current stroke line dash pattern to a normalized copy of
the argument.
|
void |
setLineDashOffset(double dashOffset)
Sets the line dash offset.
|
void |
setLineJoin(StrokeLineJoin join)
Sets the current stroke line join.
|
void |
setLineWidth(double lw)
Sets the current line width.
|
void |
setMiterLimit(double ml)
Sets the current miter limit.
|
void |
setStroke(Paint p)
Sets the current stroke paint attribute.
|
void |
setTextAlign(TextAlignment align)
Defines horizontal text alignment, relative to the text
x origin. |
void |
setTextBaseline(VPos baseline)
Sets the current Text Baseline.
|
void |
setTransform(Affine xform)
Sets the current transform.
|
void |
setTransform(double mxx,
double myx,
double mxy,
double myy,
double mxt,
double myt)
Sets the current transform.
|
void |
stroke()
Strokes the path with the current stroke paint.
|
void |
strokeArc(double x,
double y,
double w,
double h,
double startAngle,
double arcExtent,
ArcType closure)
Strokes an Arc using the current stroke paint.
|
void |
strokeLine(double x1,
double y1,
double x2,
double y2)
Strokes a line using the current stroke paint.
|
void |
strokeOval(double x,
double y,
double w,
double h)
Strokes an oval using the current stroke paint.
|
void |
strokePolygon(double[] xPoints,
double[] yPoints,
int nPoints)
Strokes a polygon with the given points using the currently set stroke paint.
|
void |
strokePolyline(double[] xPoints,
double[] yPoints,
int nPoints)
Strokes a polyline with the given points using the currently set stroke
paint attribute.
|
void |
strokeRect(double x,
double y,
double w,
double h)
Strokes a rectangle using the current stroke paint.
|
void |
strokeRoundRect(double x,
double y,
double w,
double h,
double arcWidth,
double arcHeight)
Strokes a rounded rectangle using the current stroke paint.
|
void |
strokeText(String text,
double x,
double y)
Draws the given string of text at position x, y
with the current stroke paint attribute.
|
void |
strokeText(String text,
double x,
double y,
double maxWidth)
Draws text with stroke paint and includes a maximum width of the string.
|
void |
transform(Affine xform)
Concatenates the input with the current transform.
|
void |
transform(double mxx,
double myx,
double mxy,
double myy,
double mxt,
double myt)
Concatenates the input with the current transform.
|
void |
translate(double x,
double y)
Translates the current transform by x, y.
|
public Canvas getCanvas()
Canvas
that the GraphicsContext
is issuing draw
commands to. There is only ever one Canvas
for a
GraphicsContext
.GraphicsContext
is issuing draw
commands to.public void save()
public void restore()
public void translate(double x, double y)
x
- value to translate along the x axis.y
- value to translate along the y axis.public void scale(double x, double y)
x
- value to scale in the x axis.y
- value to scale in the y axis.public void rotate(double degrees)
degrees
- value in degrees to rotate the current transform.public 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 void transform(Affine xform)
null
value is treated as identity.xform
- The affine to be concatenated with the current transform or null.public 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 void setTransform(Affine xform)
xform
- The affine to be copied and used as the current transform.public Affine getTransform(Affine xform)
Affine
object if it is null, and returns the object
containing the copy.xform
- A transform object that will be used to hold the result.
If xform is non null, then this method will copy the current transform
into that object. If xform is null a new transform object will be
constructed. In either case, the return value is a copy of the current
transform.public Affine getTransform()
public void setGlobalAlpha(double alpha)
1.0
.
Any valid double can be set, but only values in the range
[0.0, 1.0]
are valid and the nearest value in that
range will be used for rendering.
The global alpha is a common attribute
used for nearly all rendering methods as specified in the
Rendering Attributes Table.alpha
- the new alpha value, clamped to [0.0, 1.0]
during actual use.public double getGlobalAlpha()
1.0
.
The global alpha is a common attribute
used for nearly all rendering methods as specified in the
Rendering Attributes Table.public void setGlobalBlendMode(BlendMode op)
SRC_OVER
.
A null
value will be ignored and the current value will remain unchanged.
The blend mode is a common attribute
used for nearly all rendering methods as specified in the
Rendering Attributes Table.op
- the BlendMode
that will be set or null.public BlendMode getGlobalBlendMode()
SRC_OVER
.
The blend mode is a common attribute
used for nearly all rendering methods as specified in the
Rendering Attributes Table.BlendMode
of the current state.public void setFill(Paint p)
BLACK
.
The fill paint is a fill attribute
used for any of the fill methods as specified in the
Rendering Attributes Table.
A null
value will be ignored and the current value will remain unchanged.p
- The Paint
to be used as the fill Paint
or null.public Paint getFill()
BLACK
.
The fill paint is a fill attribute
used for any of the fill methods as specified in the
Rendering Attributes Table.Paint
to be used as the fill Paint
.public void setStroke(Paint p)
BLACK
.
The stroke paint is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.
A null
value will be ignored and the current value will remain unchanged.p
- The Paint to be used as the stroke Paint or null.public Paint getStroke()
BLACK
.
The stroke paint is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.Paint
to be used as the stroke Paint
.public void setLineWidth(double lw)
1.0
.
The line width is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.
An infinite or non-positive value outside of the range (0, +inf)
will be ignored and the current value will remain unchanged.lw
- value in the range {0-positive infinity}, with any other value
being ignored and leaving the value unchanged.public double getLineWidth()
1.0
.
The line width is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.public void setLineCap(StrokeLineCap cap)
SQUARE
.
The line cap is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.
A null
value will be ignored and the current value will remain unchanged.cap
- StrokeLineCap
with a value of Butt, Round, or Square or null.public StrokeLineCap getLineCap()
SQUARE
.
The line cap is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.StrokeLineCap
with a value of Butt, Round, or Square.public void setLineJoin(StrokeLineJoin join)
StrokeLineJoin.MITER
.
The line join is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.
A null
value will be ignored and the current value will remain unchanged.join
- StrokeLineJoin
with a value of Miter, Bevel, or Round or null.public StrokeLineJoin getLineJoin()
StrokeLineJoin.MITER
.
The line join is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.StrokeLineJoin
with a value of Miter, Bevel, or Round.public void setMiterLimit(double ml)
10.0
.
The miter limit is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.
An infinite or non-positive value outside of the range (0, +inf)
will be ignored and the current value will remain unchanged.ml
- miter limit value between 0 and positive infinity with
any other value being ignored and leaving the value unchanged.public double getMiterLimit()
10.0
.
The miter limit is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.0.0-positive infinity
public void setLineDashes(double... dashes)
null
.
The line dash array is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.
If the array is null
or empty or contains all 0
elements
then dashing will be disabled and the current dash array will be set
to null
.
If any of the elements of the array are a negative, infinite, or NaN
value outside the range [0, +inf)
then the entire array will
be ignored and the current dash array will remain unchanged.
If the array is an odd length then it will be treated as if it
were two copies of the array appended to each other.dashes
- the array of finite non-negative dash lengthspublic double[] getLineDashes()
null
.
The array may be normalized by the validation tests in the
setLineDashes(double...)
method.
The line dash array is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.public void setLineDashOffset(double dashOffset)
0.0
.
The line dash offset is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.
An infinite or NaN value outside of the range (-inf, +inf)
will be ignored and the current value will remain unchanged.dashOffset
- the line dash offset in the range (-inf, +inf)
public double getLineDashOffset()
0.0
.
The line dash offset is a stroke attribute
used for any of the stroke methods as specified in the
Rendering Attributes Table.(-inf, +inf)
public void setFont(Font f)
Font.getDefault()
.
The font is a text attribute
used for any of the text methods as specified in the
Rendering Attributes Table.
A null
value will be ignored and the current value will remain unchanged.f
- the Font or null.public Font getFont()
Font.getDefault()
.
The font is a text attribute
used for any of the text methods as specified in the
Rendering Attributes Table.public void setFontSmoothingType(FontSmoothingType fontsmoothing)
GRAY
.
The font smoothing type is a text attribute
used for any of the text methods as specified in the
Rendering Attributes Table.
A null
value will be ignored and the current value will remain unchanged.
Note that the FontSmoothingType
value of
LCD
is only supported over an opaque
background. LCD
text will generally appear as GRAY
text over transparent or partially transparent pixels, and in some
implementations it may not be supported at all on a Canvas
because the required support does not exist for surfaces which contain
an alpha channel as all Canvas
objects do.
fontsmoothing
- the FontSmoothingType
or nullpublic FontSmoothingType getFontSmoothingType()
GRAY
.
The font smoothing type is a text attribute
used for any of the text methods as specified in the
Rendering Attributes Table.FontSmoothingType
public void setTextAlign(TextAlignment align)
x
origin.
The default value is LEFT
.
The text alignment is a text attribute
used for any of the text methods as specified in the
Rendering Attributes Table.
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.
A null
value will be ignored and the current value will remain unchanged.
align
- TextAlignment
with values of Left, Center, Right or null.public TextAlignment getTextAlign()
TextAlignment
.
The default value is LEFT
.
The text alignment is a text attribute
used for any of the text methods as specified in the
Rendering Attributes Table.TextAlignment
with values of Left, Center, Right, or
Justify.public void setTextBaseline(VPos baseline)
BASELINE
.
The text baseline is a text attribute
used for any of the text methods as specified in the
Rendering Attributes Table.
A null
value will be ignored and the current value will remain unchanged.baseline
- VPos
with values of Top, Center, Baseline, or Bottom or null.public VPos getTextBaseline()
BASELINE
.
The text baseline is a text attribute
used for any of the text methods as specified in the
Rendering Attributes Table.VPos
with values of Top, Center, Baseline, or Bottompublic void fillText(String text, double x, double y)
null
text value will be ignored.
This method will be affected by any of the global common, fill, or text attributes as specified in the Rendering Attributes Table.
text
- the string of text or null.x
- position on the x axis.y
- position on the y axis.public void strokeText(String text, double x, double y)
null
text value will be ignored.
This method will be affected by any of the global common, stroke, or text attributes as specified in the Rendering Attributes Table.
text
- the string of text or null.x
- position on the x axis.y
- position on the y axis.public void fillText(String text, double x, double y, double maxWidth)
null
text value will be ignored.
This method will be affected by any of the global common, fill, or text attributes as specified in the Rendering Attributes Table.
text
- the string of text or null.x
- position on the x axis.y
- position on the y axis.maxWidth
- maximum width the text string can have.public void strokeText(String text, double x, double y, double maxWidth)
null
text value will be ignored.
This method will be affected by any of the global common, stroke, or text attributes as specified in the Rendering Attributes Table.
text
- the string of text or null.x
- position on the x axis.y
- position on the y axis.maxWidth
- maximum width the text string can have.public void setFillRule(FillRule fillRule)
FillRule.NON_ZERO
.
A null
value will be ignored and the current value will remain unchanged.
The fill rule is a path attribute
used for any of the fill or clip path methods as specified in the
Rendering Attributes Table.fillRule
- FillRule
with a value of Even_odd or Non_zero or null.public FillRule getFillRule()
FillRule.NON_ZERO
.
The fill rule is a path attribute
used for any of the fill or clip path methods as specified in the
Rendering Attributes Table.public void beginPath()
save()
and
restore()
operations.public void moveTo(double x0, double y0)
save()
and
restore()
operations.x0
- the X position for the move to command.y0
- the Y position for the move to command.public void lineTo(double x1, double y1)
save()
and
restore()
operations.x1
- the X coordinate of the ending point of the line.y1
- the Y coordinate of the ending point of the line.public void quadraticCurveTo(double xc, double yc, double x1, double y1)
save()
and
restore()
operations.xc
- the X coordinate of the control pointyc
- the Y coordinate of the control pointx1
- the X coordinate of the end pointy1
- the Y coordinate of the end pointpublic void bezierCurveTo(double xc1, double yc1, double xc2, double yc2, double x1, double y1)
save()
and
restore()
operations.xc1
- the X coordinate of first Bezier control point.yc1
- the Y coordinate of the first Bezier control point.xc2
- the X coordinate of the second Bezier control point.yc2
- the Y coordinate of the second Bezier control point.x1
- the X coordinate of the end point.y1
- the Y coordinate of the end point.public void arcTo(double x1, double y1, double x2, double y2, double radius)
save()
and
restore()
operations.
If p0
is the current point in the path and p1
is the
point specified by (x1, y1)
and p2
is the point
specified by (x2, y2)
, then the arc segments appended will
be segments along the circumference of a circle of the specified
radius touching and inscribed into the convex (interior) side of
p0->p1->p2
. The path will contain a line segment (if
needed) to the tangent point between that circle and p0->p1
followed by circular arc segments to reach the tangent point between
the circle and p1->p2
and will end with the current point at
that tangent point (not at p2
).
Note that the radius and circularity of the arc segments will be
measured or considered relative to the current transform, but the
resulting segments that are computed from those untransformed
points will then be transformed when they are added to the path.
Since all computation is done in untransformed space, but the
pre-existing path segments are all transformed, the ability to
correctly perform the computation may implicitly depend on being
able to inverse transform the current end of the current path back
into untransformed coordinates.
If there is no way to compute and inscribe the indicated circle
for any reason then the entire operation will simply append segments
to force a line to point p1
. Possible reasons that the
computation may fail include:
p0->p1->p2
are colinear.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 void arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length)
save()
and
restore()
operations.centerX
- the center x position of the arc.centerY
- the center y position of the arc.radiusX
- the x radius of the arc.radiusY
- the y radius of the arc.startAngle
- the starting angle of the arc in the range 0-360.0
length
- the length of the baseline of the arc.public void rect(double x, double y, double w, double h)
save()
and
restore()
operations.x
- x position of the upper left corner of the rectangle.y
- y position of the upper left corner of the rectangle.w
- width of the rectangle.h
- height of the rectangle.public void appendSVGPath(String svgpath)
null
value or incorrect SVG path will be ignored.
The coordinates are transformed by the current transform as they are
added to the path and unaffected by subsequent changes to the transform.
The current path is a path attribute
used for any of the path methods as specified in the
Rendering Attributes Table
and is not affected by the save()
and
restore()
operations.svgpath
- the SVG Path string.public void closePath()
save()
and
restore()
operations.public void fill()
This method will be affected by any of the
global common,
fill,
or path
attributes as specified in the
Rendering Attributes Table.
Note that the path segments were transformed as they were originally
added to the current path so the current transform will not affect
those path segments again, but it may affect other attributes in
affect at the time of the fill()
operation.
public void stroke()
This method will be affected by any of the
global common,
stroke,
or path
attributes as specified in the
Rendering Attributes Table.
Note that the path segments were transformed as they were originally
added to the current path so the current transform will not affect
those path segments again, but it may affect other attributes in
affect at the time of the stroke()
operation.
public void clip()
This method will itself be affected only by the
path
attributes as specified in the
Rendering Attributes Table.
Note that the path segments were transformed as they were originally
added to the current path so the current transform will not affect
those path segments again, but it may affect other attributes in
affect at the time of the stroke()
operation.
public 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 void clearRect(double x, double y, double w, double h)
This method will be affected only by the current transform, clip, and effect.
x
- X position of the upper left corner of the rectangle.y
- Y position of the upper left corner of the rectangle.w
- width of the rectangle.h
- height of the rectangle.public void fillRect(double x, double y, double w, double h)
This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table.
x
- the X position of the upper left corner of the rectangle.y
- the Y position of the upper left corner of the rectangle.w
- the width of the rectangle.h
- the height of the rectangle.public void strokeRect(double x, double y, double w, double h)
This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.
x
- the X position of the upper left corner of the rectangle.y
- the Y position of the upper left corner of the rectangle.w
- the width of the rectangle.h
- the height of the rectangle.public void fillOval(double x, double y, double w, double h)
This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table.
x
- the X coordinate of the upper left bound of the oval.y
- the Y coordinate of the upper left bound of the oval.w
- the width at the center of the oval.h
- the height at the center of the oval.public void strokeOval(double x, double y, double w, double h)
This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.
x
- the X coordinate of the upper left bound of the oval.y
- the Y coordinate of the upper left bound of the oval.w
- the width at the center of the oval.h
- the height at the center of the oval.public void fillArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
null
ArcType or
non positive width or height will cause the render command to be ignored.
This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table.
x
- the X coordinate of the arc.y
- the Y coordinate of the arc.w
- the width of the arc.h
- the height of the arc.startAngle
- the starting angle of the arc in degrees.arcExtent
- the angular extent of the arc in degrees.closure
- closure type (Round, Chord, Open) or null.public void strokeArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
null
ArcType or
non positive width or height will cause the render command to be ignored.
This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.
x
- the X coordinate of the arc.y
- the Y coordinate of the arc.w
- the width of the arc.h
- the height of the arc.startAngle
- the starting angle of the arc in degrees.arcExtent
- arcExtent the angular extent of the arc in degrees.closure
- closure type (Round, Chord, Open) or nullpublic void fillRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
This method will be affected by any of the global common or fill attributes as specified in the Rendering Attributes Table.
x
- the X coordinate of the upper left bound of the oval.y
- the Y coordinate of the upper left bound of the oval.w
- the width at the center of the oval.h
- the height at the center of the oval.arcWidth
- the arc width of the rectangle corners.arcHeight
- the arc height of the rectangle corners.public void strokeRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.
x
- the X coordinate of the upper left bound of the oval.y
- the Y coordinate of the upper left bound of the oval.w
- the width at the center of the oval.h
- the height at the center of the oval.arcWidth
- the arc width of the rectangle corners.arcHeight
- the arc height of the rectangle corners.public void strokeLine(double x1, double y1, double x2, double y2)
This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.
x1
- the X coordinate of the starting point of the line.y1
- the Y coordinate of the starting point of the line.x2
- the X coordinate of the ending point of the line.y2
- the Y coordinate of the ending point of the line.public void fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
null
value for any of the arrays will be ignored and nothing will be drawn.
This method will be affected by any of the global common, fill, or Fill Rule attributes as specified in the Rendering Attributes Table.
xPoints
- array containing the x coordinates of the polygon's points or null.yPoints
- array containing the y coordinates of the polygon's points or null.nPoints
- the number of points that make the polygon.public void strokePolygon(double[] xPoints, double[] yPoints, int nPoints)
null
value for any of the arrays will be ignored and nothing will be drawn.
This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.
xPoints
- array containing the x coordinates of the polygon's points or null.yPoints
- array containing the y coordinates of the polygon's points or null.nPoints
- the number of points that make the polygon.public void strokePolyline(double[] xPoints, double[] yPoints, int nPoints)
null
value for any of the arrays will be ignored and nothing will be drawn.
This method will be affected by any of the global common or stroke attributes as specified in the Rendering Attributes Table.
xPoints
- array containing the x coordinates of the polyline's points or null.yPoints
- array containing the y coordinates of the polyline's points or null.nPoints
- the number of points that make the polyline.public void drawImage(Image img, double x, double y)
null
image value or an image still in progress will be ignored.
This method will be affected by any of the global common attributes as specified in the Rendering Attributes Table.
img
- the image to be drawn or null.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 void drawImage(Image img, double x, double y, double w, double h)
null
image value or an image still in progress will be ignored.
This method will be affected by any of the global common attributes as specified in the Rendering Attributes Table.
img
- the image to be drawn or null.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.w
- the width of the destination rectangle.h
- the height of the destination rectangle.public void drawImage(Image img, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)
null
image value or an image still in progress will be ignored.
This method will be affected by any of the global common attributes as specified in the Rendering Attributes Table.
img
- the image to be drawn or null.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 PixelWriter getPixelWriter()
PixelWriter
object that can be used to modify
the pixels of the Canvas
associated with this
GraphicsContext
.
All coordinates in the PixelWriter
methods on the returned
object will be in device space since they refer directly to pixels
and no other rendering attributes will be applied when modifying
pixels using this object.PixelWriter
for modifying the pixels of this
Canvas
public void setEffect(Effect e)
e
- the effect to use, or null to disable effectspublic Effect getEffect(Effect e)
e
- an Effect
object that may be used to store the
copy of the current effect, if it is of a compatible typepublic void applyEffect(Effect e)
null
value will be ignored.
The effect will be applied without any other rendering attributes and
under an Identity coordinate transform.
Since the effect is applied to the entire bounds of the canvas, some
effects may have a confusing result, such as a Reflection effect
that will apply its reflection off of the bottom of the canvas even if
only a portion of the canvas has been rendered to and will not be
visible unless a negative offset is used to bring the reflection back
into view.e
- the effect to apply onto the entire destination or null.Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2008, 2017, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.