藍山帝景
2022-09-29 16:38:08
我使用“閱讀像素()”來閱讀網頁畫布上的像素顏色。我無法讀取像素時,當反化設置為 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讀取像素顏色,抗鋸齒=假嗎?對不起,我的英語不好,謝謝。
1 回答

HUX布斯
TA貢獻1876條經驗 獲得超6個贊
在代碼段中發布最小存儲庫(如果需要調試幫助)
這在蘋果和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);
添加回答
舉報
0/150
提交
取消