[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CopyRect from one Bitmap to another

Posted on 2004-08-04
7
Medium Priority
?
929 Views
Last Modified: 2010-04-05
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;
0
Comment
Question by:fuluppi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 11718776
try ScanLine.
In a few moments I'll give You some code
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11718826
use the bitblt-api
0
 
LVL 17

Accepted Solution

by:
mokule earned 2000 total points
ID: 11719052
// I don't check which is faster

// with ScanLine
procedure TForm1.Button1Click(Sender: TObject);
var
  leftsrc,topsrc: integer;
  hsrc,wsrc:integer;
  leftdst,topdst: integer;
  h,w: integer;
  rowsrc, rowdst: pByteArray;
begin
  leftsrc := 0;
  topsrc := 0;
  hsrc := 100;
  wsrc := 100;
  leftdst := 120;
  topdst := 120;
  for h := 0 to hsrc-1 do
    begin
    rowsrc := pByteArray(Image1.Picture.Bitmap.ScanLine[topsrc+h]);
    rowdst := pByteArray(Image1.Picture.Bitmap.ScanLine[topdst+h]);
    for w := 0 to wsrc-1 do
      begin
      // assumming pixelformat pf24bit
      rowdst[3*(leftdst+w)] := rowsrc[3*(leftsrc+w)];
      rowdst[3*(leftdst+w)+1] := rowsrc[3*(leftsrc+w)+1];
      rowdst[3*(leftdst+w)+2] := rowsrc[3*(leftsrc+w)+2];
      end;
    end;
  Image1.Invalidate;
end;

// with BitBlt

procedure TForm1.Button2Click(Sender: TObject);
var
  leftsrc,topsrc: integer;
  hsrc,wsrc:integer;
  leftdst,topdst: integer;
begin
  leftsrc := 0;
  topsrc := 0;
  hsrc := 100;
  wsrc := 100;
  leftdst := 120;
  topdst := 120;
  BitBlt(Image1.Canvas.Handle,leftdst,topdst,wsrc,hsrc,
          Image1.Canvas.Handle,leftsrc,topsrc,SRCCOPY);
  Image1.Invalidate;
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:mokule
ID: 11719340
All right meikl
BitBlt is 6 times faster
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11723472
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 ;-)
0
 

Author Comment

by:fuluppi
ID: 11888369
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
0
 
LVL 17

Expert Comment

by:mokule
ID: 11889529
Hi

Set
b1.PixelFormat := b.PixelFormat;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question