Select to view content in your preferred language

How to use RenderingRule with Colormap to display imagery in greyscale

718
2
02-10-2011 09:27 AM
BobbyRadakovich
Deactivated User
I am trying to apply a RenderingRule using a Colormap to switch my imagery display from color to greyscale (print preview for people without color printers).  Here is my code snippet from the button handler that handles the switch:

[INDENT]        private void Button1_Click(object sender, RoutedEventArgs e)
        {
[INDENT]            ArcGISImageServiceLayer lyr = (ArcGISImageServiceLayer)(MyMap.Layers[0]);
            RenderingRule rule = new RenderingRule();
            rule.VariableName = "Raster";
            rule.RasterFunctionName = "Colormap";
            Dictionary<string, object> parms = new Dictionary<string, object>();
            parms.Add("ColormapName", "Gray");
            lyr.RenderingRule = rule;
            lyr.Refresh();
[/INDENT]        }
[/INDENT]
The code runs fine, but when the imagery layer refreshes instead of displaying in greyscale it just disappears altogether.

Ideas?
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
Your dictionary of parameters looks initialized but never used.
0 Kudos
ChristopherHill
Deactivated User
private void Button1_Click(object sender, RoutedEventArgs e)
{
ArcGISImageServiceLayer lyr = (ArcGISImageServiceLayer)(MyMap.Layers[0]);


// Make sure when you are applying rendering rule that you are only 
// using a single color band id. Layer may have multiple color bands.
// You have to select a single color band id to convert to grayscale.

lry.BandIds = new int[] { bandID }; 
RenderingRule rule = new RenderingRule();
rule.VariableName = "Raster";
rule.RasterFunctionName = "Colormap";
Dictionary<string, object> parms = new Dictionary<string, object>();
parms.Add("ColormapName", "Gray");
rule.RasterFunctionArguments = parms; // Missing this line
lyr.RenderingRule = rule;
lyr.Refresh();
}
0 Kudos