• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 553
  • Last Modified:

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?
0
ITugay
Asked:
ITugay
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now