ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / ColorFactory Class / ConstructColorRamp Method / ConstructColorRamp(ColorRampAlgorithm,CIMColor,CIMColor) Method
ColorRampAlgorithm
The from color
The to color
Example

In This Topic
    ConstructColorRamp(ColorRampAlgorithm,CIMColor,CIMColor) Method
    In This Topic
    Construct a color ramp using the specified algorithm. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Function ConstructColorRamp( _
       ByVal algorithm As ColorRampAlgorithm, _
       ByVal fromColor As CIMColor, _
       ByVal toColor As CIMColor _
    ) As CIMColorRamp

    Parameters

    algorithm
    ColorRampAlgorithm
    fromColor
    The from color
    toColor
    The to color

    Return Value

    CIMColorRamp
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    fromColor
    toColor
    Remarks
    From and to colors are ignored for ColorRampAlgorithm.Fixed. For ColorRampAlgorithm.RandomHSV the fromColor acts as the minimum, the toColor acts as the maximum. From and to colors are converted to HSV.
    Example
    Snippet Gradient color fill using CIMGradientFill
    /// <summary>
    /// Create a polygon symbol with a gradient color fill. <br/>
    /// ![PolygonSymbolGradientColor](http://Esri.github.io/arcgis-pro-sdk/images/Symbology/polygon-gradient-color.png)
    /// </summary>
    /// <remarks>
    /// 1. Create a solid colored stroke with 50% transparency
    /// 1. Create a fill using gradient colors red through green
    /// 1. Apply both the stroke and fill as a symbol layer array to the new PolygonSymbol
    /// </remarks>
    /// <returns></returns>
    public static Task<CIMPolygonSymbol> CreateGradientFillAsync()
    {
        return QueuedTask.Run<CIMPolygonSymbol>(() =>
        {
            var trans = 50.0;//semi transparent
            CIMStroke outline = SymbolFactory.Instance.ConstructStroke(CIMColor.CreateRGBColor(0, 0, 0, trans), 2.0, SimpleLineStyle.Solid);
            //Mimic cross hatch
            CIMFill solidColorHatch =
             new CIMGradientFill()
             {
                 ColorRamp = ColorFactory.Instance.ConstructColorRamp(ColorRampAlgorithm.LinearContinuous,
                                    ColorFactory.Instance.RedRGB, ColorFactory.Instance.GreenRGB)
             };
            List<CIMSymbolLayer> symbolLayers = new List<CIMSymbolLayer>
            {
                outline,
                solidColorHatch
            };
    
            return new CIMPolygonSymbol() { SymbolLayers = symbolLayers.ToArray() };
        });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also