This document is archived and information here might be outdated.  Recommended version.


How to access the color map of an image service (ArcObjects .NET 10.4 SDK)

How to access the color map of an image service


Summary
At ArcGIS 10.1, image service supports color map on single band data source. This topic shows how to retrieve color map from an image service.

Accessing the color map of an image service

Do the following steps to access a color map for an image service:
  1. Get the color map from an image service.
  2. Export an image from the image service while applying a color map function.

    See the following code example:
[C#]
public static void GetAndApplyColormap(IImageServer imageServer)
{
    //Get the color map.
    IImageServiceInfo3 isInfo=imageServer.ServiceInfo as IImageServiceInfo3;
    IRasterColormap colormap=isInfo.Colormap;

    //Create the color map function using the color map.
    IRenderingRule rule=new RenderingRuleClass();
    ColormapFunction colormapfunction=new ColormapFunctionClass();
    IColormapFunctionArguments colormapargs=new ColormapFunctionArgumentsClass();
    colormapargs.Colormap=colormap;
    rule.Function=colormapfunction;
    rule.Arguments=(IRasterFunctionArguments)colormapargs;
    rule.VariableName="Raster";

    //Define export image request.
    IGeoImageDescription2 geoImageDesc=new GeoImageDescriptionClass();
    geoImageDesc.Width=800;
    geoImageDesc.Height=600;
    geoImageDesc.Extent=isInfo.Extent;
    geoImageDesc.RenderingRule=rule;

    //Export an image using service's color map.
    IImageType imageType=new ImageTypeClass();
    imageType.Format=esriImageFormat.esriImageJPGPNG;
    imageType.ReturnType=esriImageReturnType.esriImageReturnURL;
    IMapImage mapImage=((IImageServer2)imageServer).ExportMapImage(geoImageDesc,
        imageType);
    System.Diagnostics.Process.Start("iexplore.exe", mapImage.URL);
}
[VB.NET]
Public Shared Sub GetAndApplyColormap(imageServer As IImageServer)

'Get the color map.
Dim isInfo As IImageServiceInfo3=TryCast(imageServer.ServiceInfo, IImageServiceInfo3)
Dim colormap As IRasterColormap=isInfo.Colormap

'Create the color map function using the color map.
Dim rule As IRenderingRule=New RenderingRuleClass()
Dim colormapfunction As ColormapFunction=New ColormapFunctionClass()
Dim colormapargs As IColormapFunctionArguments=New ColormapFunctionArgumentsClass()
colormapargs.Colormap=colormap
rule.[Function]=colormapfunction
rule.Arguments=DirectCast(colormapargs, IRasterFunctionArguments)
rule.VariableName="Raster"

'Define export image extent.
Dim geoImageDesc As IGeoImageDescription2=New GeoImageDescriptionClass()
geoImageDesc.Width=800
geoImageDesc.Height=600
geoImageDesc.Extent=isInfo.Extent
geoImageDesc.RenderingRule=rule

'Export an image using service's color map.
Dim imageType As IImageType=New ImageTypeClass()
imageType.Format=esriImageFormat.esriImageJPGPNG
imageType.ReturnType=esriImageReturnType.esriImageReturnURL
Dim mapImage As IMapImage=DirectCast(imageServer, IImageServer2).ExportMapImage(geoImageDesc, imageType)
System.Diagnostics.Process.Start("iexplore.exe", mapImage.URL)
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
Engine Developer Kit Engine