We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
leafer的Canvas元素改变宽高后,获取imageData很慢,要100多毫秒
const { Canvas } = LeaferUI const canvas = new Canvas({ width: 10000, height: 10000 }) canvas.width = 700 canvas.height = 300 console.time("getImageData") const imageData = canvas.context.getImageData(0, 0, 700, 300) console.timeEnd("getImageData") // getImageData: 102.496826171875 ms
原生canvas只需要4毫秒
const canvas = document.createElement("canvas") canvas.width = 10000 canvas.height = 10000 const ctx = canvas.getContext("2d") canvas.width = 700 canvas.height = 300 console.time("getImageData") const imageData = ctx.getImageData(0, 0, 700, 300) console.timeEnd("getImageData") // getImageData: 3.77783203125 ms
延迟一秒获取,速度就恢复正常了,5-10毫秒,这是为什么呢
const { Canvas } = LeaferUI const canvas = new Canvas({ width: 10000, height: 10000 }) canvas.width = 700 canvas.height = 300 setTimeout(() => { console.time("getImageData") const imageData = canvas.context.getImageData(0, 0, 700, 300) console.timeEnd("getImageData") // getImageData: 10.425048828125 ms }, 1000)
因为我需要处理canvas的像素,可能要不断的getImageData,100多毫秒很慢啊,怎样解决呢
The text was updated successfully, but these errors were encountered:
Canvas 增加 contextSettings.willReadFrequently 配置试试
https://www.leaferjs.com/ui/reference/display/Canvas.html#contextsettings-icanvasrenderingcontext2dsettings
Sorry, something went wrong.
Canvas 增加 contextSettings.willReadFrequently 配置试试 https://www.leaferjs.com/ui/reference/display/Canvas.html#contextsettings-icanvasrenderingcontext2dsettings
不好使,已经用别的方法解决了
No branches or pull requests
leafer的Canvas元素改变宽高后,获取imageData很慢,要100多毫秒
原生canvas只需要4毫秒
延迟一秒获取,速度就恢复正常了,5-10毫秒,这是为什么呢
因为我需要处理canvas的像素,可能要不断的getImageData,100多毫秒很慢啊,怎样解决呢
The text was updated successfully, but these errors were encountered: