抗锯齿=假阻碍读取在MacOS上使用野生动物园的像素

我使用“阅读像素()”来阅读网页画布上的像素颜色。我无法读取像素时,当反化设置为 false 以获取上下文选项。我可以在野生动物园/ MacOS,铬,火狐和野生动物园/ iOS上阅读以下行。

const gl = canvas.getContext('webgl', {'preserveDrawingBuffer':true, 'antialias':true});

但是我无法在野生动物园/ MacOS上阅读以下内容,但可以在铬,火狐和野生动物园/ iOS上阅读。

const gl = canvas.getContext('webgl', {'preserveDrawingBuffer':true, 'antialias':false});

添加行:控制台输出 Uint8 数组 [0, 0, 0, 0],但像素有颜色。

是不是有问题 与 Safari/MacOS 或我是否需要任何选项的野生动物园/MacOS ?我可以用苹果浏览器/MacOS读取像素颜色,抗锯齿=假吗?

对不起,我的英语不好,谢谢。


蓝山帝景
浏览 62回答 1
1回答

HUX布斯

在代码段中发布最小存储库(如果需要调试帮助)这在苹果和iPhone上的野生动物园中适用于我function test(antialias) {  const gl = document.createElement('canvas').getContext('webgl', {    preserveDrawingBuffer: true,    antialias,  });  gl.clearColor(1, 0.5, 0.25, 1);  gl.clear(gl.COLOR_BUFFER_BIT);  const pixel = new Uint8Array(4);  gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);  log(JSON.stringify(gl.getContextAttributes(), null, 2));  log('pixel:', pixel);}function log(...args) {  const elem = document.createElement('pre');  elem.textContent = args.join(' ');  document.body.appendChild(elem);}test(false);test(true);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript