delphi之颜色转换和像素访问

模拟需要找色,找图等等功能,我们先要熟悉有关的知识。

我们的目的是为了找色和找图,所以只用考虑只需要处理24B颜色(PF24BIT)。

TColor 值是以十六进制进行存储的,低三位分别表示红、绿、蓝三种基色的饱和度。

var

   C:Tcolor

   R,G,B:Byte;

TColor转换成RGB的值

   R:=GetRValue(C);

   G:=GetGValue(C);

   B::=GetBValue(C);

   R:=C and $FF;

   G:=(C and $FF00) shr 8;

   B:=(C and $FF0000) shr 16;

RGB转换成TColor的值

   C:=StrToInt(IntToHex(B,2)+IntToHex(G,2)+IntToHex(R,2));

   C:=RGB(R,G,B);

对BMP像素的快速访问,一般使用scanline.

type //补充定义,方便使用

   pRGBTripArray=^TRGBTripleArray;

   TRGBTripleArray=array[0..1024-1] of TRGBTriple;

var

   row:pRGBTripArray;

   p:TRGBTriple;

访问第y行第x列(x,y)

   row := bmp.scanline[y];

   p:= row [x];

   R:= p.rgbtRed;

   G:=p.rgbtGreen;

   B:=p.rgbtBlue;

另外的一种访问方式

var

   p: PByteArray;

访问第y行第x列(x,y)

   p := bmp..scanline[y];

然后用p[x * 3],  p[x * 3 + 1],  p[x * 3 + 2] 来访问

原文地址:https://www.cnblogs.com/MaxWoods/p/3106272.html