您现在的位置:首页 >> 图形媒体 >> 图形媒体 >> 内容

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

时间:2011/9/3 15:00:58 点击:

  核心提示:function IsJpegFile(FileName: string): Boolean;constRightBuf : array[0..3] of Byte = ($FF,$D8,$FF,$D...

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;

作者:LihuaSoft 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号