How to load an arbitrary image from a BLOB stream into a TImage?

前端 未结 4 1370
攒了一身酷
攒了一身酷 2020-12-28 22:46

If I understand it correctly, TImage.LoadFromFile determines the type of picture from the file extension.

Is there any way to detect the image type auto

4条回答
  •  余生分开走
    2020-12-28 23:08

    See this SO answer for file content retrieval from header.

    Or you can use our TSynPicture class, which will handle all kind of pictures (bmp/gif/tiff/jpg/png) using Gdi+ library, in one single class. So your TPicture can be this unique class, for any kind of picture. With less code overhead than the Jpeg or PNG Delphi units.

    var Pic: TSynPicture;
    
    Pic := TSynPicture.Create;
    Pic.LoadFromStream(aStream); // will load bmp/gif/tiff/jpeg/png content
    AImage.Picture.Graphic := Pic;
    ....
    

提交回复
热议问题