掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
画像ファイルのみ対応させるには? (ID:10685)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
拡張子で判断する方法もありますが、質問者のレベルからすると こちらを望んでるのかな? function checkImageFormat(path:string):integer; // -1: 不明 // 0: bmp // 1: jpg // 2: gif // 3: 拡張メタファイル emf var F:File; Buf: array[0..50] of Char; i,j,Attrs:integer; ext:string; begin result:=-1; ext:=AnsiLowerCase(ExtractFileExt(path)); if FileExists(path)=True then begin Attrs := FileGetAttr(path); if Attrs and faReadOnly <> 0 then SetFileAttributes(PChar(path),Attrs - faReadOnly); try AssignFile(F,path); Reset(F,1); BlockRead(F, Buf, 50, i); if (Word(Buf[0])=$FF) and (Word(Buf[1])=$D8) and (Word(Buf[2])=$FF) then result:=1; if (Word(Buf[0])=$42) and (Word(Buf[1])=$4D) then result:=0; if (Word(Buf[0])=$47) and (Word(Buf[1])=$49) and (Word(Buf[2])=$46) then result:=2; if (Word(Buf[40])=$20) and (Word(Buf[41])=$45) and (Word(Buf[42])=$4D) and (Word(Buf[43])=$46) then result:=3; finally if Attrs and faReadOnly <> 0 then SetFileAttributes(PChar(path),Attrs); CloseFile(F); end; end; end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.