Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctx.drawImage 方法与新版 canvas api 不一致 #111

Closed
hcl2020 opened this issue Mar 30, 2020 · 4 comments
Closed

ctx.drawImage 方法与新版 canvas api 不一致 #111

hcl2020 opened this issue Mar 30, 2020 · 4 comments
Labels
WIP Working in progress

Comments

@hcl2020
Copy link

hcl2020 commented Mar 30, 2020

Canvas 实例通过 SelectorQuery 获取,
ctx.drawImage方法的 imageResource 实际不支持字符串类型。

Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'
@hcl2020 hcl2020 closed this as completed Mar 30, 2020
@hcl2020 hcl2020 reopened this Mar 30, 2020
@SgLy
Copy link
Contributor

SgLy commented Mar 30, 2020

定义里提供的 drawImage 接口和获取路径还是旧版的,通过 wx.createCanvasContext 获取的;新版的通过 getContext 获取的暂时还没有支持,现在应该返回的是 any。实际使用的时候有遇到问题吗?

@hcl2020
Copy link
Author

hcl2020 commented Mar 30, 2020

是的,目前返回的any。
目前在使用时需要手动指定类型

let canvas = this.getCanvas() as HTMLCanvasElement & WechatMiniprogram.Canvas;
const ctx = canvas.getContext('2d')!;
const img = canvas.createImage() as CanvasImageSource;
ctx.drawImage(img, 0, 0, 100, 100);

目前官方文档已经不推荐使用 wx.createCanvasContext 接口,建议 getContext 相关的类型能够完善一下。

@SgLy
Copy link
Contributor

SgLy commented Apr 3, 2020

正在补了,wechat-miniprogram/minigame-api-typings#3 里也有跟踪

@SgLy SgLy added the WIP Working in progress label Apr 3, 2020
@SgLy SgLy pinned this issue Jan 15, 2021
@KuuBee
Copy link

KuuBee commented May 9, 2022

小程序已经原生支持ts了,canvas类型有很多问题,请问有什么进展吗。

@SgLy SgLy closed this as completed in 82d28b6 Jun 9, 2023
SgLy added a commit that referenced this issue Jun 9, 2023
feat: update to v2.32.2 & add canvas rendering context typings. close #111
@SgLy SgLy unpinned this issue Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Working in progress
Projects
None yet
Development

No branches or pull requests

3 participants