Board index » delphi » Getting R,G,B values from TColor?

Getting R,G,B values from TColor?

I'm using D4, and want to process a bitmap. To do this I need to access
every pixel, and get the Red, Green and Blue values for each pixel
(separately).

How do I split up a TColor into Red, Green and Blue?

I was able to do this in D3 by using a simple function that Delphi provided,
(If I can remember correctly).

I'll also need to use R, G, and B values to recombine into a TColor again,
so I can create a new (different) bitmap.

I don't want to use scanline, something simple would be much appreciated.

Thanks,

Col.

 

Re:Getting R,G,B values from TColor?


If u dont use scanline, then your program will need some weeks to process a big
bitmap... :-)

Anyway, u can use pixels[] property of the Bitmap.Canvas :

var c : Tcolor;

c:=Bitmap.Canvas.Pixels[i,j]; but it is a little bit strange how to process with
c variable (look at the TColor in your help file).

The way i use to look at the RGB band in c is to declare another type:

type RGBcolor = record
  case integer of
   0: (Bcolor : Tcolor);
   1: (R,G,B,dummy : byte);
end;

var c: RGBColor

C.BColor:=Bitmap.Canvas.Pixels[i,j];

and you can play with the color bands with

C.R // RED
C.B // BLUE
C.G // GREEN

if c.G = 100 then c.R:=200;  // if green value is 100 then change the red value
to 200 ...

But i suggest you to USE SCANLINE.... !!

Lazikas.

Quote
closetnerd wrote:
> I'm using D4, and want to process a bitmap. To do this I need to access
> every pixel, and get the Red, Green and Blue values for each pixel
> (separately).

> I don't want to use scanline, something simple would be much appreciated.

> Thanks,

> Col.

Other Threads