Link to home
Start Free TrialLog in
Avatar of fuluppi
fuluppi

asked on

CopyRect from one Bitmap to another

Dear experts,
I have got a camera image 240x320 px which comes 6 times
per second. I need to copy a specific part out of the image
into another one. This must be really fast !!! I tried using
the canvas.CopyRect function (code below) but this is extremely
slow and makes my CPU going up to 100%.

I need a working solution (code) very fast.

Thanks a lot
fuluppi

My code example:

 b:=TBitmap.Create;
  b.Width := 320;
  b.Height := 240;
  b.LoadFromStream(ms);
  b.Canvas.FillRect(Rect(0,0,320,100));
  b.Canvas.FillRect(Rect(0,150,320,240));
 
n := TBitmap.Create;
n.width := 190;
n.height := 100;

//THIS IS SO SLOW !!!
n.Canvas.CopyRect(rect(0,0,190,100),b.Canvas,Rect(60,100,250,200));

  image1.Picture.Bitmap := b;
Avatar of mokule
mokule
Flag of Poland image

try ScanLine.
In a few moments I'll give You some code
Avatar of kretzschmar
use the bitblt-api
ASKER CERTIFIED SOLUTION
Avatar of mokule
mokule
Flag of Poland 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
All right meikl
BitBlt is 6 times faster
yep, just got no time for a sample yesterday,
but you did this already mokule, you deserves the points,
if this is the solution

meikl ;-)
Avatar of fuluppi
fuluppi

ASKER

hi !
i tried bitblt. it works fine and pretty fast with a TImage but when I try to copy thge rectangle into a new bitmap
it doesn't work any longer. why ???

  b:=TBitmap.Create;
  b.Width := 320;
  b.Height := 240;
  b.LoadFromStream(ms);

  b1:=TBitmap.Create;
  b1.Width  := 320;
  b1.Height := 100;

  BitBlt (b1.Canvas.Handle,0,0,320,100,b.Canvas.Handle,0,0,srccopy);

I'm not able to pass b1 as parameter to a component for further processing....

thanks
Philip
Hi

Set
b1.PixelFormat := b.PixelFormat;