我正在尝试绘制一个带有虚线边框的圆。我已经试过了:
Shape shape = new Shape()
..graphics.beginPath()
..graphics.circle( 50 , 50, 50 )
..graphics.closePath()
..graphics.strokePattern(new GraphicsPattern.repeat(new BitmapData.fromImageElement(new HTML.ImageElement(src: "img/dash.png"))))
..addTo(stage);
}
但是圆圈没有显示。似乎strokePattern行打破了我的代码。任何想法如何解决这个问题?
最佳答案
我想出了这个解决方案:
void _addDottedCircle(double x, double y, int radius) {
List<double> xCoords = new List<double>();
List<double> yCoords = new List<double>();
for (int i = 0; i < radius; i++) {
xCoords.add( radius * cos(2 * PI * i / radius) + x);
yCoords.add( radius * sin(2 * PI * i / radius) + y);
}
for (int i = 0; i < radius; i++) {
new Shape()
..graphics.beginPath()
..graphics.circle(xCoords[i], yCoords[i], 1)
..graphics.closePath()
..graphics.fillColor(lightgreen)
..addTo(stage);
}
}
关于canvas - 如何在Dart中使用StageXL绘制虚线圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22721870/