从流数据获知文件类型

从流数据获知文件类型

function StreamGetFileType(aStream:TStream):String;
var Buffer:Word;
begin
  Result := '';
  aStream.Position := 0;
  if aStream.Size=0 then
   exit;
  aStream.ReadBuffer(Buffer,2);
  case Buffer of
    $4D42:Result := 'bmp';
    $D8FF:Result := 'jpeg';
    $4947:Result := 'gifp';
    $050A:Result :='pcx';
    $5089:Result :='png';
    $4238:Result :='psd';
    $A659:Result :='ras';
    $DA01:Result :='sgi';
    $4949:Result :='tiff';
  end;
end;

  

原文地址:https://www.cnblogs.com/hnxxcxg/p/11124571.html