delphi 改变位图图片大小

2018-10-30

delphi 改变位图图片大小
procedure pic_fitbmp(const Source,Dest:string;const x,y:integer);
var
abmp,bbmp:tbitmap;
scalex,scaley:real;
begin
abmp:=tbitmap.Create;
bbmp:=tbitmap.Create;
try
abmp.LoadFromFile(Source);
scaley:=abmp.Height/y;
scalex:=abmp.Width/x;
bbmp.Width:=round(abmp.Width/scalex);
bbmp.Height:=round(abmp.Height/scaley);
bbmp.PixelFormat:=pfDevice;
SetStretchBltMode(bbmp.Canvas.Handle,COLORONCOLOR);
stretchblt(bbmp.Canvas.Handle,0,0,bbmp.Width,bbmp.Height,abmp.Canvas.Handle,0,0,abmp.Width,abmp.Height,srccopy);
bbmp.SaveToFile(Dest);
finally
abmp.Free;
bbmp.Free;
end;
end;
阅读58