收藏
回答

截屏问题

游戏引擎 AppID 操作系统 微信版本 基础库版本
cocos creator wxf2576211d666694d Android 8.0.9 2.19.0

ios和微信开发者工具显示正常 但是android手机上截屏后 透明区显示白边

captureNode2Base64WX(node, isRight = true) { // 初始化渲染纹理 let width = node.width; let height = node.height; let w_h = width / height; let vw_vh = cc.visibleRect.width / cc.visibleRect.height; let _texture = new cc.RenderTexture(); _texture.initWithSize(width, height, cc.gfx.RB_FMT_S8); // 获取canvas画布 let _canvas = wx.createCanvas(); _canvas.width = width; _canvas.height = height; let _ctx = _canvas.getContext('2d'); // 克隆需要渲染的节点 let _content = cc.instantiate(node); _content.parent = cc.Canvas.instance.node; _content.position = cc.v3(0, 0, 0); _content.scale = w_h > vw_vh ? (cc.visibleRect.width / width) + 0.02 : (cc.visibleRect.height / height) + 0.02; if (!isRight) { _content.scaleY *= -1; } let _camera = _content.addComponent(cc.Camera); _camera.backgroundColor = new cc.Color(255, 255, 255, 0); _camera.alignWithScreen = true; _camera.clearFlags = 7; _camera.targetTexture = _texture; _camera.render(_content); // 渲染图片到canvas let data = _texture.readPixels(); let rowBytes = width * 4; for (let row = 0; row < height; row++) { let srow = height - 1 - row; let imageData = _ctx.createImageData(width, 1); let start = srow * width * 4; for (let i = 0; i < rowBytes; i++) { imageData.data[i] = data[start + i]; } _ctx.putImageData(imageData, 0, row); } // 销毁临时节点 _content.destroy(); _texture.destroy(); //let dataURL = _canvas.toDataURL("image/jpg"); // console.log("dataURL:", dataURL); let tempFilePath = _canvas.toTempFilePathSync({ }) //console.log("tempFilePath:", tempFilePath); cc.loader.load(tempFilePath, (err, texture2D) => { if (err) { return; } if (isRight) { this.verletRenderScript.textureList[0] = texture2D; } else { this.verletRenderScript.textureList[1] = texture2D; } this.verletRenderScript._updateMaterial(); this.verletRenderScript.draw(); }); },
回答关注问题邀请回答
收藏
登录 后发表内容