从流数据获知文件类型

从流数据获知文件类型

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;

  

posted @ 2019-07-03 09:48  delphi中间件  阅读(545)  评论(0编辑  收藏  举报