小程序webglCanvas在iOS中获取图像信息是透明图问题
这段代码在安卓手机上可以正常获取webgl上面的图像信息,但是iOS为空白图。官方可以随便写一个demo试一下 saveImg: function () { if (!this.data.modelType) {//没有识别不能打卡 return } else { wx.showToast({ title: '打卡成功', icon: 'success', duration: 800 }) setTimeout(() => { let self = this var gl = this.canvas.getContext("webgl", {//获取canvas preserveDrawingBuffer: true }); console.log('gl获取内容', gl); const { drawingBufferWidth: width, drawingBufferHeight: height } = gl; const pixels = new Uint8Array(width * height * 4); gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels); flip(pixels, width, height, 4);//旋转获取的图片数据 console.log('像素数据', new Uint8ClampedArray(typedArrayToBuffer(pixels))); wx.canvasPutImageData({ canvasId: "myCanvas", data: new Uint8ClampedArray(typedArrayToBuffer(pixels)), x: 0, y: 0, width: width, height: height, success(res) { console.log('canvasPutImage success', res); save(); }, fail(err) { console.log('canvasPutImage err', err); } }, self); function save() { wx.canvasToTempFilePath({ x: 0, y: 0, width: width, height: height, destWidth: width, destHeight: height, canvasId: 'myCanvas', success(res) { console.log(res.tempFilePath); this.setData({ saveImg: res.tempFilePath }) if (res.tempFilePath) { // wx.navigateTo({//获得图片跳转 // url: '/pages/index2/index?imgUrl=' + res.tempFilePath, // }) } }, fail(res) { console.log(res); } }, self) } function typedArrayToBuffer(array) { return array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset) } }, 800) } },