收藏
回答

canvas 2D 使用canvasToTempFilePath生成的临时路径图片无法显示?

基础库在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: {


}


})

回答关注问题邀请回答
收藏

1 个回答

  • Cjiang
    Cjiang
    2021-06-25

    你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    2021-06-25
    有用
    回复 4
    • 神经蛙
      神经蛙
      2021-06-28
      你就用我贴的这段代码 就能复现  麻烦尽快看一下
      2021-06-28
      回复
    • Cjiang
      Cjiang
      2021-06-29回复神经蛙
      用了第三方框架,先自查下。
      2021-06-29
      回复
    • 神经蛙
      神经蛙
      2021-06-29
      拍照后生成的图片用canvas剪裁后,基础库在2.8.3以上图片就没有了
      2021-06-29
      回复
    • 余哎呀
      余哎呀
      2022-09-14回复神经蛙
      有解决方案了吗
      2022-09-14
      回复
登录 后发表内容