feat(内存占用): 优化图片裁剪,减少内存分配
build.yaml / build (push) Successful in 41s

This commit is contained in:
xiaoqidun committed 2026-09-12 15:46:38 +08:00
1 parent c82c810c9e
commit d5b8343ac4
1 file changed
+2 -1
+2 -1
View File
@@ -205,8 +205,8 @@ func imageWithClip(img image.Image, clipPath *canvas.Path, m canvas.Matrix) imag
return img return img
} }
source := imagePixelSource(img) source := imagePixelSource(img)
out := image.NewNRGBA(bounds)
if src, ok := source.(*image.NRGBA); ok { if src, ok := source.(*image.NRGBA); ok {
out := image.NewNRGBA(bounds)
for y := 0; y < h; y++ { for y := 0; y < h; y++ {
offset := src.PixOffset(bounds.Min.X, bounds.Min.Y+y) offset := src.PixOffset(bounds.Min.X, bounds.Min.Y+y)
row := out.Pix[y*out.Stride : y*out.Stride+w*4] row := out.Pix[y*out.Stride : y*out.Stride+w*4]
@@ -218,6 +218,7 @@ func imageWithClip(img image.Image, clipPath *canvas.Path, m canvas.Matrix) imag
} }
return out return out
} }
out := &image.NRGBA{Pix: mask.Pix, Stride: mask.Stride, Rect: bounds}
for y := bounds.Min.Y; y < bounds.Max.Y; y++ { for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ { for x := bounds.Min.X; x < bounds.Max.X; x++ {
c := imageNRGBAAt(source, x, y) c := imageNRGBAAt(source, x, y)