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

Delphi图片格式判断

时间:2015-09-23 14:54:04      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

procedure TForm1.CheckImgType(fn: string);
var
  MyImage: TMemoryStream;
  Buffer: Word;
  i: integer;
begin
  MyImage := TMemoryStream.Create;
  try
    MyImage.LoadFromFile(fn);
    MyImage.Position := 0;
    if MyImage.Size = 0 then
    begin
      ShowMessage(错误);
      Exit;
    end;
    MyImage.ReadBuffer(Buffer, 2);
    if Buffer = $4D42 then
    begin
      ShowMessage(BMP);
    end
    else if Buffer = $D8FF then
    begin
      ShowMessage(JPEG);
    end
    else if Buffer = $4947 then
    begin
      ShowMessage(GIF);
    end
    else if Buffer = $050A then
    begin
      ShowMessage(PCX);
    end
    else if Buffer = $5089 then
    begin
      ShowMessage(PNG);
    end
    else if Buffer = $4238 then
    begin
      ShowMessage(PSD);
    end
    else if Buffer = $A659 then
    begin
      ShowMessage(RAS);
    end
    else if Buffer = $DA01 then
    begin
      ShowMessage(SGI);
    end
    else if Buffer = $4949 then
    begin
      ShowMessage(TIFF);
    end
    else //如是其他类型的文件的话,直接显示错误
    begin
      ShowMessage(ERR);
    end;

  finally
    MyImage.Free;
  end;
end;

 

Delphi图片格式判断

标签:

原文地址:http://www.cnblogs.com/jieke/p/4831960.html

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