mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +08:00
This commit is contained in:
1 parent
9a618d6eae
commit
c5abb3667a
1 file changed
+11
@@ -289,6 +289,17 @@ func imageWithAlpha(img image.Image, alpha *int) image.Image {
|
||||
bounds := img.Bounds()
|
||||
out := image.NewNRGBA(bounds)
|
||||
source := imagePixelSource(img)
|
||||
if src, ok := source.(*image.NRGBA); ok {
|
||||
for y := 0; y < bounds.Dy(); y++ {
|
||||
offset := src.PixOffset(bounds.Min.X, bounds.Min.Y+y)
|
||||
row := out.Pix[y*out.Stride : (y+1)*out.Stride]
|
||||
copy(row, src.Pix[offset:offset+len(row)])
|
||||
for x := 3; x < len(row); x += 4 {
|
||||
row[x] = uint8(int(row[x]) * a / 255)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
||||
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
||||
c := imageNRGBAAt(source, x, y)
|
||||
|
||||
Reference in new issue
Block a user