HarmonyOS Path2D的addPath方法报错

Path2D的addPath方法报错不传transform会报错,错误提示:Cannot read property scaleX of undefined。

HarmonyOS
2024-10-17 10:09:38
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

参考代码:

// xxx.ets  
@Entry  
@Component  
struct CanvasExample {  
  private settings: RenderingContextSettings = new RenderingContextSettings(true)  
  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)  
  build() {  
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {  
      Canvas(this.context)  
        .width('100%')  
        .height('100%')  
        .backgroundColor('#ffff00')  
        .onReady(() => {  
          let path = new Path2D();  
          path.moveTo(50, 5);  
          path.lineTo(20, 90);  
          path.lineTo(95, 39);  
          path.lineTo(5, 39);  
          path.lineTo(80, 90);  
          path.closePath();  
          this.context.save()  
          let testPath = new Path2D();  
          testPath.addPath(path);  
          this.context.fillStyle = '#ff0000'  
          this.context.fill(path);  
          this.context.restore()  
        })  
    }  
    .width('100%')  
    .height('100%')  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
分享
微博
QQ
微信
回复
2024-10-17 15:52:11
相关问题
HarmonyOS Matrix2D用法问题
753浏览 • 1回复 待解决
HarmonyOS CanvasRenderingContext2D使用问题
816浏览 • 1回复 待解决
HarmonyOS 下载报错Download File Path Valid
1919浏览 • 1回复 待解决
HarmonyOS cocod2d-x适配问题
689浏览 • 1回复 待解决
ArkGraphics 2D有什么优势?
1164浏览 • 1回复 待解决
使用Drawing进行2d图像绘制
1798浏览 • 1回复 待解决
DevEco编译报错:Invalid JavaScript file path
4674浏览 • 0回复 待解决
XComponent、NativeDrawing实现2D图形绘制
2091浏览 • 1回复 待解决
ArkGraphics 2D都有哪些使用场景?
1670浏览 • 1回复 待解决