I would like to load an image, and read pixels to find a certain RGB, but then check the next pixels across to make sure they match, and i am at the right position of the bitmap.
I know the below code is wrong, but i am not sure how to go about correcting it. I also know Pixels is not the fastest way to read pixels.
Thanks guys!
procedure RGB(Col: TColor; var R, G, B: Byte);
var
Color: $0..$FFFFFFFF;
begin
Color := ColorToRGB(Col);
R := ($000000FF and Color);
G := ($0000FF00 and Color) Shr 8;
B := ($00FF0000 and Color) Shr 16;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x,y : Integer;
ColorN: TColor;
R, G, B: Byte;
begin
for Y := 0 to Image1.Picture.Bitmap.Height -1 do
begin
for X := 0 to Image1.Picture.Bitmap.Width -1 do
begin
inc(i);
ColorN := Image1.Canvas.Pixels[x, y];
RGB(ColorN, R, G, B);
//Memo1.Lines.Append('Line: '+IntToStr(i)+' Y: '+IntToStr(Y)+' X: '+IntToStr(X)+' R: '+IntToStr(R)+' G: '+IntToStr(G)+' B: '+IntToStr(B));
if (IntToStr(R) = '235') and (IntToStr(G) = '235') and (IntToStr(B) = '235') then //Y: 500 X: 587
begin
//Image1.Canvas.MoveTo(X,Y);
//Image1.Canvas.LineTo(X,Y);
ColorN := Image1.Canvas.Pixels[x +1, y];
RGB(ColorN, R, G, B);
end;
if (IntToStr(R) = '232') and (IntToStr(G) = '232') and (IntToStr(B) = '232') then //RGB:232,232,232 Y: 500 X: 588
begin
ColorN := Image1.Canvas.Pixels[x +1, y];
RGB(ColorN, R, G, B);
ShowMessage('Test1');
end;
if (IntToStr(R) = '231') and (IntToStr(G) = '231') and (IntToStr(B) = '231') then //RGB: 231,231,231 Y: 500 X: 589
begin
ColorN := Image1.Canvas.Pixels[x +1, y];
RGB(ColorN, R, G, B);
ShowMessage('Test2');
end;
if (IntToStr(R) = '230') and (IntToStr(G) = '230') and (IntToStr(B) = '230') then //RGB: 230,230,230 Y: 500 X: 590
begin
ShowMessage('Test3');
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
b: TBitmap;
begin
Image1.Picture.LoadFromFile('E:\Delphi Projects\Detect(XE6)\screen\1.png');
b := TBitmap.Create;
b.Assign(Image1.Picture.Graphic);
Image1.Picture.bitmap := b;
FreeAndNil(b);
end;