基础库在2.8.3以上的 canvas 2D 使用canvasToTempFilePath生成的临时路径图片无法显示
<canvas canvas-id="secondCanvas" :style="{width:canvasWidth + 'px',height:canvasHeight + 'px'}" type></canvas>
<view class="">
<cover-view>
<cover-image :src = "srcurl"></cover-image>
</cover-view>
</view>
import Vue from 'vue';
export default Vue.extend({
data() {
return {
photoSrc: 'https://bkimg.cdn.bcebos.com/pic/77094b36acaf2eddff326d3e871001e938019321',
canvasHeight: '',
canvasWidth: '',
srcurl: ''
}
},
onLoad(option) {},
mounted() {
wx.getImageInfo({
src: this.photoSrc,
success: (res) => {
// 生成指定宽度的图片
var canvasWidth = 100;
var canvasHeight = canvasWidth / res.width * res.height;
this.canvasHeight = canvasHeight;
this.canvasWidth = canvasWidth
var ctx = uni.createCanvasContext('secondCanvas');
console.log(canvasWidth, canvasHeight)
ctx.drawImage(this.photoSrc, 0, 0, canvasWidth, canvasHeight);
ctx.draw(false,(()=> {
//保存临时文件
setTimeout(() => {
uni.canvasToTempFilePath({
canvasId: 'secondCanvas',
x: 0,
y: 0,
width: 50,
height: 50,
destWidth: 100,
destHeight: 100,
success: (res) => {
this.srcurl = res.tempFilePath
console.log(res.tempFilePath)
// wx.getImageInfo({
// src: res.tempFilePath,
// success: function (res) {
// console.log(res)
// // 问题:这里得到的图片像素大小预期的大小不一致
// }
// });
},
fail: function(error) {
console.log(error)
}
})
}, 1000)
})())
}
})
},
methods: {
}
})
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)