web游戏截图如何保存到本地?

let texture = new cc.RenderTexture();
texture.initWithSize(****);
let spriteFrame = new cc.SpriteFrame();
spriteFrame.setTexture(texture);
img.spriteFrame = spriteFrame;
这个能截图能显示,但是不知道怎么保存啊? 我比较新手

存base64

大佬 cc.RenderTexture cc.SpriteFrame 这两个参数 怎么操作转换base64呢

 /** 截图 */
    private screenshot(): string {
        let size = View.instance.getVisibleSize();
        let width = Math.round(size.width);
        let height = Math.round(size.height);
        // 设置用来截图的相机
        let camera = camera;
        let tf = new RenderTexture();
        tf.initialize({ width: width, height: height });
        camera.targetTexture = tf;
        director.root.frameMove(0);
        // 截图的宽高
        height = 584;
        width = 736
        if (!this._canvas) {
            this._canvas = document.createElement('canvas');
            this._canvas.width = width;
            this._canvas.height = height;
        } else {
            this.clearCanvas();
        }
        camera.targetTexture = null;
        let ctx = this._canvas.getContext('2d')!;
        // 参数2为距离屏幕底部的距离
        let arrayBuffer = tf.readPixels(0, 0, width, height);
        tf.destroy();
        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] = arrayBuffer[start + i];
            }
            ctx.putImageData(imageData, 0, row);
        }
        let data = this._canvas.toDataURL("image/png");
        return data;
    }

    /** 截图完毕后清空canvas */
    private clearCanvas(): void {
        let ctx = this._canvas.getContext('2d');
        ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
    }
1赞