Convert Amibroker color constants to RGB values

I'd like to convert an Amibroker constant value for a color (eg colorGreen) to its individual RGB component values.

I've used the code from this help page, which has the formula for this. However, the values for the green and blue color components always come out as 0 and -1 respectively, regardless of the input color I use.

Here's my code:

ChartBackColor = colorGreen; //colorYellow; //colorBlue;

SetChartBkColor( ParamColor("Color", ChartBackColor)); //ColorRGB( 255, 255, 255 ) ) );

rgb = ChartBackColor - 56;

red = ( rgb & 255 );
green = floor( (rgb/256) & 255 );
blue = floor( rgb/(256*256) );

Title="Color: " + ChartBackColor + " R="+ red + " G=" + green + " B=" + blue;

And here's the outcome for using an input value of colorGreen:
image

And for colorYellow:
image

And colorBlue:
image

Where am I going wrong?

Hi.

I don't think that is how it works. Those are like internal constants or Windows OS color palette.
Like colorTurquoise is 44 as constant but RGB is 64,224,208 for the same.

So if you set color using colorRGB(), then the value returned is 13688896
and the formula RGB value - 56 works properly.

I am assuming here, and maybe incorrect but that means you may have to make your own lookup table where you will check the RGB values for the AB color constants.

See this post
GetChartBkColor returns correct value, was: wrong value - AFL Programming - AmiBroker Community Forum

1 Like

Thanks nsm. I see my error now.

Anyone know where I can find a reference to get the RGB values for each of the color constants?

Simple go to Google search and type color picker program.

Title = "";

colorstr = "colorBlack,colorBrown,colorDarkOliveGreen,colorDarkGreen,colorDarkTeal,colorDarkBlue,colorIndigo,colorDarkGrey," +
           "colorDarkRed,colorOrange,colorDarkYellow,colorGreen,colorTeal,colorBlue,colorBlueGrey,colorGrey40," +
           "colorRed,colorLightOrange,colorLime,colorSeaGreen,colorAqua,colorLightBlue,colorViolet,colorGrey50," +
           "colorPink,colorGold,colorYellow,colorBrightGreen,colorTurquoise,colorSkyblue,colorPlum,colorLightGrey," +
           "colorRose,colorTan,colorLightYellow,colorPaleGreen,colorPaleTurquoise,colorPaleBlue,colorLavender,colorWhite";

GfxFillSolidRect( 0, 0, 310, 719, colorLightGrey );

GfxSetBkMode(0);
GfxSelectFont( "ARIAL", 9, 700 );

n = 0;
for( i = 16; i <= 55; i++ ) {
	y = i+17*n-16;
	GfxFillSolidRect( 0, y, 150, y+17, i );
	GfxTextOut( "" + i + " == " + StrExtract(colorstr, n), 152, y+1 );
	n++;	
}


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.