已绑定手机
|
globalAlpha
代码
- // xxx.ets
- @Entry
- @Component
- struct GlobalAlpha {
- 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.fillStyle = 'rgb(0,0,255)'
- this.context.fillRect(0, 0, 50, 50)
- this.context.globalAlpha = 0.4
- this.context.fillStyle = 'rgb(0,0,255)'
- this.context.fillRect(50, 50, 50, 50)
- })
- }
- .width('100%')
- .height('100%')
- }
- }
复制代码
效果
效果
lineDashOffset
代码
- // xxx.ets
- @Entry
- @Component
- struct LineDashOffset {
- 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.arc(100, 75, 50, 0, 6.28)
- this.context.setLineDash([10,20])
- this.context.lineDashOffset = 10.0
- this.context.stroke()
- })
- }
- .width('100%')
- .height('100%')
- }
- }
复制代码效果
|
|