- 安卓手机用canvasToTempFilePath提示exceed size limit
使用canvas2d的方法,安卓手机vivo z5x 红米note8 pro等用canvasToTempFilePath生成图片提示canvasToTempFilePath:fail:convert native buffer parameter fail. native buffer exceed size limit,初步怀疑是宽度设置太大原因,设置了180vw。 <canvas id="canvas" canvas-id="signCanvas" type="2d" binderror="drawError" bindtouchstart="drawStart" bindtouchmove="drawMove" bindtouchend="drawEnd" style="width:{{width}}vw;height:100%;border:1px solid #ddd;margin:auto;margin-left:{{marginLeft}}vw;"> </canvas> data: { marginLeft: 0, width: 180, demoSrc: '', title: '', isShowCanvas: true, // 默认一开始只有一个页面 isOnlyOnePage: true }, init(res) { console.log(res) const width = res[0].width const height = res[0].height const canvas = res[0].node console.log('初始化宽高度', width, height) canvasWidth = width; canvasHeight = height signCanvas = canvas.getContext('2d') canvas.width = width * dpr canvas.height = height * dpr canvasObj = canvas signCanvas.scale(dpr, dpr) signCanvas.lineWidth = 8; signCanvas.lineCap = "round"; signCanvas.strokeStyle = "#222222"; }, // 保存确定 saveSign() { let that = this; let canHeight = 90; let canWidth = this.data.width; if (handData.length) { console.log('canvas宽高', canvasWidth, canvasHeight) console.log('dest图片宽度高度', canWidth, canHeight) wx.canvasToTempFilePath({ x: 0, y: 0, destHeight: canHeight, destWidth: canWidth, canvas: canvasObj, success: function (res) { console.log('res', res) that.setData({ demoSrc: res.tempFilePath }) wx.downloadFile({ url: res.tempFilePath, success: (res) => { console.log(res) }, fail: (err) => { console.log(err) } }) }, fail: function (err) { console.log('生成图片失败', err) if (err && err.errMsg.indexOf('native buffer exceed size limit') >= 0) { util.showModel('生成图片失败', '生成图片过大,请重新进入该页面,减少签名文字大小,降低右移次数') } else if (err && err.errMsg) { util.showModel('生成图片失败', err.errMsg) } else { util.showModel('生成图片失败', '请重新打开页面签名') } } }) } }
2020-04-27 - 清理缓存接口何时才能 清理图片缓存
- 需求的场景描述(希望解决的问题) 越用越卡 - 希望提供的能力 清理缓存接口 能够 清理图片缓存
2018-10-11