From: Kerstin Thaler Subject: Re: Extracting a Region Date: 16 Jul 1999 00:00:00 GMT Message-ID: <378F28DC.FDE93698@t-online.de> Content-Transfer-Encoding: 7bit References: <7ml7em$5qq23@forums.borland.com> <7mlr0b$66q26@forums.borland.com> <7mn4mc$7oc7@forums.borland.com> X-Accept-Language: de,en-US Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.delphi.graphics Here is a little example how to crop a bitmap. It only works correctly if you move the mouse from topleft to rightbottom. To make it properly you have to recalculate the concerning rectangle. implementation {$R *.DFM} var PDown : TPoint; PActually : TPoint; MouseIsDown : Boolean; procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; x, y: Integer); begin PDown := Point(x, y); PActually := Point(x, y); MouseIsDown := TRUE; Image1.Canvas.DrawFocusRect(Rect(x, y, x, y)); end; procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; x, y: Integer); begin if MouseIsDown then begin Image1.Canvas.DrawFocusRect(Rect(PDown.x, PDown.y, PActually.x, PActually.y)); PActually := Point(x, y); Image1.Canvas.DrawFocusRect(Rect(PDown.x, PDown.y, x, y)); end; end; procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; x, y: Integer); begin Image1.Canvas.DrawFocusRect(Rect(PDown.x, PDown.y, PActually.x, PActually.y)); Image1.Canvas.DrawFocusRect(Rect(PDown.x, PDown.y, x, y)); PActually := Point(x, y); MouseIsDown := FALSE; end; procedure TForm1.Button1Click(Sender: TObject); var TmpBmp : TBitmap; begin Image1.Canvas.DrawFocusRect(Rect(PDown.x, PDown.y, PActually.x, PActually.y)); TmpBmp := TBitmap.Create; with TmpBmp do try Width := Round(abs(PActually.x - PDown.x)); Height := Round(abs(PActually.y - PDown.y)); BitBlt(Canvas.Handle, 0, 0, Width, Height, Image1.Canvas.Handle, PDown.x, PDown.y, SRCCOPY); Image1.AutoSize := TRUE; Image1.Picture.Bitmap.Assign(TmpBmp); finally Free; end; end; Kerstin Robert Parrish wrote: > > Thanks Earl for the info. I want to draw a rectangle and crop the area > outside of it. I have a crop function but I need to get the > coordinates of the rectangle. > Bob