class function TGGraphicUtils.GetImageStreamType(AImageStream: TStream;
ASpeedGet: Boolean): TGImageStreamType;
const
cSBMPCodeStr = '424D';
cSICOCodeStr = '000001';
cSJPGCodeStr = 'FFD8FFE000104A464946';
cSGIFCodeStr = '474946';
cSWMFCodeStr = 'D7CDC69A';
cSTIFCodeStr = '49492A0008';
var
vCode: array [0..9] of Char;
vCodeStr: string;
I, vOldPos: Integer;
begin
if ASpeedGet then
begin
vOldPos := AImageStream.Position;
AImageStream.Position := 0;
AImageStream.ReadBuffer(vCode, 1);
vCodeStr := IntToHex(Byte(vCode[0]), 2);
if vCodeStr = '42' then Result := istBMP
else if vCodeStr = '00' then Result := istICO
else if vCodeStr = 'FF' then Result := istJPG
else if vCodeStr = '47' then Result := istGIF
else if vCodeStr = 'D7' then Result := istWMF
else if vCodeStr = '49' then Result := istTIF
else Result := istCustom;
AImageStream.Position := vOldPos;
end
else begin
vOldPos := AImageStream.Position;
AImageStream.Position := 0;
AImageStream.ReadBuffer(vCode, 10);
for I := 0 to 9 do
vCodeStr := vCodeStr + IntToHex(Byte(vCode), 2);
if Pos(cSBMPCodeStr, vCodeStr) = 1 then Result := istBMP
else if Pos(cSICOCodeStr, vCodeStr) = 1 then Result := istICO
else if Pos(cSJPGCodeStr, vCodeStr) = 1 then Result := istJPG
else if Pos(cSGIFCodeStr, vCodeStr) = 1 then Result := istGIF
else if Pos(cSWMFCodeStr, vCodeStr) = 1 then Result := istWMF
else if Pos(cSTIFCodeStr, vCodeStr) = 1 then Result := istTIF
else Result := istCustom;
AImageStream.Position := vOldPos;
end;
end;