Guest User

Untitled

a guest
Apr 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. wx.getImageInfo({
  2. src: photo.tempFilePaths[0],
  3. success: function (res) {
  4. var ctx = wx.createCanvasContext('photo_canvas');
  5. var ratio = 2;
  6. var canvasWidth = res.width;
  7. var canvasHeight = res.height;
  8. // 保证宽高均在200以内
  9. while (canvasWidth > 300 || canvasHeight > 300) {
  10. //比例取整
  11. canvasWidth = Math.trunc(res.width / ratio)
  12. canvasHeight = Math.trunc(res.height / ratio)
  13. ratio++;
  14. }
  15. that.setData({
  16. canvasWidth: canvasWidth,
  17. canvasHeight: canvasHeight
  18. })//设置canvas尺寸
  19. ctx.drawImage(photo.tempFilePaths[0], 0, 0, canvasWidth, canvasHeight)
  20. ctx.draw()
  21. //下载canvas图片
  22. setTimeout(function () {
  23. wx.canvasToTempFilePath({
  24. canvasId: 'photo_canvas',
  25. success: function (res) {
  26. console.log(res.tempFilePath)
  27. filePath = res.tempFilePath;
  28. that.setData({
  29. invoice: filePath
  30. });
  31.  
  32. },
  33. fail: function (error) {
  34. console.log(error)
  35. }
  36. })
  37. }, 100)
  38. },
  39. fail: function (error) {
  40. console.log(error)
  41. }
  42. })
Add Comment
Please, Sign In to add comment