2.4.x 微信小游戏获取相册或者拍照的图片显示在场景中的问题


不显示

base64.zip (81.9 KB)

wx.chooseMedia({

        count: 1,

        success(res) {

            // tempFilePath可以作为 img 标签的 src 属性显示图片

            const tempFiles = res.tempFiles

            const src = tempFiles[0]['tempFilePath'];

            var img = new Image();

            img.src = src;

            img.onload = function (info) {

                let texture = new cc.Texture2D();

                texture.initWithElement(img);

                texture.handleLoadedTexture();

                cb && cb(new cc.SpriteFrame(texture))

            };

            img.onerror = function (err) {

                // console.warn(err)

            }

        }

    })
1赞