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;
    }
});

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM