Board index » delphi » Quick-count colour bitmap pixels

Quick-count colour bitmap pixels

Quick-count colour bitmap pixels

Is there a quick way to count how much of a bitmap contains a
particular color, i.e. how many pixels in a bitmap area are
red, for example.

Slow method:

      for x:=x1 to x2 do begin
         for y:=y1 to y2 do begin
            if CountBitMap.canvas.pixels[x,y]=CountColor then
               Counter:=Counter+1;
         end;
      end;

Smarter?

Please email me. I thankfully reply.
--------------------------------------------
M...@lottery.powernet.co.uk
--------------------------------------------
Sorry, I do not have a return address in my message header to avoid
the email gathering robots. Please cut and paste my email from here
thanks. M...@lottery.powernet.co.uk

Please email me. I thankfully reply.
--------------------------------------------
M...@lottery.powernet.co.uk
--------------------------------------------
Sorry, I do not have a return address in my message header to avoid
the email gathering robots. Please cut and paste my email from here
thanks. M...@lottery.powernet.co.uk

 

Re:Quick-count colour bitmap pixels


In article <374f1...@news.power.net.uk>,
  PleaseSeeAddr...@TheBottom.OfMyMessage.co.uk  wrote:

Quote
> Quick-count colour bitmap pixels

> Is there a quick way to count how much of a bitmap contains a
> particular color, i.e. how many pixels in a bitmap area are
> red, for example.

> Slow method:

>       for x:=x1 to x2 do begin
>          for y:=y1 to y2 do begin
>             if CountBitMap.canvas.pixels[x,y]=CountColor then
>                Counter:=Counter+1;
>          end;
>       end;

> Smarter?

     Well there's no clever way to count how many red
pixels there are, you do have to look at each pixel and
see whether it's red. (Or have something else do it for
you). But there's a much faster way: use Scanline
instead of Canvas.Pixels in the same loop.

     (If you want to count the red pixels and also count
the black and white pixels there are smart and not so
smart ways to do _that_. The not so smart way would be
to repeat this loop three times, once for each color.)

- Show quoted text -

Quote
> Please email me. I thankfully reply.
> --------------------------------------------
> M...@lottery.powernet.co.uk
> --------------------------------------------
> Sorry, I do not have a return address in my message header to avoid
> the email gathering robots. Please cut and paste my email from here
> thanks. M...@lottery.powernet.co.uk

> Please email me. I thankfully reply.
> --------------------------------------------
> M...@lottery.powernet.co.uk
> --------------------------------------------
> Sorry, I do not have a return address in my message header to avoid
> the email gathering robots. Please cut and paste my email from here
> thanks. M...@lottery.powernet.co.uk

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Other Threads