- java.lang.Object
-
- javafx.scene.canvas.GraphicsContext
-
public final class GraphicsContext extends Object
该类用于使用缓冲区发出对Canvas的绘制调用。每个呼叫将必要的参数推送到缓冲区上,随后它们将在脉冲结束时由渲染线程随后呈现到
Canvas节点的图像上。A
Canvas只包含一个GraphicsContext,只有一个缓冲区。 如果它不附加到任何场景,那么它可以被任何线程修改,只要它一次只能从一个线程使用。 一旦Canvas节点附加到场景,它必须在JavaFX应用程序线程上进行修改。调用
GraphicsContext上的任何方法被认为是修改其对应的Canvas,并受同样的线程规则约束。A
GraphicsContext还管理可以随时保存或恢复的一堆状态对象。
List of Rendering Attributes Attribute Save/Restore? Default value Description Common Rendering AttributesGraphicsContext维护以下渲染属性,它们影响渲染方法的各种子集:ClipYes No clipping An anti-aliased intersection of various clip paths to which rendering is restricted.Global AlphaYes1.0An opacity value that controls the visibility or fading of each rendering operation.Global Blend ModeYesSRC_OVERABlendModeenum value that controls how pixels from each rendering operation are composited into the existing image.TransformYesIdentityA 3x2 2D affine transformation matrix that controls how coordinates are mapped onto the logical pixels of the canvas image.EffectYesnullAnEffectapplied individually to each rendering operation. Fill AttributesFill PaintYesBLACKThePaintto be applied to the interior of shapes in a fill operation. Stroke AttributesStroke PaintYesBLACKThePaintto be applied to the boundary of shapes in a stroke operation.Line WidthYes1.0The width of the stroke applied to the boundary of shapes in a stroke operation.Line CapYesSQUAREThe style of the end caps applied to the beginnings and ends of each dash and/or subpath in a stroke operation.Line JoinYesMITERThe style of the joins applied between individual segments in the boundary paths of shapes in a stroke operation.Miter LimitYes10.0The ratio limit of how far aMITERline 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 aBEVELjoin in a stroke operation.DashesYesnullThe array of dash lengths to be applied to the segments in the boundary of shapes in a stroke operation.Dash OffsetYes0.0The 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 AttributesFontYesDefault FontThe font used for all fill and stroke text operations.Text AlignYesLEFTThe horizontal alignment of text with respect to theXcoordinate specified in the text operation.Text BaselineYesBASELINEThe vertical position of the text relative to theYcoordinate specified in the text operation.Font SmoothingYesGRAYThe type of smoothing (antialiasing) applied to the glyphs in the font for all fill text operations. Path AttributesCurrent PathNo Empty path The path constructed using various path construction methods to be used in various path filling, stroking, or clipping operations.Fill RuleYesNON_ZEROThe method used to determine the interior of paths for a path fill or clip operation.The various rendering methods on the
Rendering Attributes Table Method Common Rendering Attributes Fill Attributes Stroke Attributes Text Attributes Path Attributes Basic Shape RenderingGraphicsContextuse the following sets of rendering attributes:fillRect(),fillRoundRect(),fillOval(),fillArc()Yes Yes No No NostrokeLine(),strokeRect(),strokeRoundRect(),strokeOval(),strokeArc()Yes No Yes No NoclearRect()Yes [1] No No No NofillPolygon()Yes Yes No No Yes [2]strokePolygon(),strokePolyline()Yes No Yes No No [1] Only the Transform, Clip, and Effect apply to clearRect()
[2] Only the Fill Rule applies to fillPolygon(), the current path is left unchanged Text RenderingfillText(),fillText(with maxWidth)Yes Yes No Yes [3] NostrokeText(),strokeText(with maxWidth)Yes No Yes Yes [3] No [3] The Font Smoothing attribute only applies to filled text Path RenderingbeginPath(),moveTo(),lineTo(),quadraticCurveTo(),bezierCurveTo(),arc(),arcTo(),appendSVGPath(),closePath(),rect()Yes [4] No No No Nofill()Yes [4] Yes No No Yesstroke()Yes [4] No Yes No Yes [5]clip()No No No No Yes [4] Transform applied only during path construction
[5] Fill Rule only used for fill() and clip() Image RenderingdrawImage(all forms)Yes No No No No MiscellaneousapplyEffect(),PixelWriter methodsNo No No No No例:
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);- 从以下版本开始:
- JavaFX 2.2
- 另请参见:
-
Canvas
-
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 voidappendSVGPath(String svgpath)将SVG路径字符串附加到当前路径。voidapplyEffect(Effect e)将给定的效果应用于画布的整个边界,并将结果存储回同一个画布。voidarc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length)将路径元素添加到当前路径以创建使用欧几里德度数的弧。voidarcTo(double x1, double y1, double x2, double y2, double radius)将段添加到当前路径以创建弧。voidbeginPath()将当前路径重置为空。voidbezierCurveTo(double xc1, double yc1, double xc2, double yc2, double x1, double y1)将段添加到当前路径以生成立方贝塞尔曲线。voidclearRect(double x, double y, double w, double h)用透明颜色值清除画布的一部分。voidclip()使用当前路径相交当前的剪辑并将其作为抗锯齿掩码应用到后续渲染操作。voidclosePath()关闭路径。voiddrawImage(Image img, double x, double y)使用给定图像的宽度和高度在给定的x,y位置绘制图像。voiddrawImage(Image img, double x, double y, double w, double h)将图像绘制到画布的给定目标矩形中。voiddrawImage(Image img, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)将给定图像的指定源矩形绘制到Canvas的给定目标矩形。voidfill()填充当前填充油漆的路径。voidfillArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)使用当前的填充油漆填充弧。voidfillOval(double x, double y, double w, double h)使用当前的填充油漆填充椭圆。voidfillPolygon(double[] xPoints, double[] yPoints, int nPoints)使用当前设置的填充油漆填充具有给定点的多边形。voidfillRect(double x, double y, double w, double h)使用当前的填充油漆填充矩形。voidfillRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)使用当前的填充油漆填充圆角矩形。voidfillText(String text, double x, double y)使用当前的填充颜色属性填充位置x,y处的给定文本字符串。voidfillText(String text, double x, double y, double maxWidth)填写文本并包含字符串的最大宽度。CanvasgetCanvas()获取Canvas的GraphicsContext发出绘制命令。EffectgetEffect(Effect e)获取下一次绘图调用后应用的效果的副本。PaintgetFill()获取当前的填充颜色属性。FillRulegetFillRule()获取填充规则属性,以确定填充和剪辑操作中路径的内部。FontgetFont()获取当前字体。FontSmoothingTypegetFontSmoothingType()获取当前的字体平滑类型。doublegetGlobalAlpha()获取当前的全局alpha。BlendModegetGlobalBlendMode()获取全局混合模式。StrokeLineCapgetLineCap()获取当前行程线上限。double[]getLineDashes()获取当前线短线阵列的副本。doublegetLineDashOffset()获取当前行的虚线偏移量。StrokeLineJoingetLineJoin()获取当前笔划行连接。doublegetLineWidth()获取当前行宽。doublegetMiterLimit()获得当前的斜角限制。PixelWritergetPixelWriter()返回一个PixelWriter对象,可用于修改与此GraphicsContext关联的Canvas的像素。PaintgetStroke()获取当前行程。TextAlignmentgetTextAlign()获得当前的TextAlignment。VPosgetTextBaseline()获取当前的文本基线。AffinegetTransform()返回当前变换的副本。AffinegetTransform(Affine xform)将当前变换复制到提供的对象中,创建一个新的Affine对象(如果为null),并返回包含副本的对象。booleanisPointInPath(double x, double y)如果给定的x,y点在路径内,则返回true。voidlineTo(double x1, double y1)将段添加到当前路径,以形成与给定x,y坐标的一条线。voidmoveTo(double x0, double y0)X- 20045 X- 20045 X- 20045 X- 20045 X- 2001-voidquadraticCurveTo(double xc, double yc, double x1, double y1)将段添加到当前路径以生成二次贝塞尔曲线。voidrect(double x, double y, double w, double h)将路径元素添加到当前路径以创建一个矩形。voidrestore()将状态从堆栈中弹出,将以下属性设置为将该状态推送到堆栈时的值。voidrotate(double degrees)以度为单位旋转当前变换。voidsave()将以下属性保存到堆栈中。voidscale(double x, double y)通过x,y来缩放当前的变换。voidsetEffect(Effect e)设置在下一次绘图调用后应用的效果,或设置为禁用效果的效果。voidsetFill(Paint p)设置当前填充绘图属性。voidsetFillRule(FillRule fillRule)设置填充规则属性以确定填充或剪辑操作中路径的内部。voidsetFont(Font f)设置当前字体。voidsetFontSmoothingType(FontSmoothingType fontsmoothing)设置当前的字体平滑类型。voidsetGlobalAlpha(double alpha)设置当前状态的全局alpha。voidsetGlobalBlendMode(BlendMode op)设置全局混合模式。voidsetLineCap(StrokeLineCap cap)设置当前行程行上限。voidsetLineDashes(double... dashes)将当前笔划线划线模式设置为参数的归一化副本。voidsetLineDashOffset(double dashOffset)设置线破折号偏移。voidsetLineJoin(StrokeLineJoin join)设置当前笔画行连接。voidsetLineWidth(double lw)设置当前行宽。voidsetMiterLimit(double ml)设定当前的斜度限制。voidsetStroke(Paint p)设置当前笔画paint属性。voidsetTextAlign(TextAlignment align)定义水平文本对齐方式,相对于文字x来源。voidsetTextBaseline(VPos baseline)设置当前的文本基线。voidsetTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt)设置当前变换。voidsetTransform(Affine xform)设置当前变换。voidstroke()用当前行程画笔来描绘路径。voidstrokeArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)使用当前笔画绘制弧。voidstrokeLine(double x1, double y1, double x2, double y2)使用当前笔画绘制线条。voidstrokeOval(double x, double y, double w, double h)使用当前的行程画笔绘制椭圆形。voidstrokePolygon(double[] xPoints, double[] yPoints, int nPoints)使用当前设置的笔画绘制使用给定点绘制多边形。voidstrokePolyline(double[] xPoints, double[] yPoints, int nPoints)使用当前设置的stroke paint属性来绘制具有给定点的折线。voidstrokeRect(double x, double y, double w, double h)使用当前笔画绘制矩形。voidstrokeRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)使用当前笔画绘制一个圆角矩形。voidstrokeText(String text, double x, double y)使用当前笔画paint属性绘制位置x,y处的给定文本字符串。voidstrokeText(String text, double x, double y, double maxWidth)用笔画绘制文本,并包含字符串的最大宽度。voidtransform(double mxx, double myx, double mxy, double myy, double mxt, double myt)将输入与当前变换相连。voidtransform(Affine xform)将输入与当前变换相连。voidtranslate(double x, double y)将当前变换转换为x,y。
-
-
-
方法详细信息
-
getCanvas
public Canvas getCanvas()
获取Canvas的GraphicsContext发出绘制命令。 对于Canvas,只有一个GraphicsContext。- 结果
-
画出这个
GraphicsContext发布绘制命令的画布。
-
save
public void save()
将以下属性保存到堆栈中。- 全球阿尔法
- 全球混合操作
- 转变
- 填充油漆
- 中风漆
- 行宽
- 线帽
- 行加入
- 斜度限制
- 夹
- 字形
- 文本对齐
- 文本基线
- 影响
- 填充规则
-
restore
public void restore()
将状态从堆栈中弹出,将以下属性设置为将该状态推送到堆栈时的值。 如果堆栈为空,则没有更改。- 全球阿尔法
- 全球混合操作
- 转变
- 填充油漆
- 中风漆
- 行宽
- 线帽
- 行加入
- 斜度限制
- 夹
- 字形
- 文本对齐
- 文本基线
- 影响
- 填充规则
-
translate
public void translate(double x, double y)将当前变换转换为x,y。- 参数
-
x- 沿x轴平移的值。 -
y- 沿y轴平移的值。
-
scale
public void scale(double x, double y)通过x,y来缩放当前的变换。- 参数
-
x- 在x轴上缩放的值。 -
y- 在y轴上缩放的值。
-
rotate
public void rotate(double degrees)
以度为单位旋转当前变换。- 参数
-
degrees- 以度为单位旋转当前变换的值。
-
transform
public void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt)将输入与当前变换相连。- 参数
-
mxx- - 3x4矩阵的X坐标缩放元素 -
myx- - 3x4矩阵的Y坐标剪切元素 -
mxy- - 3x4矩阵的X坐标剪切元素 -
myy- - 3x4矩阵的Y坐标缩放元素 -
mxt- - 3x4矩阵的X坐标转换元素 -
myt- - 3x4矩阵的Y坐标转换元素
-
transform
public void transform(Affine xform)
将输入与当前变换相连。 只支持2D转换。 所使用的唯一值是变换的X和Y缩放,平移和剪切分量。 Anull值被视为身份。- 参数
-
xform- 与当前变换连接的仿射或空值。
-
setTransform
public void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt)设置当前变换。- 参数
-
mxx- - 3x4矩阵的X坐标缩放元素 -
myx- - 3x4矩阵的Y坐标剪切元素 -
mxy- 3x4矩阵的X坐标剪切元素 -
myy- - 3x4矩阵的Y坐标缩放元素 -
mxt- 3x4矩阵的X坐标转换元素 -
myt- - 3x4矩阵的Y坐标转换元素
-
setTransform
public void setTransform(Affine xform)
设置当前变换。 只支持2D转换。 所使用的唯一值是变换的X和Y缩放,平移和剪切分量。- 参数
-
xform- 要复制并用作当前变换的仿射。
-
getTransform
public Affine getTransform(Affine xform)
将当前变换复制到提供的对象中,创建一个新的Affine对象(如果为null),并返回包含副本的对象。- 参数
-
xform- 将用于保存结果的转换对象。 如果xform为非空,则该方法将将当前变换复制到该对象中。 如果xform为空,则将构建一个新的变换对象。 在任一情况下,返回值都是当前变换的副本。 - 结果
- 当前变换的副本。
-
getTransform
public Affine getTransform()
返回当前变换的副本。- 结果
- 当前状态转换的副本。
-
setGlobalAlpha
public void setGlobalAlpha(double alpha)
设置当前状态的全局alpha。 默认值为1.0。 可以设置任何有效的双倍,但只有[0.0, 1.0]范围内的值有效,并且该范围中最接近的值将用于呈现。 全球阿尔法是common attribute用于在指定的几乎所有的渲染方法Rendering Attributes Table 。- 参数
-
alpha- 新的alpha值,在实际使用中被钳制到[0.0, 1.0]。
-
getGlobalAlpha
public double getGlobalAlpha()
- 结果
- 当前的全局alpha。
-
setGlobalBlendMode
public void setGlobalBlendMode(BlendMode op)
设置全局混合模式。 默认值为SRC_OVER。 Anull值将被忽略,当前值将保持不变。 混合模式是common attribute用于在指定的几乎所有的渲染方法Rendering Attributes Table 。- 参数
-
op- 将被设置或为null的BlendMode。
-
getGlobalBlendMode
public BlendMode getGlobalBlendMode()
- 结果
-
全球
BlendMode目前状态。
-
setFill
public void setFill(Paint p)
设置当前填充绘图属性。 默认值为BLACK。 填充油漆是用于Rendering Attributes Table中规定的任何填充方法的fill attribute 。 Anull值将被忽略,当前值将保持不变。- 参数
-
p-该Paint用作填充Paint或空。
-
getFill
public Paint getFill()
- 结果
-
p
Paint被用作填充Paint。
-
setStroke
public void setStroke(Paint p)
设置当前笔画paint属性。 默认值为BLACK。 中风涂料是用于Rendering Attributes Table中规定的任何冲程方法的stroke attribute 。 Anull值将被忽略,当前值将保持不变。- 参数
-
p- 用作笔画的油漆或空白。
-
getStroke
public Paint getStroke()
- 结果
-
Paint被用作笔画Paint。
-
setLineWidth
public void setLineWidth(double lw)
设置当前行宽。 默认值为1.0。 线宽是stroke attribute用于任何的作为规定的冲程方法Rendering Attributes Table 。 超出范围(0, +inf)的无限或非正值将被忽略,当前值将保持不变。- 参数
-
lw- 值范围为{0-positive infinity},任何其他值都被忽略,并保持不变。
-
getLineWidth
public double getLineWidth()
- 结果
- 值在0和无穷大之间。
-
setLineCap
public void setLineCap(StrokeLineCap cap)
设置当前行程行上限。 默认值为SQUARE。 线盖是stroke attribute用于任何的作为规定的冲程方法Rendering Attributes Table 。 Anull值将被忽略,当前值将保持不变。- 参数
-
cap-StrokeLineCap,其值为Butt,Round或Square或null。
-
getLineCap
public StrokeLineCap getLineCap()
- 结果
-
StrokeLineCap,其值为Butt,Round或Square。
-
setLineJoin
public void setLineJoin(StrokeLineJoin join)
设置当前笔画行连接。 默认值为StrokeLineJoin.MITER。 线连接是用于Rendering Attributes Table中规定的任何笔画方法的stroke attribute 。 Anull值将被忽略,当前值将保持不变。- 参数
-
join-StrokeLineJoin,其值为斜角,斜角或圆形或零。
-
getLineJoin
public StrokeLineJoin getLineJoin()
- 结果
-
StrokeLineJoin,其值为斜角,斜角或圆形。
-
setMiterLimit
public void setMiterLimit(double ml)
设定当前的斜度限制。 默认值为10.0。 转角限制是stroke attribute用于任何的作为规定的冲程方法Rendering Attributes Table 。 超出范围(0, +inf)的无限或非正值将被忽略,当前值将保持不变。- 参数
-
ml- 任何其他值被忽略且保持不变的0和正无穷大之间的ml极限值。
-
getMiterLimit
public double getMiterLimit()
- 结果
-
斜角极限值在
0.0-positive infinity范围内
-
setLineDashes
public void setLineDashes(double... dashes)
将当前笔划线划线模式设置为参数的归一化副本。 默认值为null。 行虚线数组是stroke attribute用于任何的作为规定的冲程方法Rendering Attributes Table 。 如果数组为null或为空或包含所有0元素,则0将被禁用,并且当前的虚线数组将被设置为null。 如果数组的任何元素是负数,无限或NaN值超出范围[0, +inf)则整个数组将被忽略,并且当前的虚线数组将保持不变。 如果数组是一个奇数长度,那么它将被视为相互附加的数组的两个副本。- 参数
-
dashes- 有限非负面短划线的数组 - 从以下版本开始:
- JavaFX 8u40
-
getLineDashes
public double[] getLineDashes()
获取当前线短线阵列的副本。 默认值为null。 可以通过setLineDashes(double...)方法中的验证测试对阵列进行归一化。 行虚线数组是stroke attribute用于任何的作为规定的冲程方法Rendering Attributes Table 。- 结果
- 当前线短线阵列的副本。
- 从以下版本开始:
- JavaFX 8u40
-
setLineDashOffset
public void setLineDashOffset(double dashOffset)
设置线破折号偏移。 默认值为0.0。 线破折号偏移是2706838111542770中指定的任何笔画方法的stroke attribute 。 超出范围(-inf, +inf)的无限或NaN值将被忽略,当前值将保持不变。- 参数
-
dashOffset- 线破折号在范围(-inf, +inf) - 从以下版本开始:
- JavaFX 8u40
-
getLineDashOffset
public double getLineDashOffset()
- 结果
-
在线破折号偏移范围
(-inf, +inf) - 从以下版本开始:
- JavaFX 8u40
-
setFont
public void setFont(Font f)
设置当前字体。 默认值由Font.getDefault()指定。 该字体是用于Rendering Attributes Table中指定的任何文本方法的text attribute 。 Anull值将被忽略,当前值将保持不变。- 参数
-
f- 字体或空。
-
getFont
public Font getFont()
- 结果
- 字体
-
setFontSmoothingType
public void setFontSmoothingType(FontSmoothingType fontsmoothing)
设置当前的字体平滑类型。 默认值为GRAY。 字体平滑类型是用于Rendering Attributes Table中指定的任何文本方法的text attribute 。 Anull值将被忽略,当前值将保持不变。需要注意的是
FontSmoothingType的价值LCD仅支持在一个不透明的背景。LCD文本通常会在透明或部分透明的像素上显示为GRAY文本,在某些实现中,由于对于所有Canvas对象都包含alpha通道的表面,不存在所需的支持,因此Canvas可能不受支持。- 参数
-
fontsmoothing-FontSmoothingType或null - 从以下版本开始:
- JavaFX 8u40
-
getFontSmoothingType
public FontSmoothingType getFontSmoothingType()
- 结果
-
FontSmoothingType - 从以下版本开始:
- JavaFX 8u40
-
setTextAlign
public void setTextAlign(TextAlignment align)
定义水平文本对齐,相对于文本x来源。 默认值为LEFT。 文本对齐是用于Rendering Attributes Table中指定的任何文本方法的text attribute 。让水平边界表示单行文本的逻辑宽度。 每行文本都有一个单独的水平边界。
然后TextAlignment指定为:
- 左:水平边界的左边缘将在
x。 - 中心:中心,左右边缘之间的中间,水平边界将在
x。 - 右:水平边界的右边缘将在
x。
注意:画布不支持换行,因此文本对齐对齐对齐与左对齐文本相同。
A
null值将被忽略,当前值将保持不变。- 参数
-
align-TextAlignment,其值为Left,Center,Right或null。
- 左:水平边界的左边缘将在
-
getTextAlign
public TextAlignment getTextAlign()
- 结果
-
TextAlignment,其值为左,中,右或对齐。
-
setTextBaseline
public void setTextBaseline(VPos baseline)
设置当前的文本基线。 默认值为BASELINE。 文本基线是用于Rendering Attributes Table中指定的任何文本方法的text attribute 。 Anull值将被忽略,当前值将保持不变。- 参数
-
baseline-VPos,其值为Top,Center,Baseline或Bottom或null。
-
getTextBaseline
public VPos getTextBaseline()
- 结果
-
VPos,其值为Top,Center,Baseline或Bottom
-
fillText
public void fillText(String text, double x, double y)
使用当前的填充颜色属性填充位置x,y处的给定文本字符串。 Anull文本值将被忽略。此方法将被任何的影响global common , fill ,或text属性作为指定Rendering Attributes Table 。
- 参数
-
text- 文本字符串或null。 -
x- x轴上的位置。 -
y- y轴上的位置。
-
strokeText
public void strokeText(String text, double x, double y)
使用当前笔画paint属性绘制位置x,y处的给定文本字符串。 Anull文本值将被忽略。此方法将被任何的影响global common , stroke ,或text属性作为指定Rendering Attributes Table 。
- 参数
-
text- 文本字符串或null。 -
x- x轴上的位置。 -
y- y轴上的位置。
-
fillText
public void fillText(String text, double x, double y, double maxWidth)
填写文本并包含字符串的最大宽度。 如果文本的宽度超过最大宽度,则它的大小适合。 Anull文本值将被忽略。此方法将被任何的影响global common , fill ,或text属性作为指定Rendering Attributes Table 。
- 参数
-
text- 文本字符串或null。 -
x- x轴上的位置。 -
y- y轴上的位置。 -
maxWidth- 文本字符串可以具有的最大宽度。
-
strokeText
public void strokeText(String text, double x, double y, double maxWidth)
用笔画绘制文本,并包含字符串的最大宽度。 如果文本的宽度超过最大宽度,则它的大小适合。 一个null文本值将被忽略。此方法将被任何的影响global common , stroke ,或text属性作为指定Rendering Attributes Table 。
- 参数
-
text- 文本字符串或null。 -
x- x轴上的位置。 -
y- y轴上的位置。 -
maxWidth- 文本字符串可以具有的最大宽度。
-
setFillRule
public void setFillRule(FillRule fillRule)
设置填充规则属性以确定填充或剪辑操作中路径的内部。 默认值为FillRule.NON_ZERO。 Anull值将被忽略,当前值将保持不变。 填充规则是用于Rendering Attributes Table中指定的任何填充或剪辑路径方法的path attribute 。- 参数
-
fillRule-FillRule,其值为Even_odd或Non_zero或null。
-
getFillRule
public FillRule getFillRule()
获取填充规则属性,以确定填充和剪辑操作中路径的内部。 默认值为FillRule.NON_ZERO。 填充规则是用于Rendering Attributes Table中指定的任何填充或剪辑路径方法的path attribute 。- 结果
- 当前填充规则。
-
beginPath
public void beginPath()
将当前路径重置为空。 默认路径为空。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。
-
moveTo
public void moveTo(double x0, double y0)X- 20045 X- 20045 X- 20045 X- 20045 X- 2001- 当它们被添加到路径中时,坐标被当前变换变换,并且不受变换的后续改变的影响。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。- 参数
-
x0- 移动到命令的X位置。 -
y0- 移动命令的Y位置。
-
lineTo
public void lineTo(double x1, double y1)将段添加到当前路径,以形成与给定x,y坐标的一条线。 当它们被添加到路径中时,坐标被当前变换变换,并且不受变换的后续改变的影响。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。- 参数
-
x1- 线的终点的X坐标。 -
y1- 线的终点的Y坐标。
-
quadraticCurveTo
public void quadraticCurveTo(double xc, double yc, double x1, double y1)将段添加到当前路径以生成二次贝塞尔曲线。 当它们被添加到路径中时,坐标被当前变换变换,并且不受变换的后续改变的影响。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。- 参数
-
xc- 控制点的X坐标 -
yc- 控制点的Y坐标 -
x1- 终点的X坐标 -
y1- 终点的Y坐标
-
bezierCurveTo
public void bezierCurveTo(double xc1, double yc1, double xc2, double yc2, double x1, double y1)将段添加到当前路径以生成立方贝塞尔曲线。 当它们被添加到路径中时,坐标被当前变换变换,并且不受变换的后续改变的影响。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。- 参数
-
xc1- 第一个贝塞尔控制点的X坐标。 -
yc1- 第一个贝塞尔控制点的Y坐标。 -
xc2- 第二个贝塞尔控制点的X坐标。 -
yc2- 第二个贝塞尔控制点的Y坐标。 -
x1- 终点的X坐标。 -
y1- 终点的Y坐标。
-
arcTo
public void arcTo(double x1, double y1, double x2, double y2, double radius)将段添加到当前路径以创建弧。 当它们被添加到路径中时,坐标被当前变换变换,并且不受变换的后续改变的影响。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。如果
p0是路径中的当前点,并且p1是由(x1, y1)指定的点,而p2是由(x2, y2)指定的点,则附加的弧段将沿着指定半径的圆的圆周接触并内接到凸起(内)侧p0->p1->p2。 路径将包含线段(如果需要)到该圆之间的切点p0->p1接着圆弧段到达圆之间的切点p1->p2,并且将与在该切点当前点端(未在p2)。 请注意,圆弧段的半径和圆形度将相对于当前变换进行测量或考虑,但是从这些未转换点计算的结果段随后将被添加到路径中进行变换。 由于所有计算都是在未转换的空间中完成的,而是先前存在的路径段都被转换,所以正确执行计算的能力可能隐含地取决于是否能够将当前路径的当前结果逆变换为未转换的坐标。如果由于任何原因无法计算和刻录指示的圆圈,那么整个操作将只是附加段来强制线到
p1。 计算可能失败的可能原因包括:- 当前路径为空。
- 段
p0->p1->p2是共线的。 - 当前变换是不可逆的,因此当前路径的当前终点不能被转换以用于计算。
- 参数
-
x1- 弧的第一个点的X坐标。 -
y1- 弧的第一个点的Y坐标。 -
x2- 弧的第二个点的X坐标。 -
y2- 弧的第二个点的Y坐标。 -
radius- 圆弧的半径范围为{0.0-positive infinity}。
-
arc
public void arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length)将路径元素添加到当前路径以创建使用欧几里德度数的弧。 这个欧几里得方向从东到北,然后从西到西,然后是南,再回到东方。 当它们被添加到路径中时,坐标被当前变换变换,并且不受变换的后续改变的影响。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。- 参数
-
centerX- 弧的中心x位置。 -
centerY- 弧的中心y位置。 -
radiusX- 圆弧的x半径。 -
radiusY- 圆弧的y半径。 -
startAngle- 弧的起始角度在0-360.0范围内 -
length- 弧线基线的长度。
-
rect
public void rect(double x, double y, double w, double h)将路径元素添加到当前路径以创建一个矩形。 当它们被添加到路径中时,坐标被当前变换变换,并且不受变换的后续改变的影响。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。- 参数
-
x- 矩形左上角的x位置。 -
y- 矩形左上角的y位置。 -
w- 矩形的宽度。 -
h- 矩形的高度。
-
appendSVGPath
public void appendSVGPath(String svgpath)
将SVG路径字符串附加到当前路径。 如果没有当前路径,则字符串必须以任一类型的move命令开头。 一个null值或不正确的SVG路径将被忽略。 当它们被添加到路径中时,坐标被当前变换变换,并且不受变换的后续改变的影响。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。- 参数
-
svgpath- SVG路径字符串。
-
closePath
public void closePath()
关闭路径。 的电流路径是path attribute用于任何的作为指定的路径的方法Rendering Attributes Table , 并不受save()个restore()操作。
-
fill
public void fill()
填充当前填充油漆的路径。此方法将被任何的影响global common , fill ,或path属性作为指定Rendering Attributes Table 。 请注意,路径段原始添加到当前路径中进行转换,因此当前的变换不会再次影响这些路径段,但是在
fill()操作时可能会影响其他属性。
-
stroke
public void stroke()
用当前行程画笔来描绘路径。此方法将被任何的影响global common , stroke ,或path属性作为指定Rendering Attributes Table 。 请注意,路径段被原始添加到当前路径中进行转换,因此当前的变换不会再次影响这些路径段,但是在
stroke()操作时可能会影响其他属性。
-
clip
public void clip()
使用当前路径相交当前的剪辑并将其作为抗锯齿掩码应用到后续渲染操作。 目前的剪辑是common attribute用于在指定的几乎所有的渲染操作Rendering Attributes Table 。此方法本身将仅受Rendering Attributes Table中指定的path属性的影响 。 请注意,路径段最初被添加到当前路径中进行了转换,因此当前的变换不会再次影响这些路径段,但是在
stroke()操作时可能会影响其他属性。
-
isPointInPath
public boolean isPointInPath(double x, double y)如果给定的x,y点在路径内,则返回true。- 参数
-
x- 用于检查的X坐标。 -
y- 用于检查的Y坐标。 - 结果
- 如果给定的点在路径内,则为true,否则为false。
-
clearRect
public void clearRect(double x, double y, double w, double h)用透明颜色值清除画布的一部分。此方法将仅受当前的变换,剪辑和效果的影响。
- 参数
-
x- 矩形左上角的X位置。 -
y- 矩形左上角的Y位置。 -
w- 矩形的宽度。 -
h- 矩形的高度。
-
fillRect
public void fillRect(double x, double y, double w, double h)使用当前的填充油漆填充矩形。该方法将受到Rendering Attributes Table中规定的任何global common或fill属性的影响 。
- 参数
-
x- 矩形左上角的X位置。 -
y- 矩形左上角的Y位置。 -
w- 矩形的宽度。 -
h- 矩形的高度。
-
strokeRect
public void strokeRect(double x, double y, double w, double h)使用当前笔画绘制矩形。该方法将受到Rendering Attributes Table中规定的任何global common或stroke属性的影响 。
- 参数
-
x- 矩形左上角的X位置。 -
y- 矩形左上角的Y位置。 -
w- 矩形的宽度。 -
h- 矩形的高度。
-
fillOval
public void fillOval(double x, double y, double w, double h)使用当前的填充油漆填充椭圆。此方法将受到Rendering Attributes Table中规定的任何global common或fill属性的影响 。
- 参数
-
x- 椭圆的左上界的X坐标。 -
y- 椭圆的左上界的Y坐标。 -
w- 椭圆中心的宽度。 -
h- 椭圆中心的高度。
-
strokeOval
public void strokeOval(double x, double y, double w, double h)使用当前的行程画笔绘制椭圆形。该方法将受到Rendering Attributes Table中规定的任何global common或stroke属性的影响 。
- 参数
-
x- 椭圆的左上界的X坐标。 -
y- 椭圆的左上界的Y坐标。 -
w- 椭圆中心的宽度。 -
h- 椭圆中心的高度。
-
fillArc
public void fillArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)使用当前的填充油漆填充弧。 AnullArcType或非正的宽度或高度将导致render命令被忽略。该方法将受到Rendering Attributes Table中规定的任何global common或fill属性的影响 。
- 参数
-
x- 弧的X坐标。 -
y- 弧的Y坐标。 -
w- 弧的宽度。 -
h- 弧的高度。 -
startAngle- 圆弧的起始角度,以度为单位。 -
arcExtent- 弧度的角度范围。 -
closure- 封闭类型(Round,Chord,Open)或null。
-
strokeArc
public void strokeArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)使用当前笔画绘制弧。 AnullArcType或非正的宽度或高度将导致render命令被忽略。该方法将受到Rendering Attributes Table中规定的任何global common或stroke属性的影响 。
- 参数
-
x- 弧的X坐标。 -
y- 弧的Y坐标。 -
w- 弧的宽度。 -
h- 弧的高度。 -
startAngle- 圆弧的起始角度,以度为单位。 -
arcExtent- arcExtent弧的角度范围为度。 -
closure- 封闭类型(Round,Chord,Open)或null
-
fillRoundRect
public void fillRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)使用当前的填充油漆填充圆角矩形。该方法将受到Rendering Attributes Table中规定的任何global common或fill属性的影响 。
- 参数
-
x- 椭圆的左上边界的X坐标。 -
y- 椭圆的左上界的Y坐标。 -
w- 椭圆中心的宽度。 -
h- 椭圆中心的高度。 -
arcWidth- 矩形角的弧宽。 -
arcHeight- 矩形角的弧高。
-
strokeRoundRect
public void strokeRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)使用当前笔画绘制一个圆角矩形。该方法将受到Rendering Attributes Table中规定的任何global common或stroke属性的影响 。
- 参数
-
x- 椭圆的左上界的X坐标。 -
y- 椭圆的左上界的Y坐标。 -
w- 椭圆中心的宽度。 -
h- 椭圆中心的高度。 -
arcWidth- 矩形角的弧宽。 -
arcHeight- 矩形角的圆弧高度。
-
strokeLine
public void strokeLine(double x1, double y1, double x2, double y2)使用当前笔画绘制线条。该方法将受到Rendering Attributes Table中规定的任何global common或stroke属性的影响 。
- 参数
-
x1- 行的起始点的X坐标。 -
y1- 线的起始点的Y坐标。 -
x2- 线的终点的X坐标。 -
y2- 线的终点的Y坐标。
-
fillPolygon
public void fillPolygon(double[] xPoints, double[] yPoints, int nPoints)使用当前设置的填充油漆填充具有给定点的多边形。 任何数组的值为null将被忽略,不会绘制任何内容。此方法将被任何的影响global common , fill ,或Fill Rule属性作为指定Rendering Attributes Table 。
- 参数
-
xPoints- 包含多边形点的x坐标的数组或空值。 -
yPoints- 包含多边形点的y坐标或空值的数组。 -
nPoints- 创建多边形的点数。
-
strokePolygon
public void strokePolygon(double[] xPoints, double[] yPoints, int nPoints)使用当前设置的笔画绘制使用给定点绘制多边形。 任何数组的值为null将被忽略,不会绘制任何内容。该方法将受到Rendering Attributes Table中规定的任何global common或stroke属性的影响 。
- 参数
-
xPoints- 包含多边形点的x坐标的数组或空值。 -
yPoints- 包含多边形点的y坐标或空值的数组。 -
nPoints- 使多边形的点数。
-
strokePolyline
public void strokePolyline(double[] xPoints, double[] yPoints, int nPoints)使用当前设置的stroke paint属性来绘制具有给定点的折线。 任何数组的值为null将被忽略,不会绘制任何内容。该方法将受到Rendering Attributes Table中规定的任何global common或stroke属性的影响 。
- 参数
-
xPoints- 包含折线点的x坐标的数组或空值。 -
yPoints- 包含折线点的y坐标或空值的数组。 -
nPoints- 使折线的点数。
-
drawImage
public void drawImage(Image img, double x, double y)
使用给定图像的宽度和高度在给定的x,y位置绘制图像。 一个null图像值或仍在进行中的图像将被忽略。该方法将受到Rendering Attributes Table中规定的任何global common属性的影响 。
- 参数
-
img- 要绘制的图像或null。 -
x- 图像左上方目的地的X坐标。 -
y- 图像左上方目的地的Y坐标。
-
drawImage
public void drawImage(Image img, double x, double y, double w, double h)
将图像绘制到画布的给定目标矩形中。 图像被缩放以适应目的地直角。 Anull图像值或仍在进行中的图像将被忽略。该方法将受到Rendering Attributes Table中规定的任何global common属性的影响 。
- 参数
-
img- 要绘制的图像或null。 -
x- 图像左上方目的地的X坐标。 -
y- 图像左上方目的地的Y坐标。 -
w- 目标矩形的宽度。 -
h- 目标矩形的高度。
-
drawImage
public void drawImage(Image img, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)
将给定图像的指定源矩形绘制到Canvas的给定目标矩形。 一个null图像值或仍在进行中的图像将被忽略。该方法将受到Rendering Attributes Table中规定的任何global common属性的影响 。
- 参数
-
img- 要绘制的图像或null。 -
sx- 源矩形的X坐标位置。 -
sy- 源矩形的Y坐标位置。 -
sw- 源矩形的宽度。 -
sh- 源矩形的高度。 -
dx- 目标矩形的X坐标位置。 -
dy- 目标矩形的Y坐标位置。 -
dw- 目标矩形的宽度。 -
dh- 目标矩形的高度。
-
getPixelWriter
public PixelWriter getPixelWriter()
返回一个PixelWriter对象,可用于修改与此GraphicsContext关联的Canvas的像素。 返回对象中的PixelWriter方法中的所有坐标将在设备空间中,因为它们直接引用像素,并且在使用此对象修改像素时不会应用其他渲染属性。- 结果
-
用于修改
PixelWriter的像素的Canvas
-
setEffect
public void setEffect(Effect e)
设置在下一次绘图调用后应用的效果,或设置为禁用效果的效果。 目前的效果是common attribute用于在指定的几乎所有的渲染操作Rendering Attributes Table 。- 参数
-
e- 使用的效果,或禁用效果为null
-
getEffect
public Effect getEffect(Effect e)
获取下一次绘图调用后应用的效果的副本。 空返回值意味着在后续呈现调用之后不会应用任何效果。 目前的效果是common attribute用于在指定的几乎所有的渲染操作Rendering Attributes Table 。- 参数
-
e- 一个Effect对象,可用于存储当前效果的副本,如果它是兼容类型 - 结果
- 用于所有渲染调用的当前效果,如果没有当前效果,则为null
-
applyEffect
public void applyEffect(Effect e)
将给定的效果应用于画布的整个边界,并将结果存储回同一个画布。 Anull值将被忽略。 该效果将被应用而没有任何其他渲染属性和身份坐标变换下。 由于效果应用于画布的整个边界,因此某些效果可能会产生令人困惑的结果,例如即使仅将画布的一部分渲染到并且将不可见,除非使用负偏移使反射回到视图。- 参数
-
e- 应用于整个目的地的效果或null。
-
-