Use these functions to help you create new color objects. You can create RGBColors, CMYKColors, HSVColors, or HLSColors and specify 1 of 16 basic colors for the new color class. The 16 basic colors reflect the colors typically found in a 4 bit, 16 color system.
How to use
- Copy and paste the required functions into your application. Make sure the enumeration is defined in an appropriate place, i.e. that it is global to all the functions which need to use it.
- Call MakeRGB, MakeCMYK, MakeHLS or MakeHSV using a color from the basicColorEnum enumeration as the paramater in the function call to create a new color object.
//
// This enumeration creates constants for the 16 basic colors used in a 4bit
// color system.
//
typedef enum basicColorEnum
{
colorBlack, colorDarkRed, colorDarkGreen, colorDarkYellow, colorDarkBlue,
colorDarkPurple, colorDarkCyan, colorPaleGray, colorMidGray, colorRed,
colorGreen, colorYellow, colorBlue, colorMagenta, colorCyan, colorWhite,
};
//
// This function will return a RGB OLE_COLOR.
// Its color is initialized to the passed in constant.
//
HRESULT MakeOLEColor(basicColorEnum inColor, OLE_COLOR *pRGB)
{
if (!pRGB)
return E_POINTER;
switch (inColor)
{
case colorBlack:
*pRGB = RGB(0, 0, 0);
break;
case colorDarkRed:
*pRGB = RGB(128, 0, 0);
break;
case colorDarkGreen:
*pRGB = RGB(0, 128, 0);
break;
case colorDarkYellow:
*pRGB = RGB(128, 128, 0);
break;
case colorDarkBlue:
*pRGB = RGB(0, 0, 128);
break;
case colorDarkPurple:
*pRGB = RGB(128, 0, 128);
break;
case colorDarkCyan:
*pRGB = RGB(0, 128, 128);
break;
case colorPaleGray:
*pRGB = RGB(192, 192, 192);
break;
case colorMidGray:
*pRGB = RGB(128, 128, 128);
break;
case colorRed:
*pRGB = RGB(255, 0, 0);
break;
case colorGreen:
*pRGB = RGB(0, 255, 0);
break;
case colorYellow:
*pRGB = RGB(255, 255, 0);
break;
case colorBlue:
*pRGB = RGB(0, 0, 255);
break;
case colorMagenta:
*pRGB = RGB(255, 0, 255);
break;
case colorCyan:
*pRGB = RGB(0, 255, 255);
break;
case colorWhite:
*pRGB = RGB(255, 255, 255);
break;
default:
*pRGB = RGB(255, 255, 255);
break;
}
return S_OK;
}
//
// This function will return a new RGBColor object.
// Its color is initialized to the passed in constant.
//
HRESULT MakeRGB(basicColorEnum inColor, IRgbColor **ppColor)
{
if (!ppColor)
return E_POINTER;
IRgbColorPtr ipRGBColor(CLSID_RgbColor);
OLE_COLOR rgb;
MakeOLEColor(inColor, &rgb);
ipRGBColor->put_RGB(rgb);
*ppColor = ipRGBColor;
if (*ppColor)
(*ppColor)->AddRef();
else
return E_FAIL;
return S_OK;
}
//
// This function will return a new CMYKColor object.
// Its color is initialized to the passed in constant.
//
HRESULT MakeCMYK(basicColorEnum inColor, ICmykColor **ppColor)
{
if (!ppColor)
return E_POINTER;
ICmykColorPtr ipCMYKColor(CLSID_CmykColor);
OLE_COLOR rgb;
MakeOLEColor(inColor, &rgb);
ipCMYKColor->put_RGB(rgb);
*ppColor = ipCMYKColor;
if (*ppColor)
(*ppColor)->AddRef();
else
return E_FAIL;
return S_OK;
}
//
// This function will return a new HSVColor object.
// Its color is initialized to the passed in constant.
//
HRESULT MakeHSV(basicColorEnum inColor, IHsvColor **ppColor)
{
if (!ppColor)
return E_POINTER;
IHsvColorPtr ipHSVColor(CLSID_HsvColor);
OLE_COLOR rgb;
MakeOLEColor(inColor, &rgb);
ipHSVColor->put_RGB(rgb);
*ppColor = ipHSVColor;
if (*ppColor)
(*ppColor)->AddRef();
else
return E_FAIL;
return S_OK;
}
//
// This function will return a new HLSColor object.
// Its color is initialized to the passed in constant.
//
HRESULT MakeHLS(basicColorEnum inColor, IHlsColor **ppColor)
{
if (!ppColor)
return E_POINTER;
IHlsColorPtr ipHLSColor(CLSID_HlsColor);
OLE_COLOR rgb;
MakeOLEColor(inColor, &rgb);
ipHLSColor->put_RGB(rgb);
*ppColor = ipHLSColor;
if (*ppColor)
(*ppColor)->AddRef();
else
return E_FAIL;
return S_OK;
}
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |