delphi实现批量缩略图生成工具开发代码 [收藏本页]
  • 作者:佚名 来源:不详 发布时间:2006-12-8 16:57:37
  •  

    主要功能:

    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中使用纯正的面向对象方法
Copyright © 2003-2008 站长助手 www.web162.com
辽ICP备05001760号 网络实名:站长助手 转载本站原创教程请注名来源于本站
力倡站长资源文化,崇尚互联共享,做中国最好站长网站,为中国网站提供动力!
始建于2003-3-1 8:10 中国首都·北京 辽宁(分站)
主资源渠道辽宁电信分公司服务器组及带宽!