小程序
小游戏
企业微信
微信支付
扫描小程序码分享
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
var that = this
that.data.ctx.takePhoto({
quality: 'normal', //高质量
success: (res) => {
this.loadTempImagePath(res.tempImagePath);
},
})
},
loadTempImagePath: function(options) {
var that = this
that.data.path = options
console.log();
wx.getSystemInfo({
success: function(res) {
// 矩形的位置
var image_x = 15;
var image_y = 120;
var image_width = that.data.windowWidth - 2 * 15;
var image_height = 238;
console.log(that.data.path);
wx.getImageInfo({
src: that.data.path,
success: function(res) {
console.log(res);
that.setData({
isShowImage: true
})
console.log(that.data.isShowImage);
canvas = wx.createCanvasContext("image-canvas")
//过渡页面中,图片的路径坐标和大小
canvas.drawImage(that.data.path, 0, 0, that.data.windowWidth, that.data.windowHeight)
wx.showLoading({
title: '数据处理中...',
icon: 'loading',
duration: 10000
})
// 这里有一些很神奇的操作,总结就是MD拍出来的照片规格居然不是统一的过渡页面中,对裁剪框的设定
canvas.setStrokeStyle('black')
canvas.strokeRect(image_x, image_y, image_width, image_height)
canvas.draw()
setTimeout(function() {
wx.canvasToTempFilePath({ //裁剪对参数
canvasId: "image-canvas",
x: image_x, //画布x轴起点
y: image_y, //画布y轴起点
width: image_width, //画布宽度
height: image_height, //画布高度
destWidth: image_width, //输出图片宽度
destHeight: image_height, //输出图片高度
success: function(res) {
that.setData({
image: res.tempFilePath,
})
//清除画布上在该矩形区域内的内容。
// that.canvas.clearRect(0, 0, that.data.width, that.data.height)
// that.canvas.drawImage(res.tempFilePath, image_x, image_y, image_width, image_height)
// that.canvas.draw()
wx.hideLoading()
console.log(res.tempFilePath);
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success(res) {
console.log(res)
wx.hideLoading();
wx.showToast({
title: '保存成功',
});
},
fail() {
wx.hideLoading()
}
})
//在此可进行网络请求
// PublicJS.drivinglicenseUpload(res.tempFilePath, that.uploadFile);
},
fail: function(e) {
wx.hideLoading()
wx.showToast({
title: '出错啦...',
icon: 'loading'
})
if (this.data.skipphotoStatus == 1) {
wx.redirectTo({
url: 'addCarInfo/addCarInfo',
})
} else {
wx.navigateBack({
delta: 1
});
}
}
});
}, 1000);
}
})
}
})
},