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