我第一次截屏 截半屏是正常的, 然后我再截屏, 截半屏, 就出现了 两张图片混合的情况
第二次, 同样的截屏方法, 然后显示截屏图片的 sprite 也是同一个
使用cocos 官方的 截屏方法, 是不是要先销毁掉第一次的 rendertexture?
我第一次截屏 截半屏是正常的, 然后我再截屏, 截半屏, 就出现了 两张图片混合的情况
第二次, 同样的截屏方法, 然后显示截屏图片的 sprite 也是同一个
肯定要清空数据的啊
不要使用官方的, 官方的有问题
动态创建camera 用完销毁掉就可以了
好的, 试试
好像不行, 我设置成预制体了, 动态生成, 销毁 一样
let node = new cc.Node();
node.parent = cc.director.getScene();
node.width = cc.view.getVisibleSize().width;
node.height = cc.view.getVisibleSize().height;
console.log(`!!!!!! capture width:${node.width} node.height:${node.height}`);
//注意了,这里要讲节点的位置改为右上角,不然截图只有1/4
node.x = node.width/2;
node.y = node.height/2;
let camera = node.addComponent(cc.Camera);
// 设置你想要的截图内容的 cullingMask
camera.cullingMask = 0xffffffff;
// 新建一个 RenderTexture,并且设置 camera 的 targetTexture 为新建的 RenderTexture,这样 camera 的内容将会渲染到新建的 RenderTexture 中。
let texture = new cc.RenderTexture();
texture.initWithSize(node.width, node.height, cc.gfx.RB_FMT_S8);
camera.targetTexture = texture;
// 渲染一次摄像机,即更新一次内容到 RenderTexture 中
//node.parent.scaleY = -1;
// 截图默认是y轴反转的,渲染前需要将图像倒过来,渲染完倒回去
camera.render();
//node.parent.scaleY = 1;
// 这样我们就能从 RenderTexture 中获取到数据了
let data = texture.readPixels();
let {width} = texture;
let {height} = texture;
let picData = this.filpYImage(data, width, height);
//做个截屏的动作
//this.captureAction(node, width, height);
let fileDir = `${jsb.fileUtils.getWritablePath()}cocosCapture`;
let fileName = `${this.format(new Date().getTime())}.png`;
let fullPath = `${fileDir}/${fileName}`;
if (!jsb.fileUtils.isDirectoryExist(fileDir)) {
jsb.fileUtils.createDirectory(fileDir);
}
if (jsb.fileUtils.isFileExist(fullPath)) {
jsb.fileUtils.removeFile(fullPath);
}
let success = jsb.saveImageData(picData, width, height, fullPath);
node.destroy();
if (success) {
// eslint-disable-next-line no-console
console.log('截屏成功,fullPath,width,height = ', fullPath, width, height);
captureNative(fullPath);
}
else {
cc.error('截屏失败!');
}
我搞错了, 其实没问题, 是我自己的图片截图了之后,显示在屏幕中间, 然后第二次截图的时候截进去了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
请问楼主,截屏后的图片,会很模糊吗?我也是用官方文档里的方法截屏,但是截出来的图很模糊
是不是缩放比例问题, 我的不是很模糊, 但是字体会变色
该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。