wx.getImageInfo在MIX2会重新生成新文件而引发BUG
发布于 6 年前 作者 natian 6222 次浏览 来自 问答

* Bug 表现是什么?预期表现是什么?

4 回复

@黄思程  就是真机微信打开有问题,不然也不会来反馈

是只在远程调试才出现问题吗?用微信打开有没有问题

不是很理解,传给getImageInfo的path确定是可以访问到的吗?放在image标签是否很显示出来

@黄思程

好像是因为wx.previewImage导致的问题,

比如下列代码,点击按钮,获取网络图片,得到本地路径,再通过wx.getImageInfo校验文件路径是否可读,

可以读取,记录当前路径,且用wx.previewImage显示,

第二次点击按钮,路径已经记录过,再通过wx.getImageInfo校验文件路径是否可读,

MIX2返回 “getImageInfo:fail:file not found”

Page({
    data: {
        result: ''
    },
    doButton: function () {
        if (this.data.result) {
            wx.getImageInfo({
                src: this.data.result,
                success(res1) {
                    console.log('第2次1', res1.path);
                    wx.previewImage({
                        urls: [res1.path]
                    });
                },
                fail(err1) {
                    console.log('第2次1', err1.errMsg);
                }
            });
        } else {
            let _this = this;
            wx.getImageInfo({
                src: 'http://a.hiphotos.baidu.com/image/pic/item/faf2b2119313b07eaad49f0c00d7912397dd8c4d.jpg',
                success(res1) {
                    console.log('第1次1', res1.path);
                    wx.getImageInfo({
                        src: res1.path,
                        success(res2) {
                            console.log('第1次2', res2.path);
                            _this.data.result = res2.path;
                            wx.previewImage({
                                urls: [res2.path]
                            });
                        },
                        fail(err2) {
                            console.log('第1次2', err2.errMsg);
                        }
                    });
                },
                fail(err1) {
                    console.log('第1次1', err1.errMsg);
                }
            });
        }
    }
})

小米6

小米Mix2

回到顶部