Using ScanLine to get the RGB Value of a pixel

Please discuss general Delphi programming topics here.

Using ScanLine to get the RGB Value of a pixel

Postby hadipardis » March 20th, 2006, 7:56 am

Hi, I want to use ScanLine to get the RGB value (R,G,B) of each pixel inside a TBitmap. Could you please tell me how I can do that?Thanks :?:
hadipardis
Junior Member
Junior Member
 
Posts: 33
Joined: July 17th, 2004, 5:45 am

Postby Johnny_Bit » March 20th, 2006, 2:38 pm

simple as... very simple:
Code: Select all
type
  TRGBTripleArray = packed array[Word] of TRGBTriple;

  pRGBTripleArray = ^TRGBTripleArray;

{...}

procedure TForm1.FormCreate(Sender: TObject);

var

  X, Y: Integer;

  R, G, B: Byte;

  {Color: Cardinal;}

  ColorRow: pRGBTripleArray;

begin

  CreateColorSet;

  ActiveColorSet:=0;

  MainX:=0;

  MainY:=0;

  Randomize;

  DoubleBuffered:=True;

  R:=0;

  G:=0;

  B:=0;

  BMP:=TBitmap.Create;

  BMP.Width:=Screen.Width;

  BMP.Height:=Screen.Height;

  BMP.PixelFormat:=pf24Bit;

  for Y:=0 to BMP.Height-1 do

    begin

      ColorRow:=BMP.ScanLine[Y];

      for X:=0 to BMP.width-1 do

        begin

          {Below code can be modified in various ways, resulting very nice images,

            just change operators.}

          R:= Round(255 * Sin(2 * Pi * (Byte(X+Y) - 174) / 255));

          G:= Round(255 * Sin(2 * Pi * (Byte(X+Y) - 17) / 255));

          B:= Round(255 * Sin(2 * Pi * (Byte(X+Y) - 57) / 255));

          ColorRow[X].rgbtBlue:=B;

          ColorRow[X].rgbtGreen:=G;

          ColorRow[X].rgbtRed:=R;

        end;

    end;

end;


Well, it's not for getting rgb, but rather setting, but there's only small difference. You'll get the idea...
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 22 guests

cron