//保存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;我改的!!
procedure TForm1.Button4Click(Sender: TObject);
var
pp:TBitmap;
Width,Height:integer;
tmpInt:double;//用了double提高精确度不然会没有一块!
begin
if bmp.Width >= bmp.Height then
tmpInt := bmp.Width / Image1.Width
else
tmpInt := bmp.Height / Image1.Height;
Width := Round(bmp.Width / tmpInt); Height :=Round( bmp.Height / tmpInt);
pp:=TBitmap.Create;
pp.Width:=width;
pp.Height:=height;
pp.PixelFormat:=pf24bit;
pp.Canvas.StretchDraw(rect(0,0,Width,Height),bmp);
Image1.Picture.Bitmap.FreeImage;
Image1.Picture.Bitmap.Assign(pp);
pp.Free;
end;是拿来适应窗口用的希望能帮到大家!
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;我改的!!
procedure TForm1.Button4Click(Sender: TObject);
var
pp:TBitmap;
Width,Height:integer;
tmpInt:double;//用了double提高精确度不然会没有一块!
begin
if bmp.Width >= bmp.Height then
tmpInt := bmp.Width / Image1.Width
else
tmpInt := bmp.Height / Image1.Height;
Width := Round(bmp.Width / tmpInt); Height :=Round( bmp.Height / tmpInt);
pp:=TBitmap.Create;
pp.Width:=width;
pp.Height:=height;
pp.PixelFormat:=pf24bit;
pp.Canvas.StretchDraw(rect(0,0,Width,Height),bmp);
Image1.Picture.Bitmap.FreeImage;
Image1.Picture.Bitmap.Assign(pp);
pp.Free;
end;是拿来适应窗口用的希望能帮到大家!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货