re
la prochaine fois précise de suite
avec quelle version du compilateur
tu as essayé ...
donc voici la version qui fonctionne avec tous les compilateurs Ansi & Unicode (normalement ... je ne les possède pas tous)
unit Unit2;
interface
uses SysUtils, StrUtils, Variants, Dialogs;
function GetImageSize(const aFileName : TFileName; out aWidth, aHeight: Integer):Boolean;
implementation
uses ComObj;
function ExcludeChars(const S : AnsiString; const CS : TSysCharSet): AnsiString;
var P, PR : PByte;
BS : set of Byte absolute CS;
Size, I : Integer;
begin
P := PByte(S);
Size := Length(S);
SetLength(Result, Size);
PR := PByte(Result);
I := 0;
while P^ <> $0 do
begin
if not (P^ in BS) then
begin
Pr^ := P^;
Inc(Pr);
end
else Inc(I);
Inc(P);
end;
if I > 0 then SetLength(Result, Size - I)
end;
function GetImageSize(const aFileName : TFileName; out aWidth, aHeight: Integer):Boolean;
var FDir, FName, TMP : AnsiString;
Index : Integer;
FShellApp, FShellFolder : Variant;
begin
Result := False;
if FileExists(aFileName) then
try
FDir := AnsiString(ExtractFileDir(aFileName));
FName := AnsiString(ExtractFileName(aFileName));
FShellApp := CreateOleObject('Shell.Application');
try
FShellFolder := FShellApp.NameSpace(Variant(FDir));
TMP := AnsiString(FShellFolder.GetDetailsOf(FShellFolder.ParseName(Variant(FName)), 26));
TMP := ExcludeChars(TMP, #32);
Index := Pos('x', string(TMP));
if Index > 0 then
begin
aWidth := StrToInt(Copy(string(TMP), 1, Index - 1));
aHeight := StrToInt(Copy(string(TMP), Index + 1, High(Integer)));
Result := True;
end;
except on E : Exception do
begin
MessageDlg(Format('Une erreur %s avec le message : %s'#13#10'est survenue', [E.ClassName, E.Message]), mtINFORMATION,
[mbOk], 0);
end;
end;
finally
FShellApp := Unassigned;
FShellFolder := Unassigned;
end;
end;
end.
[hr]@+Cirec
[hr]