Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The result is always fault, even we tried 5 times #400

Open
liangyuhong160 opened this issue Dec 28, 2022 · 0 comments
Open

The result is always fault, even we tried 5 times #400

liangyuhong160 opened this issue Dec 28, 2022 · 0 comments

Comments

@liangyuhong160
Copy link

手机型号:redmi note 10 pro
当画图尺寸设置喂某些值的时候会出现这个问题,比图width: 392, height: 66
发现手机dpr是2.75
生成图的时候:
wx.canvasToTempFilePath({ canvasId: 'photo', canvas: that.properties.use2D ? that.canvasNode : null, destWidth: that.canvasWidthInPx * getApp().systemInfo.pixelRatio, destHeight: that.canvasHeightInPx * getApp().systemInfo.pixelRatio, success: function (res) { that.getImageInfo(res.tempFilePath); }, fail: function (error) { console.error(canvasToTempFilePath failed, ${JSON.stringify(error)}); that.triggerEvent('imgErr', { error: error }); }, }, this);
destWidth:是1078,destHeight:是181.5
wx.getImageInfo({ src: filePath, success: (infoRes) => { if (that.paintCount > MAX_PAINT_COUNT) { const error =The result is always fault, even we tried ${MAX_PAINT_COUNT} times; console.error(error); that.triggerEvent('imgErr', { error: error }); return; } // 比例相符时才证明绘制成功,否则进行强制重绘制 if (Math.abs((infoRes.width * that.canvasHeightInPx - that.canvasWidthInPx * infoRes.height) / (infoRes.height * that.canvasHeightInPx)) < 0.01) { that.triggerEvent('imgOK', { path: filePath }); } else { console.log('比例不同,重新绘制') that.startPaint(); } that.paintCount++; }, fail: (error) => { console.error(getImageInfo failed, ${JSON.stringify(error)}); that.triggerEvent('imgErr', { error: error }); }, });
wx.getImageInfo出来的图会精度丢失, infoRes.height是181,
Math.abs((infoRes.width * that.canvasHeightInPx - that.canvasWidthInPx * infoRes.height) / (infoRes.height * that.canvasHeightInPx))
这个算出来偏差有0.016几,就会继续重绘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant