HarmonyOS canvas Path 椭圆无法闭合路径

非椭圆路径

const path=new Path2D()
path.rect(80, 80, 50, 50)
path.arc(150, 150, 50, 0, 2 * Math.PI, false)
path.rect(0, 0, 50, 50)
this.context.fillStyle = 'red'
this.context.fill(path)

椭圆路径

const path=new Path2D()
path.rect(80, 80, 50, 50)
path.ellipse(200, 200, 50, 100, 0, Math.PI * 1, Math.PI*2)
path.rect(0, 0, 50, 50)
this.context.fillStyle = 'red'
this.context.fill(path)

详情请看图片

HarmonyOS canvas Path 椭圆无法闭合路径 -鸿蒙开发者社区

HarmonyOS canvas Path 椭圆无法闭合路径 -鸿蒙开发者社区

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

示例参考如下:

react绘制完成后,执行path2Db.moveTo(xxx,xxx)

如:

// xxx.ets
@Entry
@Component
struct Index {
  private settings: RenderingContextSettings = new RenderingContextSettings(true)
  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
  private path2Db: Path2D = new Path2D()

  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
      Canvas(this.context)
        .width('100%')
        .height('100%')
        .backgroundColor('#ffff00')
        .onReady(() =>{
          this.path2Db.rect(20, 20, 100, 100);
          this.context.stroke(this.path2Db)

          this.path2Db.moveTo(200, 200)
          this.path2Db.ellipse(200, 200, 50, 100, 0, Math.PI * 1, Math.PI * 3)
          this.context.stroke(this.path2Db)

          this.path2Db.moveTo(0, 0)
          this.path2Db.rect(0, 0, 50, 50)
          this.context.stroke(this.path2Db)
        })
    }
    .width('100%')
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS webview无法加载file协议路径
193浏览 • 1回复 待解决
HarmonyOS 应用沙盒路径视频无法播放
260浏览 • 1回复 待解决
HarmonyOS Path 是否支持矩阵变换
101浏览 • 1回复 待解决
HarmonyOS window.setUIContent 参数path问题
99浏览 • 1回复 待解决
HarmonyOS 下载报错Download File Path Valid
1020浏览 • 1回复 待解决
HarmonyOS Canvas怎么刷新
194浏览 • 1回复 待解决
HarmonyOS Canvas 实现动画
228浏览 • 1回复 待解决
HarmonyOS Canvas绘制圆角
179浏览 • 1回复 待解决
HarmonyOS canvas画图问题
147浏览 • 1回复 待解决