cocos creator3.0如何在客户端将base64转成正常的图片展示出来

cocos creator3.0如何在客户端将base64转成正常的图片展示出来

/**

 * * base64转成图片

 * @param str base64编码

 * @param node Sprite组件

 */

base64ToImg(str, node) {

    let img = new Image();

    img.src = "data:image/png;base64," + str;

    const tex = new Texture2D();

    img.onload = () => {

        tex.reset({

            width: img.width,

            height: img.height

        });

        tex.uploadData(img, 0, 0);

        tex.loaded = true;

        let sp = new SpriteFrame();

        sp.texture = tex;

        node.spriteFrame = sp;

    }

}