1. 程式人生 > >Delphi內的圖片縮放的實現

Delphi內的圖片縮放的實現

procedure ResizeBmp(Src,Dst:String);
var SrcBM,DstBM:TBitMap;
    Rect:TRect;
    NewW,NewH,PicW,PicH:Integer;
    HDivW:Double;
begin
  SrcBM:
=TBitMap.Create;
  SrcBM.LoadFromFile(Src);
  PicW:
=SrcBM.Width;
  PicH:
=SrcBM.Height;
  NewH:
=768;
  NewW:
=1024;
  DstBM:
=TBitMap.Create;
  with DstBM 
do begin
    Width:
=
NewW;
    Height:
=NewH;
    Rect.TopLeft:
=Point(0,0);
    Rect.BottomRight:
=Point(NewW,NewH);
    Canvas.Rectangle(
0,0,Width,Height);
    Canvas.StretchDraw(Rect,TGraphic(SrcBM));
    SaveToFile(Dst);
    FreeImage;
    Free;
  end;
end;