//从内存流中判断图片格式 procedure TForm1.BitBtn4Click(Sender: TObject); var MyImage:TMemoryStream; Buffer:Word; i:integer; begin if OpenDialog1.Execute then begin MyImage:=TMemoryStream.Create; MyImage.LoadFromFile(OpenDialog1.FileName); MyImage.Position :=0; if MyImage.Size =0then begin //ERR ShowMessage('ERR'); MyImage.Free; Exit; end; MyImage.ReadBuffer(Buffer,2); if Buffer=$4D42 then begin //BMP ShowMessage('BMP'); end elseif Buffer=$D8FF then begin //JPEG ShowMessage('JPEG'); end elseif Buffer=$4947then begin //GIF ShowMessage('GIF'); end elseif Buffer=$050A then begin //PCX ShowMessage('PCX'); end elseif Buffer=$5089then begin //PNG ShowMessage('PNG'); end elseif Buffer=$4238then begin //PSD ShowMessage('PSD'); end elseif Buffer=$A659 then begin //RAS ShowMessage('RAS'); end elseif Buffer=$DA01 then begin //SGI ShowMessage('SGI'); end elseif Buffer=$4949then begin //TIFF ShowMessage('TIFF'); end else begin //ERR ShowMessage('ERR'); end; MyImage.Free; end; end;
判断内存流中的图片格式代码如下://从内存流中判断图片格式procedure TForm1.BitBtn4Click(Sender: TObject);var MyImage:TMemoryStream; Buffer:Word; i:integer;begin if OpenDialog1.Execute then begin My