3.4.2 版本Camera截图分享(若干问题)

由于老版本文档中提供的例子、已经跟不上开发组版本的更新速度。在此一起探讨下,新版本中截图和分享如何实现,如何破坑!抛砖引玉!
需求:1、截图展示。2、保存本地PNG
下面把测试使用的代码奉上,还请各位大咖,大神,大侠,大哥,大姐帮帮忙

@property(Node)
targetSprite?:Node;
camera?:Camera;

start () {
    // [3]
    this.web_share()
    this.web_createImg()
}

public texture?:RenderTexture;
web_share() {
    this.camera = find("Canvas").getChildByName("Camera").getComponent(Camera)
    this.texture = new RenderTexture();
    this.texture.reset(view.getVisibleSize());
    this.camera.targetTexture = this.texture;
    let newSpFrame = new SpriteFrame();
    newSpFrame.texture = this.texture;
    this.targetSprite.getComponent(UITransform).contentSize = view.getVisibleSize();
    this.targetSprite.getComponent(Sprite).spriteFrame = newSpFrame;
    this.scheduleOnce(()=>{
        this.camera.targetTexture = null;
    }, 0);
    // 截出来的图倒立,逆天了
    this.targetSprite.setScale(new Vec3(1, -1, 1))
}

/**
 * 保存到本地不知何去何从,尝试了大咖们各种解题思路,短时间竟然依旧毫无进展
 */
web_createImg () {

}
1赞

感觉要沉,大家一起顶!


看帖子里的截图方案是否有帮助。

感谢分享,官方文档作为技术人员葵花宝典中竟找不到关键词,也是醉醉的。先欣赏下去

看了您共享的链接地址,很精辟.
我仔细核对了截图那部分内容,我当前使用的引擎位3.4.2里面已经完全融合了我需要的截图部分内容。
但我需要在“web”模式下截图。此处只支持 android 和 IOS 模式下截图。

render-texture.ts 在3.4.2版本已经是最新,无需手动处理!

最终的解决方案,官方大大有解,对于不爱逛论坛的开发者可是不太友好,虽然使用Cocos十来年,今年把我过去这么多年没逛过的论坛全看完了。哎!

目前 3.0.0 ~ 3.4.0 版本还不支持 jsb.saveImageData , 引擎计划在 3.5.0 支持, 要保存 imageData 为本地 png 文件需要参考下方的 pr 定制引擎
https://gitee.com/zzf2019/engine-native/commit/1ddb6ec9627a8320cd3545d353d8861da33282a8 (此 pr 只支持保存 png ,且只支持 ios、android)
3.4.0 也还存在一个 readPixels 的 bug ,记得手动合并下 pr : https://github.com/cocos-creator/engine/pull/9900/files

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。