TCanvas to TBitmap.

I have a TBitmap and need to copy portion of TCanvas to it.
Something like this:

procedure CopyCanvas(aBitmap : TBitmap; aCanvas : TCanvas; aRect : TRect);
begin
   //  implementation wanted.
end;

PS: I can do it pixel by pixel, but it's incredible slow. There may be BitBlt function?
LVL 9
ITugayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hi,

this is quite easy:

procedure CopyCanvas(aBitmap : TBitmap; aCanvas : TCanvas; aRect : TRect);
begin
  aBitmap.Canvas.CopyRect(aRect, aCanvas, aRect);
end;

This will copy the image part to the same location in the bitmap as it was on the canvas. If you wanna change this then specify also a new destination rectangle (first parameter in CopyRect).

Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TheNeilCommented:
aBitmap.Canvas.CopyRect(aRect, aCanvas, aRect);

This copies the section specified in aRect into exactly the same position on the destination (aBitmap in this case). If you want to copy it to another position then you'll need to modify your parameter list and the CopyRect call:

procedure CopyCanvas(aBitmap : TBitmap; aCanvas : TCanvas; srcRect, destRect : TRect);
BEGIN
  aBitmap.Canvas.CopyRect(destRect, aCanvas, srcRect);
END;

The Neil
0
ITugayAuthor Commented:
Thanx all, faster method, faster answer!
0
LischkeCommented:
Yup, you are welcome :-)

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.