参考文档:
http://www.runoob.com/tags/canvas-drawimage.html
https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLCanvasElement/toDataURL
思路:
首先是用 ctx.drawImage(img,0,0)
;方法把图片绘制到canvas画布上。
再用canvas
,toDataURL(type, encoderOptions)
;方法转成base64并压缩图片。
网上也有很多人封装好的方法,原理一样的。
网友评论