DennisJongsomjit

get legend rgb values for a raster

Discussion created by DennisJongsomjit on Nov 9, 2011
Hi,
I found some code that outputs the legend rgb values for a feature layer.  I'd like to do this for raster layers as well (using classified symbology).  Can anyone help either modify this code or point me to some existing code that can do this?  Code follows below.


   

Public Sub UVRtoRGB()
' ---- Change this output location ----
Const OUTPUT_FILE = "C:\RGBValues.txt"
' -------------------------------------
Dim pMxDoc As IMxDocument
Dim pGeoFtrLyr As IGeoFeatureLayer


Dim pUVRend As IUniqueValueRenderer

Dim pFillSym As IFillSymbol
Dim pRGB As IRgbColor
Dim f As Long
Dim sVal As String

    Set pRGB = New RgbColor
    Set pMxDoc = ThisDocument
    Set pGeoFtrLyr = pMxDoc.FocusMap.Layer(0)


   
    Set pUVRend = pGeoFtrLyr.Renderer

   
    Open OUTPUT_FILE For Output As #1
    Print #1, "Value,Red,Green,Blue"
   
    For f = 0 To pUVRend.ValueCount - 1
        sVal = pUVRend.Value(f)

        Set pFillSym = pUVRend.Symbol(sVal)
        pRGB.RGB = pFillSym.Color.RGB
        Print #1, sVal; ","; CStr(pRGB.Red); ","; CStr(pRGB.Green); ","; CStr(pRGB.Blue)
    Next f

   
    Close #1
   
    MsgBox "RGBs Exported", vbInformation

End Sub

Outcomes