INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to select a rectangular portion of a TImage Bitmap?

How to select a rectangular portion of a TImage Bitmap?

(OP)
I have a Bitmap image and need to select a particular position rectangular to select this position I must save her.

Example: Picture 800x600 size to be located / copied somewhere 300x400 photo where is the face of a person.

I found several examples but none that me an idea of ​​how to do this sad Examples for very complex tasks that I will not use. If I have not been clear, let me know. Sorry for my english.

RE: How to select a rectangular portion of a TImage Bitmap?

Hi jhcbrito...

I hope this is usefull... Use TCanvas.CopyRect method.

Code examples from Embarcadero.

{
The following code illustrates the differences between
CopyRect and BrushCopy. The bitmap graphic ‘FACTORY.BMP’ is
loaded into Bitmap and displayed on the Canvas of Form1.
BrushCopy replaces the color black in the graphic with the
brush of the canvas, while CopyRect leaves the colors intact.
}
procedure TForm1.Button1Click(Sender: TObject);
var
Bitmap: TBitmap;
MyRect, MyOther: TRect;
begin
MyRect := Rect(10,10,150,150);
MyOther := Rect(10,161,150,301);
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile(
'c:\Program Files\Common Files\CodeGear Shared\Images\Splash\256color\factory.bmp');
Form1.Canvas.BrushCopy(MyRect, Bitmap, MyRect, clBlack);
Form1.Canvas.CopyRect(MyOther,Bitmap.Canvas,MyRect);
Bitmap.Free;
end;
Copy Code
{
The following example uses the CopyMode of an image’s canvas
to blank out the image when the user chooses the "Cut" menu
item. This example requires a Main menu with a Copy and a
Cut menu item that have their OnClick error handlers populated.
Note: CopyMode and CopyRect are members of the destination
canvas.
}
procedure TForm1.Copy1Click(Sender: TObject);
var
DstRect, SrcRect: TRect;
begin
with Image2.Canvas do
begin
CopyMode := cmSrcCopy;
DstRect := Rect(0, 0, Image2.Width, Image2.Height);
SrcRect := Rect(0, 0, Image1.Width, Image1.Height);
CopyRect(DstRect, Image1.Canvas, SrcRect);
end;
end;

procedure TForm1.Cut1Click(Sender: TObject);
var
ARect: TRect;
begin
Copy1Click(Sender); { do the same thing as the copy menu item }
with Image1.Canvas do
begin
CopyMode := cmWhiteness;
ARect := Rect(0, 0, Image1.Width, Image1.Height);
CopyRect(ARect, Image1.Canvas, ARect);
CopyMode := cmSrcCopy; { restore the copy mode }
end;
end;

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close