uni使用new image()获取图片信息报错

uni使用new image()报ReferenceError: Image is not defined或者获取不到对象

JS代码:

var img = new Image(); // 创建对象
img.src = getBase64List; // 改变图片的src
img.onload = function(e) { // 加载完成执行
     contentWidth = this.width, contentHeight = this.height;
}

解决方案:

使用用 uni.getImageInfo 代替new image()

uni.getImageInfo({
        src: this.getBase64List,
    success: function (image) {
            console.log(image);
        console.log(image.height);
        var contentWidth = image.width;
            var contentHeight = image.height;
    }
});
原文地址:https://www.cnblogs.com/Intellectualscholar/p/15342744.html