当前位置:主页>Delphi教程>文章内容
delphi实现批量缩略图生成工具开发代码
来源: 作者: 发布时间:2007-04-29  
 

主要功能:

1 生成指定图片的缩略图
2 批量生成某一目录内所有图片缩略图
3 提供5中缩略图尺寸定义模式
4 目前只支持.jpg格式

测试版下载: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;


 
上一篇:Delphi中使用纯正的面向对象方法   下一篇:如何用Delphi编写自己的可视化控件
 
  相关文章
·Delphi中使用纯正的面向对象方法
·如何用Delphi编写自己的可视化控件
·FindWindowEX的一个应用实例
·使TStringGrid自适应宽度
·LineDDA的一个例子
·关于DBGrid的分类颜色显示
·巧用DBGrid控件的Sort属性实现“点击标
·Delphi和Office程序开发
·修正XPMenu的两个Bug
·模拟Nokia手机输入的编辑框
·delphi小技巧集锦
·类似Access查找中的记忆功能
 
【关闭窗口】
推荐本站资源
最新文章