How to load a png image into a TImage

后端 未结 1 503
庸人自扰
庸人自扰 2021-01-12 06:11

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.LoadFr         


        
相关标签:
1条回答
  • 2021-01-12 07:05

    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;
    
    0 讨论(0)
提交回复
热议问题