用户名: 密   码:
   飞诺网 加入收藏
飞诺网 网站开发 VBScript ASP Asp.net Jsp php XML CGI-Perl 搜索引擎 ajax web技术
.net系列教程 .net实例 .Net技术文档

您当前的位置:飞诺网 >> .net >> .net实例

缩略图批量生成器

www.diybl.com    时间 : 2010-06-28  作者:佚名   编辑:Mr.阿布 点击:   [ 评论 ]

 

主要功能:

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;

如果图片或页面不能正常显示请点击这里
.net实例推荐文章

文章评论