Delphi判断一个文件是不是JPG图片

判断头几个字节:

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

上一篇:Android项目实战(十九):Android Studio 优秀插件: Parcelable Code Generator


下一篇:P1879 [USACO06NOV]玉米田Corn Fields (状压dp入门)