关于HarmonyOS 鸿蒙Next画图

发布于 1周前 作者 wuwangju 最后一次编辑是 5天前 来自 鸿蒙OS

关于HarmonyOS 鸿蒙Next画图

1、根据路径画文字,相当于安卓的drawTextOnPath方法,见附件 2、drawArc这个方法达不到自己想要的结果 this.context.canvas.drawArc(this.firstRect, 0, 72); 是想画1/5圆。这种好像我实现不了。 1、麻烦给出具体方法 提供一段:drawArc代码

this.context.canvas.attachBrush(this.firstActivePaint); this.context.canvas.drawArc(this.firstRect, 0, 72); this.context.canvas.detachPen(); this.context.canvas.attachBrush(this.secondActivePaint); this.context.canvas.drawArc(this.secondRect, 0, 72); this.context.canvas.detachPen(); this.context.canvas.attachBrush(this.thirdActivePaint); this.context.canvas.drawArc(this.thirdRect, 0, 72); this.context.canvas.detachPen();</code

2 回复
可以试一下moveTo和arc一起使用,请参考以下demo;文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-canvasrenderingcontext2d-V5#arc

@Entry

@Component

struct Page {

&nbsp; private settings: RenderingContextSettings = <span class="hljs-keyword">new</span> RenderingContextSettings(<span class="hljs-literal">true</span>)

&nbsp; private context: CanvasRenderingContext2D = <span class="hljs-keyword">new</span> CanvasRenderingContext2D(<span class="hljs-keyword">this</span>.settings)

&nbsp; build() {

&nbsp;&nbsp;&nbsp; Column() {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas(<span class="hljs-keyword">this</span>.context)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .width(<span class="hljs-string">'100%'</span>)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .height(<span class="hljs-string">'100%'</span>)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .backgroundColor(<span class="hljs-string">'#F5DC62'</span>)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .onReady(() =&gt; {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.beginPath();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.moveTo(<span class="hljs-number">100</span>, <span class="hljs-number">200</span>)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.arc(<span class="hljs-number">200</span>, <span class="hljs-number">200</span>, <span class="hljs-number">100</span>, <span class="hljs-built_in">Math</span>.PI / <span class="hljs-number">2</span>, <span class="hljs-built_in">Math</span>.PI);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.stroke();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })

&nbsp;&nbsp;&nbsp; }

&nbsp; }

}

以下demo或许可以帮助您解决问题:


@Entry

@Component

struct CanvasExample {

&nbsp; private context: DrawingRenderingContext = <span class="hljs-keyword">new</span> DrawingRenderingContext()

&nbsp; build() {

&nbsp;&nbsp;&nbsp; Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas(<span class="hljs-keyword">this</span>.context)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .width(<span class="hljs-string">'100%'</span>)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .height(<span class="hljs-string">'100%'</span>)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .backgroundColor(<span class="hljs-string">'#ffff00'</span>)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .onReady(() =&gt; {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.canvas.drawArc({left:<span class="hljs-number">50</span>, top:<span class="hljs-number">100</span>, right:<span class="hljs-number">200</span>, bottom:<span class="hljs-number">200</span>}, <span class="hljs-number">180</span>, <span class="hljs-number">180</span>);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.canvas.drawArc({left:<span class="hljs-number">100</span>, top:<span class="hljs-number">300</span>, right:<span class="hljs-number">400</span>, bottom:<span class="hljs-number">400</span>}, <span class="hljs-number">180</span>, <span class="hljs-number">180</span>);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.canvas.drawArc({left:<span class="hljs-number">150</span>, top:<span class="hljs-number">500</span>, right:<span class="hljs-number">600</span>, bottom:<span class="hljs-number">600</span>}, <span class="hljs-number">180</span>, <span class="hljs-number">180</span>);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.canvas.drawArc({left:<span class="hljs-number">200</span>, top:<span class="hljs-number">700</span>, right:<span class="hljs-number">800</span>, bottom:<span class="hljs-number">800</span>}, <span class="hljs-number">180</span>, <span class="hljs-number">180</span>);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.canvas.drawArc({left:<span class="hljs-number">250</span>, top:<span class="hljs-number">900</span>, right:<span class="hljs-number">1000</span>, bottom:<span class="hljs-number">1000</span>}, <span class="hljs-number">180</span>, <span class="hljs-number">180</span>);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="hljs-keyword">this</span>.context.invalidate()

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })

&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp; .width(<span class="hljs-string">'100%'</span>)

&nbsp;&nbsp;&nbsp; .height(<span class="hljs-string">'100%'</span>)

&nbsp; }

}

此外,关于“text.ParagraphBuilder里的paintOnPath如何关联文本”与此单问题无关联,基于工单的问题追踪和管理,麻烦您新提一个问题单,我们这边也好定位问题和及时上升,感谢您的理解~

关于“text.ParagraphBuilder里的paintOnPath如何关联文本”的问题也可以参考该文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/text-js-guidelines-V5

关于HarmonyOS 鸿蒙Next画图功能,以下是一些专业解答:

HarmonyOS 鸿蒙Next以其强大的性能和独特的分布式架构,为画图应用提供了广阔的平台。在鸿蒙Next系统上,画图应用能够充分利用系统的特性,实现与鸿蒙设备的深度适配与无缝对接,为用户带来流畅的绘画体验。

在画图功能方面,鸿蒙Next支持丰富多样的画笔工具,包括铅笔、水彩笔、油画笔等,且每种画笔都拥有多种可调节的参数,如粗细、透明度、压力敏感度等,满足用户不同的创作需求。此外,图层功能也是鸿蒙Next画图应用的一大亮点,用户可以创建多个图层,独立进行编辑、绘制、移动、隐藏或删除操作,极大地拓展了绘画创作的边界。

鸿蒙Next还提供了智能绘画辅助功能,如智能形状识别、透视辅助线、对称绘画模式等,这些功能如同用户身边的绘画小助手,助力用户更高效地完成创作。

总之,HarmonyOS 鸿蒙Next为画图应用提供了强大的技术支持和丰富的功能体验。如果在使用过程中遇到问题,建议查阅官方文档或联系官网客服进行解决。官网地址是:https://www.itying.com/category-93-b0.html

回到顶部