var
bmp,backbmp:TBitmap;
begin
backbmp:=TBitmap.Create;
backbmp.Assign(Image1.Picture.Bitmap);
try
bmp:=TBitmap.Create;
bmp.PixelFormat:=pf24bit;
Image1.AutoSize:=True;
bmp.Width:=trunc(0.9*Image1.Width);
bmp.Height:=trunc(0.9*Image1.Height);
//保持最大限度不失真
SetStretchBltMode(bmp.Canvas.Handle,HALFTONE);
StretchBlt(bmp.Canvas.Handle,0,0,bmp.Width,bmp.Height,
backbmp.Canvas.Handle,0,0,backbmp.Width,backbmp.Height,SRCCOPY);
Image1.Picture.Bitmap.Assign(bmp);
Image1.Top:=Self.Height div 2-Image1.Height div 2;
Image1.Left:=Self.Width div 2-Image1.Width div 2;
bmp.PixelFormat:=pf24bit;
Self.Caption:='图象尺寸为:'+IntToStr(Image1.Width)+'*'+IntToStr(Image1.Height);
bmp.Free;
except
end;
backbmp.Free;
backbmp:=nil;
评论