优化bug
This commit is contained in:
@@ -677,11 +677,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 如果没有找到任何非透明像素,直接返回,不进行裁剪
|
||||||
|
if (pix.x.length === 0 || pix.y.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
pix.x.sort(fn);
|
pix.x.sort(fn);
|
||||||
pix.y.sort(fn);
|
pix.y.sort(fn);
|
||||||
n = pix.x.length - 1;
|
n = pix.x.length - 1;
|
||||||
w = pix.x[n] - pix.x[0];
|
w = pix.x[n] - pix.x[0];
|
||||||
h = pix.y[n] - pix.y[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);
|
var cut = ctx.getImageData(pix.x[0], pix.y[0], w, h);
|
||||||
canvas.width = w;
|
canvas.width = w;
|
||||||
canvas.height = h;
|
canvas.height = h;
|
||||||
|
|||||||
@@ -649,11 +649,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 如果没有找到任何非透明像素,直接返回,不进行裁剪
|
||||||
|
if (pix.x.length === 0 || pix.y.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
pix.x.sort(fn);
|
pix.x.sort(fn);
|
||||||
pix.y.sort(fn);
|
pix.y.sort(fn);
|
||||||
n = pix.x.length - 1;
|
n = pix.x.length - 1;
|
||||||
w = pix.x[n] - pix.x[0];
|
w = pix.x[n] - pix.x[0];
|
||||||
h = pix.y[n] - pix.y[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);
|
var cut = ctx.getImageData(pix.x[0], pix.y[0], w, h);
|
||||||
canvas.width = w;
|
canvas.width = w;
|
||||||
canvas.height = h;
|
canvas.height = h;
|
||||||
|
|||||||
Reference in New Issue
Block a user