Main functions:
1 Generate thumbnails for the specified image
2 Bulk generation of all picture thumbnails in a certain directory
3 Provides 5 thumbnail size definition mode
4 Currently only supports .jpg format
Beta version download: http://bjfile.focus.cn/file/15483/728_MJpg.rar
Core code:
//Save the thumbnail of 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;
//Read the source file
SourceJpg.LoadFromFile(SourceFileName);
//Calculate the reduction ratio
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 ;
//Shrink
bmp.Width := Width;
bmp.Height := Height;
bmp.PixelFormat := pf24bit;
bmp.Canvas.StretchDraw(Rect(0,0,Width,Height), SourceJpg);
//save
jpg.Assign(bmp);
jpg.SaveToFile(DescFileName);
Finally
bmp.Free;
jpg.Free;
SourceJpg.Free;
end;
end;