How to load a PNG image in TImage

I am trying to load a PNG image into TImage using Delphi XE4. Png starts in the stream: for example.

Stream := TMemoryStream.Create; try Stream.LoadFromFile('c:\file.png'); Stream.Position := 0; Image1.Picture.Graphic.LoadFromStream(Stream); finally Stream.Free; end; 

I get AV when I run this code. Can someone tell me what I am doing wrong?

Thanks.

+5
source share
1 answer

The TImage.Picture.Graphic property is zero until you load the graphics in 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; 
+15
source

Source: https://habr.com/ru/post/1235478/


All Articles