Link to home
Start Free TrialLog in
Avatar of systan
systanFlag for Philippines

asked on

delphi graphics, connect two pixel colors[red and blue] then draw a line on each point to connect

I have done a few research, but no luck, my bad, can't find any source for this,
does anyone knows how to do this?
please setup your code snippet below.

User generated image

thanks
Avatar of ThievingSix
ThievingSix
Flag of United States of America image


procedure FindAndConnect(Graphic: TBitmap; SourceColor, DestColor: TColor);
type
  TRGB32Array = Packed Array[0..(MaxInt div SizeOf(Integer)) - 1] Of Integer;
  PRGB32Array = ^TRGB32Array;
var
  CurrentLine : PRGB32Array;
  X, Y : Integer;
  StartPoint,
  EndPoint : TPoint;
begin
  Graphic.PixelFormat := pf32bit;
  FillChar(StartPoint, SizeOf(TPoint), 0);
  FillChar(EndPoint, SizeOf(TPoint), 0);
  For Y := 0 To Graphic.Height - 1 Do
    begin
    CurrentLine := PRGB32Array(Graphic.Scanline[Y]);
    For X := 0 To Graphic.Width - 1 Do
      begin
      If (CurrentLine^[X] XOR SourceColor) = 0 Then
        begin
        StartPoint := POINT(X, Y);
      end
      Else If (CurrentLine^[X] XOR DestColor) = 0 Then
        begin
        EndPoint := POINT(X, Y);
      end;
    end;
  end;
  Graphic.Canvas.Pen.Color := clBlack;
  Graphic.Canvas.Pen.Width := 1;
  Graphic.Canvas.PenPos := StartPoint;
  Graphic.Canvas.LineTo(EndPoint.X, EndPoint.Y);
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  FindAndConnect(Image1.Picture.Bitmap, clRed, clBlue);
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  Image1.Picture.LoadFromFile('C:\test.bmp');
end;

Open in new window

Avatar of systan

ASKER

hi ThievingSix;

with that .bmp, It can connect both lines, but if I will use a graphic bmp file pictures, why it can't

I'll close this post after this and answer;
Actually I'm detecting the persons eye with clWhite to clWhite, but didn't work.
Any suggestion?

ASKER CERTIFIED SOLUTION
Avatar of ThievingSix
ThievingSix
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of systan

ASKER

Thanks