`

JavaFX学习之Canvas

阅读更多
   Canvas and GraphicsContext  Canvas相当 一块画布,GraphicsContext相当于画笔,使用GraphicsContext 在canvas上面画。
        Canvas canvas = new Canvas();  //构建画布
		canvas.setWidth(400);
		canvas.setHeight(400);
		GraphicsContext gc = canvas.getGraphicsContext2D(); //获取画笔
		gc.setFill(Color.RED);
		gc.setStroke(Color.BLUE);
		gc.strokeOval(10,10,30, 60);
        gc.fillOval(50, 10, 30, 60);

Canvas的属性:
height ,width  宽高
方法:
getGraphicsContext2D() //获取画笔

Canvas没什么方法。
GraphicsContext 一些方法
setFill(Paint p) 设置内容颜色
setStroke(Paint p)  设置线条颜色
fill() 用当前的fill颜色画路径
//画内容
strokeOval(double x, double y, double w, double h)画椭圆x,y坐标,w,h宽高,线条画
fillOval(double x, double y, double w, double h) 画椭圆,填充画。
strokeLine(double x1, double y1, double x2, double y2) 画线条,第一个点坐标,第二个点坐标。
strokeRect(double x, double y, double w, double h) 画矩形,x,y坐标,w,h宽高
strokeRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)画矩形,x,y坐标,w,h宽高,arcWidth,arcHeight矩形角的弧宽高
strokePolyline(double[] xPoints, double[] yPoints, int nPoints)x,y坐标集合,一一对应,几个点。不会连成封闭的多边形 
strokePolygon(double[] xPoints, double[] yPoints, int nPoints) 
clearRect(double x, double y, double w, double h)清除一块矩形。在已经画好的上面清除。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics