Hola a todos,
yo utilizo las siguiente función para determinar el tipo imagen para las extensiones mas conocidas,
Código Delphi
[-]interface
...
function GetImageFormat(const AFileName: String; OmitirExtension:Boolean=true): String; overload;
function GetImageFormat(Stream: TStream; var fileType:String):boolean; overload;
...
implementation
...
function GetImageFormat(const AFileName: String; OmitirExtension:Boolean=true): String;
var
ext: string;
FileStream: TFileStream;
begin
ext := lowerCase(extractFileExt(AFileName));
try
FileStream := TFileStream.Create(AFileName, fmOpenRead);
try
if not GetImageFormat(FileStream, result) and
not omitirExtension then
Result:=ext;
finally
FileStream.free;
end;
except
end;
end;
function GetImageFormat(Stream: TStream; var fileType:string):Boolean;
var
FirstBytes: AnsiString;
begin
result:=False;
fileType := '';
if (Stream <> nil) and (Stream.Size > 40) then
try
SetLength(FirstBytes, 8);
Stream.Read(FirstBytes[1], 8);
if (Copy(FirstBytes, 1, 2) = 'BM') then
fileType := '.bmp'
else if (FirstBytes = #137'PNG'#13#10#26#10) then
fileType := '.png'
else if (Copy(FirstBytes, 1, 3) = 'GIF') then
fileType := '.gif'
else if (Copy(FirstBytes, 1, 2) = #$FF#$D8) then
fileType := '.jpg'
else if (Copy(FirstBytes, 1, 3) = #$49#$49#$2A) then
fileType := '.tif'
else if (Copy(FirstBytes, 1, 3) = #$0#$0#$01) then
fileType := '.ico';
finally
result:=(fileType<>'');
end;
end;
...
end.
Para el resto de extensiones simplemente hay que buscar las cabezeras que utilizan y añadirlas a la lista
Un saludo