图片的简单截取与拉伸

procedure TForm1.Button1Click(Sender: TObject);

var

 winHWND, hCur:integer;

 winDC:integer;

 rect1,rect2:TRect;

 pt:TPoint;

 fBitmap,BGBitmap:TBitmap;

 Width,Height:integer;

begin

  winHWND := GetDesktopWindow();

 winDC := GetDC(winHWND);

 GetWindowRect(winHWND, rect1);

 fBitmap := TBitmap.create;

  fBitmap.width :=100;

  fBitmap.height := 50;

  BitBlt(fBitmap.canvas.handle, 0, 0, 100,50, winDC,500, 200, SRCCOPY); //截图    ReleaseDC(winHWND, winDC); //释放DC

  fBitmap.SaveToFile('c:/test1.bmp');

 BGBitmap := TBitmap.create;

 Width:=fBitmap.Width*2; //图像放大倍数

  Height:= fBitmap.Height*2;

  BGBitmap.Width:=Width;

 BGBitmap.Height:= Height;

  rect2:=Rect(0,0,Width,Height);

  BGBitmap.Canvas.StretchDraw(rect2,fBitmap);

  BGBitmap.SaveToFile('c:/test2.bmp'); // Image1.Picture.Bitmap.Assign(fBitmap); //将bitmap图片显示在image1中

  fBitmap.Free;

 BGBitmap.Free;

end;

你可能感兴趣的:(图片的简单截取与拉伸)