HarmonyOS 使用Canvas时发现在重新绘制时有些问题

使用CanvasRenderingContext2D通过path绘制圆角矩形,在更新重新绘制时,发现圆角矩形之间有一条下划线。

代码如下:

private currPosition = 0

@State
private indicatorConfig: IndicatorConfig = new IndicatorConfig(5, 2, '#BF333333', '#33333333')

build() {
  if (this) {
    Column() {
      Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
        RectFIndicator({ indicatorConfig: this.indicatorConfig })
      }
      .margin({ bottom: 50, top: 50 })

      Row() {
        Text('滑动')
      }
      .width(50)
      .height(50)
      .onClick((event) => {
        this.currPosition++
        if (this.currPosition > 4) {
          this.currPosition = 0
        }
        this.indicatorConfig.setCurrentPosition(this.currPosition)
      })
    }
  }
}
  • 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.
HarmonyOS
2024-12-25 13:08:44
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

clearRect效率不如reset好,尤其是频繁重绘场景。所以更推荐使用reset接口实现,可参考如下示例:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-canvasrenderingcontext2d-V5#reset12

分享
微博
QQ
微信
回复
2024-12-25 15:51:00
相关问题
如何操作canvas重新绘制
1930浏览 • 1回复 待解决
HarmonyOS 如何使用canvas绘制虚线
624浏览 • 1回复 待解决
HarmonyOS Canvas绘制image的API相关问题
779浏览 • 1回复 待解决
如何使用canvas绘制圆角矩形
1257浏览 • 1回复 待解决
HarmonyOS Canvas中关于绘制图片问题
1053浏览 • 1回复 待解决
HarmonyOS Canvas绘制圆角
932浏览 • 1回复 待解决
HarmonyOS Canvas绘制曲线相关
789浏览 • 1回复 待解决
HarmonyOS Canvas绘制圆角矩形
1037浏览 • 1回复 待解决
HarmonyOS Canvas绘制内容如何更新
645浏览 • 1回复 待解决
Canvas绘制内容如何动态更新
2820浏览 • 1回复 待解决
HarmonyOS canvas如何绘制成图片导出
735浏览 • 1回复 待解决
HarmonyOS 如何在Canvas中直接绘制SVG?
784浏览 • 1回复 待解决