I don't have Delphi 2007 or 2009 to see if this will work in either of those versions. Maybe you can use this library for your purpose. This seems very similar to the VB6 way of doing this that you mention. The GraphicEx library has an example convert that uses GraphicClass := FileFormatList.GraphicFromContent(.) TBitmap, TJPEGImage, TGIFImage, TPngImage) įileStr := TFileStream.Create('D:\Temp\img.dat', fmOpenRead) įor ClassIndex := Low(GraphicClasses) to High(GraphicClasses) do begin ![]() GraphicClasses: array of TGraphicClass = ( You could use the efg page as a starting point of your research.Ī quick and dirty solution is to try the few formats you need to handle until one succeeds: function TryLoadPicture(const AFileName: string APicture: TPicture): boolean There's a reason that there is no matching TPicture.LoadFromStream method.Īn external library which can examine data and determine the graphic format at runtime would be the best solution. You can't use TPicture.LoadFromFile if you don't know what format the graphic has, as this method uses the file extension to determine which of the registered graphic formats needs to be loaded. If Copy(FirstBytes, 1, 2) = #$FF#$D8 then procedure DetectImage(const InputFileName: string BM: TBitmap) įS := TFileStream.Create(InputFileName, fmOpenRead) ![]() ![]() ![]() If the file extension is not known one method is to look at the first few bytes to determine the image type. Picture.LoadFromFile('C:\imagedata.dat') ī(0, 0, Picture.Graphic) Procedure TForm1.Button1Click(Sender: TObject) If the file has an extension you can use the following code, as noted by others the TPicture.LoadFromFile looks at the extensions registered by the inherited classes to determine which image to load. Delphi 2009 comes with built in support for JPEG, BMP, GIF and PNG.įor earlier versions of Delphi you may need to find third party implementations for PNG and GIF, but in Delphi 2009 you simply add the Jpeg, pngimage and GIFImg units to your uses clause.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |