// 仅获取文件夹 内的 文件
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;