I am trying to load a png image into a TImage with Delphi XE4. The png starts off in a stream: E.g.
Stream := TMemoryStream.Create;
try
Stream.LoadFromFile('c:\file.png');
Stream.Position := 0;
Image1.Picture.Graphic.LoadFromStream(Stream);
finally
Stream.Free;
end;
I get an AV when I run this code. Can anyone tell me what I'm doing wrong?
Thanks.
The TImage.Picture.Graphic
property is nil until you load a graphic into the Picture
.
What you are asking for can be achieved as follows:
uses pngimage;
Stream := TMemoryStream.Create;
try
// obtain png image, load from file or other..
....
Image := TPngImage.Create;
try
Stream.Position := 0;
Image.LoadFromStream(Stream);
Image1.Picture.Graphic := Image;
finally
Image.Free;
end;
finally
Stream.Free;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With