小程序API canvas 导出图片
发布于 5 年前 作者 bmeng 10222 次浏览 来自 问答

小程序API有个问题:

ctx.drawImage(filesrc, 0, 0, that.data.canWidth, that.data.canHeight);

ctx.draw(false, () =>{wx.canvasToTempFilePath({})})

这种方法调用后,偶尔取出的图片  不完整 !!!!

6 回复

这个正常,但是也是和我说的这个问题不是一回事啊!你们干嘛说这些不相干的?

------------------------------------------------双向视频中 拍照-------------------------------------------------------------------------

this.pusherContent.snapshot({

success: function (res) {

// var filePath = res.tempImagePath[0];

console.log(“图片路径” + res.tempImagePath);

//保存图片到本地

wx.saveImageToPhotosAlbum({

filePath: res.tempImagePath,

success: function (res) {

console.log(“图片保保存成功”);

},

fail: function (error) {

console.error(“图片保存出错”)

console.warn(error)

},

complete: function () {

}

});

that.drawCanvas(res.tempImagePath);

},

fail: function (error) {

console.error(“拍照失败”)

console.warn(“拍照失败原因:” + error)

},

complete: function () {

console.log(“完成”);

// that.pusherContent.resume();

// that.playerContent.play();

}

});

------------------------------------------------双向视频中 拍照-------------------------------------------------------------------------

------------------------------------------------双向视频中 拍照----通过画布导出压缩图片--------------------------------------------------


drawCanvas: function (filesrc) {  // 缩放图片

const ctx = wx.createCanvasContext(‘attendCanvasId’);

let that = this;

wx.getImageInfo({

src: filesrc,

success: function (res) {

if (res.width > 200 || res.height > 200) {//判断图片是否超过500像素

let scale = res.width / res.height//获取原图比例

that.setData({//构造画板宽高

canWidth: 200,

canHeight: 200 / scale

})

//画出压缩图片

console.log("--------------" + that.data.canWidth + “----” + that.data.canHeight);

ctx.drawImage(filesrc, 0, 0, that.data.canWidth, that.data.canHeight);

ctx.draw(false, () =>{wx.canvasToTempFilePath({

canvasId: ‘attendCanvasId’,

success: function (res) {

console.log(“压缩后:” + res.tempFilePath);

//保存图片到本地

wx.saveImageToPhotosAlbum({

filePath: res.tempFilePath,

success: function (res) {

console.log(“图片保保存成功”);

},

fail: function (error) {

console.error(“图片保存出错”)

console.warn(error)

},

complete: function () {

}

});

},

fail: function (res) {

console.log(res);

}

})});

} else {

console.log(“像素小”);

}

}

})

}

------------------------------------------------双向视频中 拍照----通过画布导出压缩图片--------------------------------------------------

draw 函数的回调里执行 导出图片  偶尔会有导出不完整的情况

若是不在draw的回调里执行,二是隔1S去执行导出,就不会出问题。

顺便问下,小程序双向视频   在视频中 可以真正全屏吗?像APP一样没有导航栏?

还有个问题,vConsole 这个 是小程序上线后就自动消失了吗?还是需要配置?

上线的小程序,怎么使用体验版或者开发版。你这回答够逗的,你看懂题目了没。什么调度?

正式版没有调度功能的。用体验版或者开发版看。

你好,请具体描述问题出现的流程,并提供能复现问题的简单代码示例。

回到顶部