Link to home
Start Free TrialLog in
Avatar of Manuel Lopez-Michelone
Manuel Lopez-MicheloneFlag for Mexico

asked on

stretchdraw ... how to use it?

Guys,

I want to copy a region of a timage to another timage, but I want that region of timage fit completely into the second timage. I am sure i have to use stretchdraw, but i can't figure out how to do this. Any help?

best wishes,
Manuel Lopez (lopem)
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

hello lopem, getting a part (or region) of one TImage to fill another TImage will use the Canvas.StretchDraw procedure. But first you need to make a Bitmap copy of that region and then stretch that bitmap into the second Image. You will have to get the Rectangle size and placement of the the part of the first Image you want to get into the second Image.

{Image1 and Image2 are TImages, Image1 is 250 wide and 150 tall, ,
Image2 is 120 wide and 50 tall}

procedure TForm1.CopyRectOfImage;
var
TempBit: TBitmap;
CopyRect: TRect;
begin
TempBit := TBitmap.Create;
// define the Rect that will be copied from Image1
CopyRect := := Rect(17,36,117,136);
// Set the width and height of TempBit to equal CopyRect
TempBit.Height := CopyRect.Bottom - CopyRect.Top;
TempBit.Width := CopyRect.Right - CopyRect.Left;
// Copy the Rect to Tempbit
Tempbit.Canvas.CopyRect(Rect(0,0,Tempbit.Width, Tempbit.Heigh), Image1.Canvas, CopyRect);
// StretchDraw the Tempbit to fill Image2
Image2.Canvas.StretchDraw(Rect(0,0,Image2.Width, Image2.Height), Tempbit);
Tempbit.Free;
end;

the new image in Image2 will be stretched and distorted. . . if you don't want it to be distorted then set the CopyRect to the width and height of Image2
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Manuel Lopez-Michelone

ASKER

thanks a lot!
great job

Manuel Lopez (lopem)