BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

detecting pixels of certain color

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Paul Nicholls
Guest





PostPosted: Tue Aug 23, 2005 5:59 am    Post subject: Re: detecting pixels of certain color Reply with quote



"SupportX" <SupportX (AT) SupportX (DOT) com> wrote

Quote:
Subject: detecting pixels of certain color

Hi,

I have a small bitmap. I wish to scan one horizontal line in it (the
middle one) from left to right, and determine which points on this line
are black.

How to?

TIA,

SupportX

you have two options:

1) use TBitmap.Canvas.Pixels[x,y] - easiest by far, but slow!
2) use TBitmap.Scanline[] - more difficult to code, but much faster!

cheers,
Paul



Back to top
Charles Hacker
Guest





PostPosted: Tue Aug 23, 2005 6:06 am    Post subject: Re: detecting pixels of certain color Reply with quote



SupportX wrote:
Quote:

I have a small bitmap. I wish to scan one horizontal line in it (the middle one) from left to right, and determine which points on this line are black.

How close to black?
Lets assume black is colour (0-255) less than '4' intensity!


var Line: PByteArray;
X,Y,col: Integer;

Bitmap.Pixelformat:= pf24bit;
{note this code only works with 24 bit RGB color images}

col:= 0;
Y:= Bitmap.Height DIV 2;
Line:= Bitmap.Scanline[Y];
for X := 0 to Bitmap.Width-1 do
begin
// Red is Line[X*3 ]
// Green Line[X*3+1]
// Blue Line[X*3+2]
if (Line[X*3]<4 and Line[X*3+1]<4 and Line[X*3+2]<4) then
begin
// Color is black
INC(col);
end;
end;

ShowMessage(IntToStr(col)+' Pixels were black');


--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia

Back to top
SupportX
Guest





PostPosted: Tue Aug 23, 2005 6:49 am    Post subject: detecting pixels of certain color Reply with quote



Subject: detecting pixels of certain color

Hi,

I have a small bitmap. I wish to scan one horizontal line in it (the middle one) from left to right, and determine which points on this line are black.

How to?

TIA,

SupportX


Back to top
SupportX
Guest





PostPosted: Tue Aug 23, 2005 7:34 pm    Post subject: Re: detecting pixels of certain color Reply with quote

Subject: Re: detecting pixels of certain color

Thanks, worked like a charm!


Back to top
Francesco Savastano
Guest





PostPosted: Wed Aug 31, 2005 2:36 pm    Post subject: Re: detecting pixels of certain color Reply with quote

Quote:
// Red is Line[X*3 ]
// Green Line[X*3+1]
// Blue Line[X*3+2]

Actually Red is Line[X*3+2] and Blue is Line[X*3 ]




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.