Yes, I think it is easy.
For example, this code sets the opacity to zero (i.e., transparency up to 100%) for each pixel in the upper half of the image:
var
png: TPNGImage;
sl: PByteArray;
...
for y := 0 to png.Height div 2 do
begin
sl := png.AlphaScanline[y];
FillChar(sl^, png.Width, 0);
end;
This will lead to the alpha channel of the linear gradient from full transparency (alpha = 0) to full opacity (alpha = 255) from left to right:
for y := 0 to png.Height do
begin
sl := png.AlphaScanline[y];
for x := 0 to png.Width - 1 do
sl^[x] := byte(round(255*x/png.Width));
end;
Basically, I'm trying to say that
(png.AlphaScanline[y]^)[x]
is the alpha value (opacity) as a pixel byte in the string y and col x.
source
share