Board index » delphi » Getting RGB Values (8bit and 24bit)

Getting RGB Values (8bit and 24bit)

I'm using ScanLine to obtain the RGB values for a particular bitmap (see
code below).  It works fine for 24bit but if the bitmap is 8bit, I get
incorrect RGB values...which I suspected but am not sure what modifications
I need to make to the code to support both 8bit and 24bit.

Hope someone can help.

type
  TRGB = array[0..6000] of TRGBTriple;
  PRGB = ^TRGB;
var
  r,g,b: integer;
  pixColor : PRGB;
begin
...
pixColor := bitmap.ScanLine[row];
r := pixColor[col].rgbtRed;
g := pixColor[col].rgbtGreen;
b := pixColor[col].rgbtBlue;
...
end

 

Re:Getting RGB Values (8bit and 24bit)


Quote
Miles wrote:
> I'm using ScanLine to obtain the RGB values for a particular bitmap (see code
> below).  It works fine for 24bit but if the bitmap is 8bit, I get incorrect
> RGB values...which I suspected but am not sure what modifications I need to
> make to the code to support both 8bit and 24bit.

You need an array of byte to access the 8 bit values of an 8bpp bitmap.  The 8
bit value is not a color but an index into the palette table which contains the
actual color you are seeking.

If you don't want to mess with the palette, the set PixelFormat := pf24bit, and
Delphi will create an 24 bpp bitmap for you to play with.

--
Wayne Herbert
Manager, Computer Products
Key Maps, Inc.
1411 West Alabama
Houston, TX  77006

Vox:  713.522.7949
Fax:  713.521.3202
Email:  wherb...@keymaps.com

"Everywhere I go, I'm asked if I think universities stifle writers. My opinion
is that they don't stifle enough of them."

Flannery O'Connor (1925-1964)

Re:Getting RGB Values (8bit and 24bit)


Quote
Miles wrote in message <01be0c33$d56b3170$6a201e8e@ldbdj6>...
>I'm using ScanLine to obtain the RGB values for a particular bitmap (see
>code below).  It works fine for 24bit but if the bitmap is 8bit, I get
>incorrect RGB values...which I suspected but am not sure what modifications
>I need to make to the code to support both 8bit and 24bit.

The format of the Scanline varies with each PixelFormat.  For details, study
www.efg2.com/lab/ImageProcessing/Scanline.htm

efg
_________________________________
efg's Computer Lab:        www.efg2.com/lab

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

Other Threads