Ali Ahmadi
Ali Ahmadi

Reputation: 731

Get image dimensions without loading using meta data

I'd like to get an image's dimensions without actually loading the image, I would like to use the meta data provided in the file.
Is there a windows api or something similar that allows me to read this meta data ? a sample would be much appreciated.
enter image description here

Upvotes: 1

Views: 594

Answers (1)

Ali Ahmadi
Ali Ahmadi

Reputation: 731

With the help of Simson Mourier's comment which was a snippet code in C#, I managed to make something similar in Delphi:

uses
  System.Win.ComObj;
var 
  ObjShell, ObjFolder, ObjFile, ObjInfo: Variant;
begin
  ObjShell := CreateOleObject('Shell.Application');

  // directory of the file to read
  ObjFolder := ObjShell.NameSpace('c:\imagefolders');

  // one of the files in the folder, just the name alone, no path
  ObjFile := ObjFolder.parseName('001.jpg');

  // example: width of the image
  ObjInfo := ObjFile.ExtendedProperty('System.Image.HorizontalSize');

  ShowMessage(ObjInfo);
end;

The code was tested in Delphi 10.4 on Windows 10.

Upvotes: 4

Related Questions