图片扫描纠偏java_Delphi 下 用 ImageEN 进行图像纠偏

// 仅获取文件夹 内的 文件

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值