How to set some rgb transparent

5055
8
12-25-2013 01:02 AM
by Anonymous User
Not applicable
Original User: 674438511

Hi!

I'm looking for a code in c# that take a rasterlayer (.tif) and display it in my globecontrol with transparency where is some specific rgb,such as R0 G0 B0. I know i can add it to my globecontrol with this code

//////////
IRasterDataset pRasterdataset = pRasterworkspace.OpenRasterDataset(filename);   

IRaster pRaster = pRasterdataset.CreateDefaultRaster();
IRasterLayer pRasterlayer = new RasterLayerClass();
pRasterlayer.CreateFromRaster(pRaster);
ILayer pLayer = pRasterlayer as ILayer;
axGlobeControl1.Globe.AddLayerType(pLayer, esriGlobeLayerTypeFloating, false);
//////////

But how can i change some specific rgb(such as R0 G0 B0) of raster to transparency?

My guess:
///////
IRasterDataset pRasterdataset = pRasterworkspace.OpenRasterDataset(filename);
IRasterBandCollection rasterBands = (IRasterBandCollection)pRasterdataset;
IRasterBand rasterBand;
IRasterProps rasterProps;
           
rasterBand = rasterBands.Item(0);//band R
rasterProps = (IRasterProps)rasterBand;//now�?NoDataValue = 256 default value
rasterProps.NoDataValue = 0;
rasterBand = rasterBands.Item(1);//band G
rasterProps = (IRasterProps)rasterBand;//now�?NoDataValue = 256 default value
rasterProps.NoDataValue = 0;
rasterBand = rasterBands.Item(2);//band B
rasterProps = (IRasterProps)rasterBand;//now�?NoDataValue = 256 default value
rasterProps.NoDataValue = 0;

IRaster pRaster = pRasterdataset.CreateDefaultRaster();
IRasterProps propt = (IRasterProps)pRaster;//now�?NoDataValue = 0
IRasterLayer pRasterlayer = new RasterLayerClass();
pRasterlayer.CreateFromRaster(pRaster);
ILayer pLayer = pRasterlayer as ILayer;
axGlobeControl1.Globe.AddLayerType(pLayer, esriGlobeLayerTypeFloating, false);
///////

But, it doesn�??t work!

Now display�?(have black region)
[ATTACH=CONFIG]30108[/ATTACH]

I want�?(do not show black region)(yellow region is earth map)
[ATTACH=CONFIG]30109[/ATTACH]


