码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-12-02 07:55:37      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

判断头几个字节:

function IsJpegFile(FileName: string): Boolean;
const
RightBuf : array[0..3] of Byte = ($FF,$D8,$FF,$D9);
var
Buf: array[0..3] of Byte;
begin
FillChar(Buf, 4, 0);
with TFileStream.Create(FileName, 0) do begin
    Position := 0;
    ReadBuffer(Buf[0], 2);
    Position := Size-2;
    ReadBuffer(Buf[2], 2);
    Free;
end;
Result := CompareMem(@RightBuf[0], @Buf[0], 4);
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

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

标签:

原文地址:http://www.cnblogs.com/findumars/p/5011869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!