Suppose I want to paint a red rectangle onto the canvas of a png graphic. The graphic is loaded from the attached file. But the image into which the modified png is copied shows only a punched-out rectangle. I tried various different approaches, but don't find the clue.
The issue seems to be related to this particular file. When I am using png files that I saved from screenshots the program has normal behaviour..
I am using the following code to load and modify the png file and to show it in a TImage component:
procedure TForm1.FormCreate(Sender: TObject);
var
png: TPortableNetworkGraphic;
begin
png := TPortableNetworkGraphic.Create;
try
png.LoadFromFile('test.png');
png.Canvas.Brush.Style := bsSolid;
png.Canvas.Brush.Color := clRed;
png.Canvas.Rectangle(100, 100, 200, 200);
Image1.Picture.Assign(png);
finally
png.Free;
end;
end;
What is wrong?