// 僅獲取文件夾 內的 文件 function GetFiles(Path, ext: string): TStringList; var Rec: TSearchRec; Lst: TStringList; begin if Path[Length(Path)] <> '\' then Path := Path + '\'; Lst := TStringList.Create; if FindFirst(Path + '*' + ext, faAnyFile, Rec) = 0 then repeat if Rec.Attr and faDirectory >= 1 then continue; // 跳過文件夾 Lst.Add(Path + Rec.Name); until FindNext(Rec) <> 0; System.SysUtils.FindClose(Rec); Result := Lst; end; procedure TForm1.ScrewJpg(FromFile, ToFile: string); var Skew: real; begin ImageEnView1.IO.LoadFromFile(FromFile); Skew := ImageEnView1.Proc.SkewDetectionFine(); ImageEnView1.Proc.Rotate(Skew); ImageEnView1.IO.SaveToFileJpeg(ToFile); end; procedure TForm1.btnScrewClick(Sender: TObject); var i: Integer; lst: TStringList; FromFile, ToFile, NewPath: string; begin NewPath := Trim(leJpgPath.Text); try lst := GetFiles(NewPath, '.jpg'); Memo1.Text := Format('共找到 %d 個圖像:', [lst.Count]) + #$D#$A + lst.Text; finally lst.Free; end; if Memo1.Lines.Count < 2 then begin ShowMessage('沒有找到圖像.'); exit; end; lst := TStringList.Create; NewPath := leJpgPath.Text + '\糾偏後\'; forcedirectories(NewPath); lst.Text := Memo1.Text; Screen.Cursor := crHourGlass; try for i := 1 to lst.Count - 1 do begin FromFile := lst[i]; ToFile := NewPath + ExtractFileName(FromFile); ScrewJpg(FromFile, ToFile); end; ShowMessage(Format('%d', [lst.Count]) + ' 個圖像糾偏完成.'); finally lst.Free; Screen.Cursor := crDefault; end; end; procedure TForm1.btnSelectDirClick(Sender: TObject); var path: string; FileList: TStringList; begin if SelectDirectory('選擇目錄 ', ' ', path) then begin leJpgPath.Text := path; try FileList := GetFiles(Path, '.jpg'); Memo1.Text := Format('共找到 %d 個圖像:', [FileList.Count]) + #$D#$A + FileList.Text; finally FileList.Free; end; end; end;