Chrome一直打印这个警告:“Canvas2D: 使用getImageData进行多个读取操作时,将willReadFrequently属性设置为true可以更快。” 我检查了代码,在触发警告的地方,您可以看到我已将willReadFrequently属性设置为true。可能问题是什么?在其他地方也有这种警告,但是那里的willReadFrequently属性解决了它。
Chrome 104-108中存在问题。顺便说一句,我在WebWorker中。这可能是一个Chrome错误吗?
const offdesireCtx = offDesire.getContext("2d", { willReadFrequently: true });
if (!offdesireCtx) {
throw new Error("Desired OffscrenCanvas ctx undefined");
}
const offGetCtx = offGet.getContext("2d", { willReadFrequently: true });
if (!offGetCtx) {
throw new Error("Get OffscrenCanvas ctx undefined");
}
var imgd = offdesireCtx.getImageData(0, 0, tileSize, tileSize), pix = imgd.data; //Warning triggers
var imgdGet = offGetCtx.getImageData(0, 0, tileSize, tileSize), pixGet = imgdGet.data; //Warning triggers
canvas.getContext("2d", { willReadFrequently: true )
新代码:canvas.getContext("2d", { willReadFrequently: true })
- Roe