Thanks
0 Kudos
8 Replies
YY
by
New Contributor
No one reply:(
0 Kudos
by Anonymous User
Not applicable
Original User: Neil

Layer transparency is a property of the layer object.  You can set it using ILayerEffects.
0 Kudos
by Anonymous User
Not applicable
Original User: 674438511

No one reply:(


Thank you for your reply!

I have tried your method, but i'am sorry to tell you that it's not my want. ILayerEffects.Transparency is used to set the whole ILayer transparency. But how can i just change some specific rgb(such as R0 G0 B0) of raster to transparency?

Like this�?

Now display�?(have black region)
[ATTACH=CONFIG]30240[/ATTACH]

I want�?(set R=0 G=0 B=0 transparency)
[ATTACH=CONFIG]30241[/ATTACH]

Thanks for your help~
0 Kudos
YY
by
New Contributor
Layer transparency is a property of the layer object.  You can set it using ILayerEffects.


Thank you for your reply!

I have tried your method, but i'am sorry to tell you that it's not my want. ILayerEffects.Transparency is used to set the whole ILayer transparency. But how can i just change some specific rgb(such as R0 G0 B0) of raster to transparency?

Like this�?

Now display�?(have black region)
[ATTACH=CONFIG]30242[/ATTACH]

I want�?(set R=0 G=0 B=0 transparency)
[ATTACH=CONFIG]30243[/ATTACH]

Thanks for your help~
0 Kudos
by Anonymous User
Not applicable
Original User: 674438511

Something like this maybe?

            Dim pApp As IMxApplication = m_application
            Dim pDoc As IMxDocument = m_application.Document
            Dim pMap As IMap = pDoc.FocusMap
            Dim pLayer As ILayer = pMap.Layer(0) 'map index set here
            Dim pRasterLayer As IRasterLayer = pLayer
            Dim pLayerEffects As ILayerEffects

            pLayerEffects = pRasterLayer
            pLayerEffects.Transparency = 25 'transparceny value set here
            pDoc.ActiveView.Refresh()
            pDoc.UpdateContents()

sorry but this is vb.net snippet



Thank you for your reply!

I have tried your method, but i'am sorry to tell you that it's not my want. ILayerEffects.Transparency is used to set the whole ILayer transparency. But how can i just change some specific rgb(such as R0 G0 B0) of raster to transparency?

Like this�?

Now display�?(have black region)
[ATTACH=CONFIG]30244[/ATTACH]

I want�?(set R=0 G=0 B=0 transparency)
[ATTACH=CONFIG]30245[/ATTACH]

Thanks for your help~
0 Kudos
by Anonymous User
Not applicable
Original User: Neil

Thank you for your reply!

I have tried your method, but i'am sorry to tell you that it's not my want. ILayerEffects.Transparency is used to set the whole ILayer transparency. But how can i just change some specific rgb(such as R0 G0 B0) of raster to transparency?

Like this�?

Now display�?(have black region)
[ATTACH=CONFIG]30242[/ATTACH]

I want�?(set R=0 G=0 B=0 transparency)
[ATTACH=CONFIG]30243[/ATTACH]

Thanks for your help~


It looks like what you want to do is change your layer's NoData symbol to No Color.  You can do this through the Layer properties -> Symbology tab.
0 Kudos
by Anonymous User
Not applicable
Original User: 674438511

It looks like what you want to do is change your layer's NoData symbol to No Color.  You can do this through the Layer properties -> Symbology tab.


Thanks!

Yeah, I know i can change the layer's NoData symbol to No Color in ArcMap and ArcGlobe. However i want to do this in my own programe with c#. I will try.:o
0 Kudos
YY
by
New Contributor
This old thread may help? http://forums.esri.com/Thread.asp?c=93&f=993&t=77571

Looks like it was figured out here... http://forums.esri.com/Thread.asp?c=93&f=992&t=77921

This is old code, not my code, I have not tested it, it's from the old forum post above... hope that helps...

'----------------change to stretched layer-------------------------
    Dim pStretchedRenderer As IRasterStretchColorRampRenderer
    Dim pRasterRendereer As IRasterRenderer
    Dim pRasterStretch As IRasterStretch
        Set pStretchedRenderer = New RasterStretchColorRampRenderer
        Set pRasterRendereer = pStretchedRenderer
        Set pRasterRendereer.Raster = pRLyr.Raster
        Set pRasterStretch = pStretchedRenderer
        pRasterStretch.BackgroundValues = 0
        pRasterStretch.Background = True
        Set pRLyr.Renderer = pStretchedRenderer
       
  pRLyr.Renderer.Update

  Set pStretchedRenderer = Nothing
  Set pRasterRendereer = Nothing
'----------------END change to stretched layer---------------------


Thanks!

I have tried your method and other methods in those URL. It does work when the tif image has only one band. But if the tif image has three bands(RGB), there will be some problem.

one band image original:
[ATTACH=CONFIG]30308[/ATTACH]

one band image after processing: (It works.)
[ATTACH=CONFIG]30309[/ATTACH]

three bands image original:
[ATTACH=CONFIG]30310[/ATTACH]

three bands image after processing: (It has problem. The RGB color is missing. Why?)
[ATTACH=CONFIG]30311[/ATTACH]

My code: (c#)
                    IRasterDataset pRasterdataset = pRasterworkspace.OpenRasterDataset(filename);
                    IRaster pRaster = pRasterdataset.CreateDefaultRaster();
                    IRasterLayer pRasterlayer = new RasterLayerClass();
                    pRasterlayer.CreateFromRaster(pRaster);

                    IRasterStretchColorRampRenderer pSR = new RasterStretchColorRampRenderer();
                    IRasterRenderer pRR = (IRasterRenderer)pSR;
                    pRR.Raster = pRasterlayer.Raster;
                    IRasterStretch pRS = (IRasterStretch)pSR;
                    //double[] bv = new double[3];
                    //bv[0] = 0.0;
                    //bv[1] = 0.0;
                    //bv[2] = 0.0;
                    //RgbColor c = new RgbColor();
                    //c.Red = 0;
                    //c.Green = 0;
                    //c.Blue = 0;
                    //c.Transparency = 0;
                    //c.NullColor = true;
                    //pRS.BackgroundColor = c;
                  
                    //pRS.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                    //pRS.StandardDeviationsParam = 3;
                    pRS.set_BackgroundValues(0.0);
                    pRS.Background = true;
                    pRasterlayer.Renderer = (IRasterRenderer)pSR;
                    pRasterlayer.Renderer.Update();

                    ILayer pLayer = pRasterlayer as ILayer;
                    axGlobeControl1.Globe.AddLayerType(pLayer, esriGlobeLayerTypeFloating, false);


Thanks for your help~
0 Kudos