Use IRasterShader in add-in button?

04-28-2014 06:32 AM
New Contributor III

I want to create an add-in button that programmatically applies contrast, brightness, and gamma to a raster layer.  I found the IRasterShader interface in the documentation, but no examples of how to use it.  My efforts to use it have not been successful thus far. 

Right now I'm doing something like:

IRasterLayer rLayer = map.get_Layer(index);
IRasterShader rShader = rLayer as IRasterShader;
rShader.Brightness = brightValue;

But rShader is null.  Does anyone have any insight?

0 Kudos
1 Reply
MVP Frequent Contributor
It's not obvious in the Help which class uses the IRasterShader interface. If you are just tweaking brightness as your snippet suggests you can point ILayerEffects to an IRasterLayer object and set the brightness.

This VBA code shows how to adjust brightness:

Public Sub test()
    Dim pMXdoc As IMxDocument
    Set pMXdoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pMXdoc.FocusMap
    Dim pRasterLayer As IRasterLayer
    Set pRasterLayer = pMap.Layer(0)
    Dim pLayerEffects As ILayerEffects
    Set pLayerEffects = pRasterLayer
    pLayerEffects.Brightness = 99
End Sub
0 Kudos