优化bug

This commit is contained in:
24kycj
2025-11-15 15:42:26 +08:00
parent 1d42f6b74b
commit ff5c511eca
2 changed files with 16 additions and 0 deletions
+8
View File
@@ -677,11 +677,19 @@
}
}
}
// 如果没有找到任何非透明像素,直接返回,不进行裁剪
if (pix.x.length === 0 || pix.y.length === 0) {
return;
}
pix.x.sort(fn);
pix.y.sort(fn);
n = pix.x.length - 1;
w = pix.x[n] - pix.x[0];
h = pix.y[n] - pix.y[0];
// 确保宽度和高度是有效的正数
if (w <= 0 || h <= 0 || isNaN(w) || isNaN(h)) {
return;
}
var cut = ctx.getImageData(pix.x[0], pix.y[0], w, h);
canvas.width = w;
canvas.height = h;