delphi实现批量缩略图生成工具开发代码

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

主要功能:[/url]

1 生成指定图片的缩略图

2 批量生成某一目录内所有图片缩略图

3 提供5中缩略图尺寸定义模式

4 目前只支持.jpg格式

测试版下载:[url=http://bjfile.focus.cn/file/15483/728_MJpg.rar]http://bjfile.focus.cn/file/15483/728_MJpg.rar

核心代码:

//保存JPEG的缩略图

procedure SavePic(SourceFileName,DescFileName: String);

const

MaxWidth = 200 ;

MaxHigth = 200 ;

var

jpg: TJPEGImage;

bmp: TBitmap;

SourceJpg: TJPEGImage;

Width, Height,tmpInt: Integer;

begin

try

bmp := TBitmap.Create;

SourceJpg := TJPEGImage.Create;

Jpg:= TJPEGImage.Create;

//读取源文件

SourceJpg.LoadFromFile(SourceFileName);

//计算缩小比例

if SourceJpg.Width >= SourceJpg.Height then

tmpInt := Round(SourceJpg.Width div MaxWidth)

else

tmpInt := Round(SourceJpg.Height div MaxHigth) ;

Width := SourceJpg.Width div tmpInt ;

Height := SourceJpg.Height div tmpInt ;

//缩小

bmp.Width := Width;

bmp.Height := Height;

bmp.PixelFormat := pf24bit;

bmp.Canvas.StretchDraw(Rect(0,0,Width,Height), SourceJpg);

//保存

jpg.Assign(bmp);

jpg.SaveToFile(DescFileName);

finally

bmp.Free;

jpg.Free;

SourceJpg.Free;

end;

end;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航