Select to view content in your preferred language

How to Convert a Graphic Symbol into an ImageSource

653
3
Jump to solution
04-05-2013 12:13 PM
DonnieHolmes
Occasional Contributor
Does anyone have any sample code for converting the Symbol of a Graphic into an ImageSource (similar to what is displayed on the Legend control)?

What i'm trying to do is display selected items from the map in a listbox and show the symbol used for the item next to the display name (similar to the Legend Symbol).

This is fairly easy if the layer uses a single symbol, but it's not so easy in the case of a unique value renderer. I have looked into simply leveraging the ILegendSupport.QueryLegendInfos call, but the return data does not contain information that is suitable for use as a unique id (In the case of a unique value renderer, only the label and description for each symbol is exposed and not the underlying values that are used).

Any ideas are appreciated - Thanks.
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
You can instantiate a simple renderer and set the symbol property to the graphic symbol.

Then by calling QueryLegendInfos on this renderer, you will get the imagesource as a property of the legendItemInfo (only one legenditeminfo is returned by a simple renderer)

View solution in original post

0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
You can instantiate a simple renderer and set the symbol property to the graphic symbol.

Then by calling QueryLegendInfos on this renderer, you will get the imagesource as a property of the legendItemInfo (only one legenditeminfo is returned by a simple renderer)
0 Kudos
DonnieHolmes
Occasional Contributor
You can instantiate a simple renderer and set the symbol property to the graphic symbol.

Then by calling QueryLegendInfos on this renderer, you will get the imagesource as a property of the legendItemInfo (only one legenditeminfo is returned by a simple renderer)



Thanks very much! That did the trick.
0 Kudos
LanceCrumbliss
Frequent Contributor
Would someone mind posting some code for this?  I get a dreaded

Error HRESULT E_FAIL has been returned from a call to a COM component.


with the following code

        Dim sr As New SimpleRenderer With {.Symbol = CType(App.Current.Resources("AutoSymbol"), MarkerSymbol)}
        'Renderer instantiates fine, with a valid symbol.
        sr.QueryLegendInfos(AddressOf WTF, Nothing) 'Error Here

    Private Sub WTF(d As LayerLegendInfo)
        'Do Something
    End Sub

0 Kudos