HarmonyOS 根据圆心坐标绘制圆问题
private settingsRound: RenderingContextSettings | null = null
private contextRound: CanvasRenderingContext2D | null = null
@State centersX:Array<number> = []
@State centersY:Array<number> = []
if (this.model.showState==1) {
this.centersX = []
this.centersY = []
this.settingsRound = new RenderingContextSettings(true)
this.contextRound = new CanvasRenderingContext2D(this.settingsRound)
if (this.contextLine && this.contextRound){
Logger.info('Safe', '-----------------------清空画布' );
this.contextLine.clearRect(0,0,this.mWidth,this.mHeight)
this.contextRound.clearRect(0,0,this.mWidth,this.mHeight)
}
//画圆
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.contextRound)
.width('100%')
.height('100%')
.backgroundColor($r('app.color.color_00000000'))
.onReady(() =>{
this.centersX.forEach((value,index) => {
this.contextRound?.beginPath()
if(this.contextRound){
this.contextRound.strokeStyle = this.roundbgcolor(index)//设置线条的颜色。
this.contextRound.fillStyle = this.roundbgcolor(index)//绘制的填充色。
}
this.contextRound?.moveTo(this.centersX[index], this.centersY[index])
this.contextRound?.arc(this.centersX[index], this.centersY[index], 2.5, 0, 7)
this.contextRound?.fill()
this.contextRound?.stroke()
})
})
}
.width('100%')
.height('100%')
首次进入可正常绘制圆,但当切换页面时centersX、centersY的值发生了变化,然后就画不出圆了。
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HarmonyOS 如何根据圆心坐标画实心圆
137浏览 • 1回复 待解决
HarmonyOS 如何根据圆心坐标连接曲线
127浏览 • 1回复 待解决
HarmonyOS @ohos.graphics.drawing绘制模块中的RenderNode怎么制定坐标绘制图片
218浏览 • 1回复 待解决
HarmonyOS 如何绘制实心圆,DrawingRenderingContext可以吗?
234浏览 • 1回复 待解决
Polyline组件绘制坐标不准确
2379浏览 • 1回复 待解决
绘制手动生成线条的坐标系
924浏览 • 1回复 待解决
HarmonyOS 线条绘制获取坐标点时,如何获取到当前空间的右下角坐标
239浏览 • 1回复 待解决
HarmonyOS 是否支持根据绘制逻辑生成imagedata
184浏览 • 1回复 待解决
#鸿蒙通关秘籍#如何使用鸿蒙OS绘制一个带虚线环的圆?
215浏览 • 1回复 待解决
HarmonyOS drawCircle画空心圆和实心圆
102浏览 • 1回复 待解决
HarmonyOS 根据坐标数据渲染的位置与实际情况不符
126浏览 • 1回复 待解决
相机对焦支持传入一个坐标然后相机根据这个坐标进行对焦吗
1750浏览 • 1回复 待解决
#鸿蒙通关秘籍#在Canvas上如何绘制基本形状如矩形和圆?
271浏览 • 1回复 待解决
HarmonyOS 在 Canvas 上绘制一张图片和一千左右个圆会卡顿
211浏览 • 1回复 待解决
HarmonyOS使用Canvas自定义绘制内容后,如何根据onTouch事件动态更新绘制的内容?
564浏览 • 1回复 待解决
同心圆及点击动画,ArkTs如何画同心圆以及同心圆的点击动画效果
1376浏览 • 1回复 待解决
HarmonyOS 底部导航绘制问题
443浏览 • 1回复 待解决
HarmonyOS 将字符串文本,根据选择的字体库,绘制成位图
217浏览 • 1回复 待解决
HarmonyOS 获取定位和逆地理时坐标系问题
343浏览 • 1回复 待解决
HarmonyOS 获取控件坐标
308浏览 • 1回复 待解决
HarmonyOS 系统定位经纬度坐标系转换问题
322浏览 • 1回复 待解决
HarmonyOS 关于使用bitmap图像绘制相关问题
221浏览 • 1回复 待解决
HarmonyOS Canvas绘制image的API相关问题
240浏览 • 1回复 待解决
harmony surfaceProvider绘制不显示问题
10347浏览 • 4回复 待解决
HarmonyOS 绘制组件和画布组件选择问题
544浏览 • 1回复 待解决
可以将变化的数据通过@Watch监听,同时绑定一个自己封装的draw()方法,当数据刷新时就会调用Watch绑定的方法执行绘制逻辑,参考代码: