當前位置:首頁>文章中心>操作系統(tǒng)
公司動態(tài) 行業(yè)新聞 技術文檔 維修技巧

小程序image 網絡http 協(xié)議不顯示方法(已驗證)

發(fā)布時間:2022-10-29 點擊數:8452

 你會發(fā)現地址正確 但是沒法顯示。

if (filePath.length < 10) {

filePath = "../../static/logo.png"

}

console.log("地址:" + filePath)

let that = this

const firstCanvas = uni.createCanvasContext('firstCanvas', this);

let scla = 1

uni.getImageInfo({

src: filePath,

success(res) {

that.canvasWidth = res.width * scla

that.canvasHeight = res.height * scla

console.log(res, that.canvasWidth, that.canvasHeight, filePath)

firstCanvas.drawImage(filePath, 0, 0, that.canvasWidth, that.canvasHeight);

firstCanvas.draw();

// that.$nextTick(() => { //獲取畫布像素數據


})

},

fail(res) {

console.log("失敗img---:" + res + " url:" + filePath)

}


所以有個方法  先下載到本地。然后重置一下。

renderFinish() {

if (this.list.id) {

this.$api.shebeiDetail({

id: this.list.id

}).then(res => {

if (res.code == 1) {

this.list.xinghao = res.data.xinghao

const downloadTask = uni.downloadFile({

url: res.data.image, 

success: (res) => {

if (res.statusCode === 200) {

this.list.image = res.tempFilePath;

console.log("本地地址" + this.list.image);

}


}

});


downloadTask.onProgressUpdate((res) => {

console.log('下載進度' + res.progress);

console.log('已經下載的數據長度' + res.totalBytesWritten);

console.log('預期需要下載的數據總長度' + res.totalBytesExpectedToWrite);

});



} else {

uni.showToast({

title: ' 錯誤:沒找到這個設備 ',

icon: "none"

});

return false;

}

})

}

let filePath = encodeURI(this.list.image)

if (filePath.length < 10) {

filePath = "../../static/logo.png"

}

console.log("地址:" + filePath)

let that = this

const firstCanvas = uni.createCanvasContext('firstCanvas', this);

let scla = 1

uni.getImageInfo({

src: filePath,

success(res) {

that.canvasWidth = res.width * scla

that.canvasHeight = res.height * scla

console.log(res, that.canvasWidth, that.canvasHeight, filePath)

firstCanvas.drawImage(filePath, 0, 0, that.canvasWidth, that.canvasHeight);

firstCanvas.draw();

// that.$nextTick(() => { //獲取畫布像素數據


})

},

fail(res) {

console.log("失敗img---:" + res + " url:" + filePath)

}

})


我要評論

評論內容:

驗證碼:
驗證碼

滇公網安備 53282302000057號