提交 c6a1aac2 编写于 作者: D DCloud_LXH

fix: canvas no necessary resize

上级 efc09cc4
......@@ -131,7 +131,6 @@ export default /*#__PURE__*/ defineBuiltInComponent({
<div style="position: absolute;top: 0;left: 0;width: 100%;height: 100%;overflow: hidden;">
{slots.default && slots.default()}
</div>
{/* @ts-expect-error */}
<ResizeSensor ref={sensor} onResize={_resize} />
</uni-canvas>
)
......@@ -212,8 +211,13 @@ function useMethods(
[key: string]: HTMLImageElement & { ready: boolean }
} = {}
function _resize() {
function _resize(size?: { width: number; height: number }) {
let canvas = canvasRef.value!
var hasChanged =
!size ||
canvas.width !== Math.floor(size.width * pixelRatio) ||
canvas.height !== Math.floor(size.height * pixelRatio)
if (!hasChanged) return
if (canvas.width > 0 && canvas.height > 0) {
let context = canvas.getContext('2d')!
let imageData = context.getImageData(0, 0, canvas.width, canvas.height)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册