• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Getting rgb values


Anyone know how can I tell the RGB values of a pixel?  For example,
I want to run a test and show that pixel[5,7] of Timage is red 200, green 155, blue 240, and use showmessage to show these 3 values on the screen.
----------
Using scanline below, I thought this would get the values with the Buffer defined as Pbytearray, and although this seems to return values, when I copy the image to the canvas as below shows (verifying that it copies the exact image to the canvas to prove that the scanline is getting the right colors), it doesn't look exactly like the Timage, as I was expecting. I've never used scanline before so I may be missing something but I thought this was how it worked.  Is there a better way to find out the individual rgb values?   I'm using D3.  
------------------
    for j:=0 to Image1.Picture.Height - 1 do
       begin
          Buffer:=Image1.Picture.Bitmap.ScanLine[j];

          for i:= 0 to Image1.Picture.Width - 1 do
            begin
               Canvas.Pixels[i,j] :=  rgb(Buffer[i+0],Buffer[i+1],Buffer[i+2]);
            end;
       end;
0
jexd99
Asked:
jexd99
  • 2
1 Solution
 
rwilson032697Commented:
Try changing this line:

Canvas.Pixels[i,j] :=  rgb(Buffer[i+0],Buffer[i+1],Buffer[i+2]);

To this:

Canvas.Pixels[i,j] :=  rgb(Buffer[i+2],Buffer[i+1],Buffer[i+0]);

Cheers,

Raymond.
0
 
MadshiCommented:
Are you sure that the bitmap has the correct pixel format? Check Image1.Picture.Bitmap.PixelFormat before using the scanLine property. The pixelFormat must be 24bit, otherwise your code must look differently...

Then use this line:

Canvas.Pixels[i,j] :=  rgb(Buffer[i*3+0],Buffer[i*3+1],Buffer[i*3+2]);

or this one:

Canvas.Pixels[i,j] :=  rgb(Buffer[i*3+2],Buffer[i*3+1],Buffer[i*3+0]);

Regards, Madshi.
0
 
rwilson032697Commented:
Its that old 'multiply by 3' again!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now