[文章]HarmonyOS/OpenHarmony应用开发-ArkTS画布组件CanvasRenderingContext2D对象(十四)

阅读量0
0
1

createPattern
createPattern(image: ImageBitmap, repetition: string | null): CanvasPattern | null
通过指定图像和重复方式创建图片填充的模板。
HarmonyOS/OpenHarmony应用开发-ArkTS画布组件(十四)-开源基础软件社区
示例:

.// xxx.ets
.@Entry
.@Component
.struct CreatePattern {
.  private settings: RenderingContextSettings = new RenderingContextSettings(true)
.  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
.  private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg")
.
.  build() {
.    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
.      Canvas(this.context)
.        .width('100%')
.        .height('100%')
.        .backgroundColor('#ffff00')
.        .onReady(() =>{
.          var pattern = this.context.createPattern(this.img, 'repeat')
.          this.context.fillStyle = pattern
.          this.context.fillRect(0, 0, 200, 200)
.        })
.    }
.    .width('100%')
.    .height('100%')
.  }
.}

HarmonyOS/OpenHarmony应用开发-ArkTS画布组件(十四)-开源基础软件社区
bezierCurveTo
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void
创建三次贝赛尔曲线的路径。
HarmonyOS/OpenHarmony应用开发-ArkTS画布组件(十四)-开源基础软件社区
示例:

.// xxx.ets
.@Entry
.@Component
.struct BezierCurveTo {
.  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(() =>{
.          this.context.beginPath()
.          this.context.moveTo(10, 10)
.          this.context.bezierCurveTo(20, 100, 200, 100, 200, 20)
.          this.context.stroke()
.        })
.    }
.    .width('100%')
.    .height('100%')
.  }

HarmonyOS/OpenHarmony应用开发-ArkTS画布组件(十四)-开源基础软件社区

*附件:HarmonyOSOpenHarmony应用开发-ArkTS画布组件CanvasRenderingContext2D对象(十四)createPattern bezierCurveTo.doc

回帖

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容图片侵权或者其他问题,请联系本站作侵删。 侵权投诉
链接复制成功,分享给好友