Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wx.getImageInfo({
- src: photo.tempFilePaths[0],
- success: function (res) {
- var ctx = wx.createCanvasContext('photo_canvas');
- var ratio = 2;
- var canvasWidth = res.width;
- var canvasHeight = res.height;
- // 保证宽高均在200以内
- while (canvasWidth > 300 || canvasHeight > 300) {
- //比例取整
- canvasWidth = Math.trunc(res.width / ratio)
- canvasHeight = Math.trunc(res.height / ratio)
- ratio++;
- }
- that.setData({
- canvasWidth: canvasWidth,
- canvasHeight: canvasHeight
- })//设置canvas尺寸
- ctx.drawImage(photo.tempFilePaths[0], 0, 0, canvasWidth, canvasHeight)
- ctx.draw()
- //下载canvas图片
- setTimeout(function () {
- wx.canvasToTempFilePath({
- canvasId: 'photo_canvas',
- success: function (res) {
- console.log(res.tempFilePath)
- filePath = res.tempFilePath;
- that.setData({
- invoice: filePath
- });
- },
- fail: function (error) {
- console.log(error)
- }
- })
- }, 100)
- },
- fail: function (error) {
- console.log(error)
- }
- })
Add Comment
Please, Sign In to add comment