6

I'm trying to create a transparent Polygon in ArcMap; however, it's never transparent. Here's the code I have.

// Create polygon
IPolygon polygon = new PolygonClass();
// create & add points,......

// Create lineSymbol
ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
// set color & style,....

// Create fillSymbol
ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
fillSymbol.Outline = lineSymbol;
fillSymbol.Color = //set to color red//;
fillSymbol.Color.Transparent = 0;
fillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;

// Draw Shape
myMap.DrawShape(polygon, fillSymbol);

RESULT ==> A solid red polygon is drawn. The Transparent setting is ignored.

Thoughts?

2
  • Hy, I also tryed to search a way to do this in ArcMAP without success. Or did anybody know where to set the transparency for a single polygon on the graphics layer?
    – tomlux
    Commented Mar 26, 2011 at 8:14
  • I have the same problem. Is it real to draw one transparency polygon on the map in arcobjects 10.1?
    – novicegis
    Commented Oct 28, 2013 at 13:17

6 Answers 6

9

As per ArcObjects docs

IColor.Transparency Property: Transparency is the degree to which a color is opaque. True transparency is only supported at the layer level. For graphic elements, 0 for transparent and 255 for opaque are the only supported values. Use either the ILayerEffects or ITransparencyRenderer interfaces to set layer transparency. For layer transparency to work properly the display device must be set to "True Color (32 bit)".

2
  • Ok thats a good answer. But what about when you are displaying temp graphics, such as a selection rectangle (mostly IDisplayFeedbacks)? Commented Mar 26, 2011 at 17:59
  • As noted in other posts, I don't think the custom graphics layer implements ILayerEffects. I don't personally know of a workaround, if one exists. Commented Mar 27, 2011 at 14:20
2

When you need your polygon symbol to be fully transparent, assign a null color to the fill symbol as others have suggested. Another way would be to set the Transparency of the fill color to 255, which has the same effect. You can also set your simple fill style to hollow. All this can be done for graphic elements so your drawings persist in the map.

If you want to draw with transparency values other than 0 or 255, you can draw using display filters. See the code below:

        // as an example, we'll draw a rectangle in the middle of the current extent
        var rectangle = activeView.Extent;
        rectangle.Expand(0.5, 0.5, true); // create a rectangle in the middle

        var lineSymbol = new SimpleLineSymbolClass();
        lineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
        lineSymbol.Color = new RgbColorClass {Red = 0, Green = 0, Blue = 0};

        var fillSymbol = new SimpleFillSymbolClass
                         {
                             Style = esriSimpleFillStyle.esriSFSSolid,
                             Outline = lineSymbol,
                             Color = new RgbColorClass { Red = 255, Green = 0, Blue = 0}
                         };

        var screenDisplay = activeView.ScreenDisplay;
        var transparencyDisplayFilter = new TransparencyDisplayFilterClass
                            {
                                Transparency = 127
                            };

        try
        {
            screenDisplay.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);
            screenDisplay.Filter = transparencyDisplayFilter;
            screenDisplay.SetSymbol(fillSymbol);
            screenDisplay.DrawRectangle(rectangle);
        }
        finally
        {
            screenDisplay.FinishDrawing();
        }

This draws a red rectangle semi-transparent (semi-opaque) in the map's display. It can be easily modified to draw any geometry, like polygons, the rectangle was just easy to construct for the sake of the example.

However, as you can see, the code does not (and cannot) use any graphic elements, so if you draw this way, the drawing does not persist in the display when it gets refreshed. One way to solve is to run any drawing code like this in the IActiveViewEvents.AfterDraw event so it gets executed after every refresh.

1
fillSymbol.Color.Transparent = 0;

should be multiple operations.

RgbColor selectedColor = getColor(0, 0, 0);
selectedColor.Transparency = (byte)0;
fillSymbol.Color = selectedColor;  


public static RgbColor getColor(int r, int g, int b)
{
RgbColor color = new RgbColor();
color.Red = r;
color.Green = g;
color.Blue = b;
return color;
}

This code works for me, I am creating an transparent point, so I assume it will work for polygons.

See this for more context: Setting color of a feature "street" with a FeatureRenderer

you actually get a copy of the renderer's symbol object. If you apply any changes to the symbol:... you need to assign the symbol back to the renderer:

thanks to petr k.

3
  • His code seems to indicate that he creates the color and sets transparency like you do (i.e. create the color first then assign it transparency): fillSymbol.Color = //set to color red//; fillSymbol.Color.Transparent = 0; Commented Mar 25, 2011 at 16:52
  • @Sasa Ivetic see my edit for clarification
    – patrick
    Commented Mar 25, 2011 at 17:37
  • There is no transparency set for the symbol in the code snippet. The post by Sasa explains the issue well, transparency can be set only at the layer level. Unfortunately, the graphics layer class (to which you would add graphic elements) does not implement ILayerEffects...
    – Petr Krebs
    Commented Mar 25, 2011 at 21:17
1

'Code example - ILayerEffects

Dim pGeoFeatureLayer as IGeoFeatureLayer

Dim pLayerEffects As ILayerEffects

Set pLayerEffects = pGeoFeatureLayer

pLayerEffects.Transparency = 70
1
  • Did you try setting this line "fillSymbol.Color.Transparent = 0" to a value other than 0?
    – artwork21
    Commented Mar 25, 2011 at 16:41
0

You're looking to have the 'No Fill' effect, correct? If so, then you really want a "null color".

fillSymbol.Color.NullColor = true;
-1

Use esriSimpleFillStyle.esriSFSHollow. Or even esriSimpleLineStyle.esriSLSNull can be used.

1
  • Welcome to GIS SE! Even though this may answer the question, answers (and questions) here are normally a minimum length of about a paragraph. If at all possible, would you be able to edit your answer to expand upon how you think this information will assist the asker of the question.
    – PolyGeo
    Commented Jul 15, 2014 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.