判断头几个字节:
function IsJpegFile(FileName: string): Boolean;
const
RightBuf : array[..] of Byte = ($FF,$D8,$FF,$D9);
var
Buf: array[..] of Byte;
begin
FillChar(Buf, , );
with TFileStream.Create(FileName, ) do begin
Position := ;
ReadBuffer(Buf[], );
Position := Size-;
ReadBuffer(Buf[], );
Free;
end;
Result := CompareMem(@RightBuf[], @Buf[], );
end; procedure TForm1.Button1Click(Sender: TObject);//测试
begin
if Self.OpenDialog1.Execute then
if IsJpegFile(Self.OpenDialog1.FileName) then
Showmessage('Is Jpg File');
end;
http://blog.csdn.net/diligentcatrich/article/details/6367077