收藏
回答

wx.canvasToTempFilePath生成的图片真机调试显示纯黑色图片,电脑端没问题?


这是pc端查看,没问题。


这是真机调试。

代码:

//添加图片

upImg(e) {

let that = this;

wx.showActionSheet({

itemList: ['从相册中选择', '相机'],

itemColor: "#67bae7",

success(res) {

if (res.tapIndex == 0) {

that.chooseWxImage('album')

} else if (res.tapIndex == 1) {

that.chooseWxImage('camera')

}

},

fail(res) {

console.log(res.errMsg)

}

})

},

//上传封面图

chooseWxImage(type) {

var that = this;

var result = {}

var icon = "";

wx.setStorageSync('initFabu', 'false')

wx.chooseImage({

count: 1,

sizeType: ['original', 'compressed'],

sourceType: [type],

success: function (res) {

var imgsrc = res.tempFilePaths[0];

that.setData({

hide: false,

isLoading:true

})

wx.getImageInfo({

src: imgsrc,

success: function (res) {

that.setData({

canvasW:res.width,

canvasH:res.height

});

setTimeout(()=>{

let ctx = wx.createCanvasContext('shuiyinCanvas');

// 打水印

ctx.drawImage(imgsrc, 0, 0, res.width, res.height);

ctx.setFillStyle(ctx.createPattern("https://ytw.oss-cn-beijing.aliyuncs.com/static/image/systemIcon/water_cover.png", "repeat"));

ctx.fillRect(0, 0, res.width, res.height);

ctx.draw(false, function () {

wx.canvasToTempFilePath({

canvasId: 'shuiyinCanvas',

success: (res) => {

let arr = [];

let imgUrl = res.tempFilePath;

arr.push(imgUrl);

wx.showLoading({ title: '等待图片上传...', mask: true });

util.uploadimg({ path: arr, url: "/api/user/uploadFile" }, function (result, currIndex) {

let curr_data = JSON.parse(result);

that.setData({

cover: curr_data.data,

isLoading: false

});

wx.hideLoading();

}, function (err) {

that.setData({

isLoading: false

});

});

},

fail: (err) => {

that.setData({

isLoading: false

});

}

})

});

},200);

}

});

}

})

},


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

2 个回答

  • 永
    2019-10-27

    预见相同的问题,pc手写签名图片正常生成图片,真机调试和体验版就出现存黑图片,请问怎么处理?

    插入不了代码......



    上面是pc插入的图片,下面是真机调试和体验版的图片

    2019-10-27
    有用
    回复
  • 是小白啊
    是小白啊
    2019-10-10

    麻烦提供能复现问题的代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    2019-10-10
    有用
    回复
登录 后发表内容
问题标签