fix(windows): validate extracted icon content in `convertIconToImage`

* Added a check to ensure the extracted icon is not empty or fully transparent.
* This prevents issues with displaying icons that do not have valid visual content.
This commit is contained in:
qianlifeng 2025-07-29 13:22:30 +08:00
parent 250f3607f6
commit fe23eed7b6
1 changed files with 16 additions and 0 deletions

View File

@ -383,6 +383,22 @@ func (a *WindowsRetriever) convertIconToImage(ctx context.Context, hIcon win.HIC
} }
} }
// Validate that the image has actual content (not just transparent pixels)
hasContent := false
bounds := img.Bounds()
for y := bounds.Min.Y; y < bounds.Max.Y && !hasContent; y++ {
for x := bounds.Min.X; x < bounds.Max.X && !hasContent; x++ {
r, g, b, a := img.At(x, y).RGBA()
if a > 0 && (r > 0 || g > 0 || b > 0) {
hasContent = true
}
}
}
if !hasContent {
return nil, fmt.Errorf("extracted icon is empty or fully transparent")
}
return img, nil return img, nil
} }