当前位置:首页 > Windows程序 > 正文

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

2024-03-31 Windows程序

判断头几个字节:

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;

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

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/57812.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494635访问次数
  • 建站天数
  • 友情链接