ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / BasicRasterLayer Class / SetColorizer Method
Your custom colorizer that will be used to draw the raster layer.
Example

In This Topic
    SetColorizer Method
    In This Topic
    Sets the colorizer. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Sub SetColorizer( _
       ByVal colorizer As CIMRasterColorizer _
    ) 
    public void SetColorizer( 
       CIMRasterColorizer colorizer
    )

    Parameters

    colorizer
    Your custom colorizer that will be used to draw the raster layer.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Cannot set colorizer for layer.
    Remarks
    Use CanSetColorizer to determine if the colorizer is valid for the layer before updating it.
    Example
    Update the raster colorizer on a raster layer
    {
        // Get the colorizer from the raster layer.
        //Note: needs to be called on the QueuedTask
        CIMRasterColorizer rasterColorizer = rasterLayer.GetColorizer();
        // Update raster colorizer properties.
        rasterColorizer.Brightness = 10;
        rasterColorizer.Contrast = -5;
        rasterColorizer.ResamplingType = RasterResamplingType.NearestNeighbor;
        // Update the raster layer with the changed colorizer.
        rasterLayer.SetColorizer(rasterColorizer);
    }
    Update the RGB colorizer on a raster layer
    {
        // Get the colorizer from the raster layer.
        //Note: needs to be called on the QueuedTask
        CIMRasterColorizer rColorizer = rasterLayer.GetColorizer();
        // Check if the colorizer is an RGB colorizer.
        if (rColorizer is CIMRasterRGBColorizer rasterRGBColorizer)
        {
            // Update RGB colorizer properties.
            rasterRGBColorizer.StretchType = RasterStretchType.ESRI;
            // Update the raster layer with the changed colorizer.
            rasterLayer.SetColorizer(rasterRGBColorizer);
        }
    }
    Create a new colorizer based on a default colorizer definition and apply it to the raster layer
    {
        // Check if the Stretch colorizer can be applied to the raster layer.
        //Note: needs to be called on the QueuedTask
        if (rasterLayer.GetApplicableColorizers().Contains(RasterColorizerType.StretchColorizer))
        {
            // Create a new Stretch Colorizer Definition using the default constructor.
            StretchColorizerDefinition stretchColorizerDef_default = new StretchColorizerDefinition();
            // Create a new Stretch colorizer using the colorizer definition created above.
            CIMRasterStretchColorizer newStretchColorizer_default =
            await rasterLayer.CreateColorizerAsync(stretchColorizerDef_default) as CIMRasterStretchColorizer;
            // Set the new colorizer on the raster layer.
            rasterLayer.SetColorizer(newStretchColorizer_default);
        }
    }
    Create a new colorizer based on a custom colorizer definition and apply it to the raster layer
    {
        // Check if the Stretch colorizer can be applied to the raster layer.
        //Get a color ramp from a style
        StyleProjectItem ArcGISColorsStyleItem =
              Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS Colors");
        var colorRamps = ArcGISColorsStyleItem.SearchColorRamps("Heat Map 4 - Semitransparent");
        CIMColorRamp colorRampToUse = colorRampList[0].ColorRamp;
    
        //Note: needs to be called on the QueuedTask
        if (rasterLayer.GetApplicableColorizers().Contains(RasterColorizerType.StretchColorizer))
        {
            // Create a new Stretch Colorizer Definition specifying parameters 
            // for band index, stretch type, gamma and color ramp.
            StretchColorizerDefinition stretchColorizerDef_custom =
        new StretchColorizerDefinition(1, RasterStretchType.ESRI, 2, colorRamp);
            // Create a new stretch colorizer using the colorizer definition created above.
            CIMRasterStretchColorizer newStretchColorizer_custom =
        await rasterLayer.CreateColorizerAsync(stretchColorizerDef_custom) as CIMRasterStretchColorizer;
            // Set the new colorizer on the raster layer.
            rasterLayer.SetColorizer(newStretchColorizer_custom);
        }
    }
    Update the raster colorizer on a mosaic layer
    {
        // Get the image sub-layer from the mosaic layer.
        //Note: needs to be called on the QueuedTask
        ImageMosaicSubLayer mosaicImageSubLayer = mosaicLayer.GetImageLayer();
        // Get the colorizer from the image sub-layer.
        CIMRasterColorizer rasterColorizer = mosaicImageSubLayer.GetColorizer();
        // Update raster colorizer properties.
        rasterColorizer.Brightness = 10;
        rasterColorizer.Contrast = -5;
        rasterColorizer.ResamplingType = RasterResamplingType.NearestNeighbor;
        // Update the image sub-layer with the changed colorizer.
        mosaicImageSubLayer.SetColorizer(rasterColorizer);
    }
    Update the RGB colorizer on a mosaic layer
    {
        // Get the image sub-layer from the mosaic layer.
        //Note: needs to be called on the QueuedTask
        ImageMosaicSubLayer mosaicImageSubLayer = mosaicLayer.GetImageLayer();
        // Get the colorizer from the image sub-layer.
        CIMRasterColorizer rColorizer = mosaicImageSubLayer.GetColorizer();
        // Check if the colorizer is an RGB colorizer.
        if (rColorizer is CIMRasterRGBColorizer rasterRGBColorizer)
        {
            // Update RGB colorizer properties.
            rasterRGBColorizer.StretchType = RasterStretchType.ESRI;
            // Update the image sub-layer with the changed colorizer.
            mosaicImageSubLayer.SetColorizer(rasterRGBColorizer);
        }
    }
    Create a new colorizer based on a default colorizer definition and apply it to the mosaic layer
    {
        // Get the image sub-layer from the mosaic layer.
        //Note: needs to be called on the QueuedTask
        ImageMosaicSubLayer mosaicImageSubLayer = mosaicLayer.GetImageLayer();
        // Check if the Stretch colorizer can be applied to the image sub-layer.
        if (mosaicImageSubLayer.GetApplicableColorizers().Contains(RasterColorizerType.StretchColorizer))
        {
            // Create a new Stretch Colorizer Definition using the default constructor.
            StretchColorizerDefinition stretchColorizerDef_default = new StretchColorizerDefinition();
            // Create a new Stretch colorizer using the colorizer definition created above.
            CIMRasterStretchColorizer newStretchColorizer_default =
        await mosaicImageSubLayer.CreateColorizerAsync(stretchColorizerDef_default) as CIMRasterStretchColorizer;
            // Set the new colorizer on the image sub-layer.
            mosaicImageSubLayer.SetColorizer(newStretchColorizer_default);
        }
    }
    Create a new colorizer based on a custom colorizer definition and apply it to the mosaic layer
    {
        // Get the image sub-layer from the mosaic layer.
        //Note: needs to be called on the QueuedTask
        ImageMosaicSubLayer mosaicImageSubLayer = mosaicLayer.GetImageLayer();
        // Check if the Stretch colorizer can be applied to the image sub-layer.
        if (mosaicImageSubLayer.GetApplicableColorizers().Contains(RasterColorizerType.StretchColorizer))
        {
            // Create a new Stretch colorizer definition specifying parameters
            // for band index, stretch type, gamma and color ramp.
            StretchColorizerDefinition stretchColorizerDef_custom =
        new StretchColorizerDefinition(1, RasterStretchType.ESRI, 2, colorRamp);
            // Create a new stretch colorizer using the colorizer definition created above.
            CIMRasterStretchColorizer newStretchColorizer_custom =
        await mosaicImageSubLayer.CreateColorizerAsync(stretchColorizerDef_custom) as CIMRasterStretchColorizer;
            // Set the new colorizer on the image sub-layer.
            mosaicImageSubLayer.SetColorizer(newStretchColorizer_custom);
        }
    }
    Update the raster colorizer on an image service layer
    {
        // Get the colorizer from the image service layer.
    
        CIMRasterColorizer rasterColorizer = imageServiceLayer.GetColorizer();
        // Update the colorizer properties.
        rasterColorizer.Brightness = 10;
        rasterColorizer.Contrast = -5;
        rasterColorizer.ResamplingType = RasterResamplingType.NearestNeighbor;
        // Update the image service layer with the changed colorizer.
        imageServiceLayer.SetColorizer(rasterColorizer);
    }
    Update the RGB colorizer on an image service layer
    {
        // Get the colorizer from the image service layer.
        //Note: needs to be called on the QueuedTask
        CIMRasterColorizer rColorizer = imageServiceLayer.GetColorizer();
        // Check if the colorizer is an RGB colorizer.
        if (rColorizer is CIMRasterRGBColorizer rasterRGBColorizer)
        {
            // Update RGB colorizer properties.
            rasterRGBColorizer.StretchType = RasterStretchType.ESRI;
            // Update the image service layer with the changed colorizer.
            imageServiceLayer.SetColorizer((CIMRasterColorizer)rasterRGBColorizer);
        }
    }
    Create a new colorizer based on a default colorizer definition and apply it to the image service layer
    {
        // Check if the Stretch colorizer can be applied to the image service layer.
        if (imageServiceLayer.GetApplicableColorizers().Contains(RasterColorizerType.StretchColorizer))
        {
            // Create a new Stretch Colorizer Definition using the default constructor.
            StretchColorizerDefinition stretchColorizerDef_default = new StretchColorizerDefinition();
            // Create a new Stretch colorizer using the colorizer definition created above.
            CIMRasterStretchColorizer newStretchColorizer_default =
        await imageServiceLayer.CreateColorizerAsync(stretchColorizerDef_default) as CIMRasterStretchColorizer;
            // Set the new colorizer on the image service layer.
            imageServiceLayer.SetColorizer(newStretchColorizer_default);
        }
    }
    Create a new colorizer based on a custom colorizer definition and apply it to the image service layer
    {
        // Check if the Stretch colorizer can be applied to the image service layer.
        //Note: needs to be called on the QueuedTask
        if (imageServiceLayer.GetApplicableColorizers().Contains(RasterColorizerType.StretchColorizer))
        {
            // Create a new Stretch Colorizer Definition specifying parameters
            // for band index, stretch type, gamma and color ramp. 
            StretchColorizerDefinition stretchColorizerDef_custom =
        new StretchColorizerDefinition(1, RasterStretchType.ESRI, 2, colorRamp);
            // Create a new stretch colorizer using the colorizer definition created above.
            CIMRasterStretchColorizer newStretchColorizer_custom =
        await imageServiceLayer.CreateColorizerAsync(stretchColorizerDef_custom) as CIMRasterStretchColorizer;
            // Set the new colorizer on the image service layer.
            imageServiceLayer.SetColorizer(newStretchColorizer_custom);
        }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also