Check image for rgb

What's the best and *fastest* way to check an image for a certain rgb color?  If it contains that color, how can I get the X,Y of where the color is in the image?
Grant FullenAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mokuleConnect With a Mentor Commented:
You need to use scanline which gives You an address of image row bytes array.
The index to scanline gives You Y, and the index to fthe bytes array gives You X.
0
 
JohnjcesConnect With a Mentor Commented:
You might try: (not tested)...

type
  TRGBArray = array[0..32767] of TRGBTriple;
  PRGBArray = ^TRGBArray;

var
 MyRed, MyGrn, MyBlu : Integer;
 X, Y : Integer;
  Row: PRGBArray;
begin
 Bmp.PixelFormat := pf24Bit;
 {Y is the pixel row of the pixel you want}
 Row := Bmp.ScanLine[Y];
 {X is the position in the row or column or the pixel}
 MyRed := Row[x].rgbtRed;
 MyGrn := Row[x].rgbtGreen;
 MyBlu := Row[x].rgbtBlue;
end;

This is not tested, off the top of my head, sort of, but might get you started.

I believe that you can add the results and get you RGB color of that pixel.

John
0
 
mokuleCommented:
Bmp.PixelFormat := pf24Bit;
This is not a good option to change bitmap format.
The rest of code should rather depend on on Bmp.PixelFormat value

In the case of pf24Bit should be
 MyRed := Row[3*x+2].rgbtRed;
 MyGrn := Row[3*x+1].rgbtGreen;
 MyBlu := Row[3*x].rgbtBlue;
0
 
mokuleCommented:
Hehe TRGBTriple. My comment is not valid in the second part
0
All Courses

From novice to tech pro — start learning today.