Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
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 Mar 26 '11 at 8:14
    
I have the same problem. Is it real to draw one transparency polygon on the map in arcobjects 10.1? –  novicegis Oct 28 '13 at 13:17
add comment

6 Answers 6

up vote 8 down vote accepted

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)".

share|improve this answer
    
Ok thats a good answer. But what about when you are displaying temp graphics, such as a selection rectangle (mostly IDisplayFeedbacks)? –  George Mar 26 '11 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. –  Sasa Ivetic Mar 27 '11 at 14:20
add comment

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.

share|improve this answer
add comment

'Code example - ILayerEffects

Dim pGeoFeatureLayer as IGeoFeatureLayer

Dim pLayerEffects As ILayerEffects

Set pLayerEffects = pGeoFeatureLayer

pLayerEffects.Transparency = 70
share|improve this answer
    
Did you try setting this line "fillSymbol.Color.Transparent = 0" to a value other than 0? –  artwork21 Mar 25 '11 at 16:41
add comment

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

fillSymbol.Color.NullColor = true;
share|improve this answer
add comment
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.

share|improve this answer
    
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; –  Sasa Ivetic Mar 25 '11 at 16:52
    
@Sasa Ivetic see my edit for clarification –  patrick Mar 25 '11 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 Mar 25 '11 at 21:17
add comment

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

share|improve this answer
    
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 Jul 15 at 11:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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