1 protected override void OnClick() 2 { 3 // 4 // TODO: Sample code showing how to access button host 5 // 6 ArcMap.Application.CurrentTool = null; 7 8 IMap pMap = ArcMap.Document.FocusMap; 9 for (int i = 0; i < pMap.LayerCount; i++) 10 { 11 ILayer pLayer = pMap.get_Layer(i); 12 if (pLayer is IRasterLayer) 13 { 14 IRasterLayer pRstLyr = pLayer as IRasterLayer; 15 IRasterStretchColorRampRenderer pRasterStretchColorRampRenderer; 16 IRasterStretch2 prstStretch= pRstLyr.Renderer as IRasterStretch2; 17 // Setup the stretch 18 prstStretch.Background = true; 19 // Apply the renderer 20 pRstLyr.Renderer = (IRasterRenderer)prstStretch; 21 // Collapse the legends on each raster 22 ILegendInfo legendInfo = (ILegendInfo)pRstLyr.Renderer; 23 ILegendGroup legendGroup = (ILegendGroup)legendInfo.get_LegendGroup(0); 24 legendGroup.Visible = false; 25 } 26 } 27 }
核心實現代碼如上
上述代碼實現了對TOC中所有柵格圖層批量設置其背景色為透明,可以避免在工作中加載大量分幅圖時,部分分幅圖背景顯示為黑色導致的黑邊問題.
相當於批量將TOC中所有柵格圖層勾選了 Display background Value as 選項.

上述代碼只是簡單實現了功能,沒有考慮圖層組的情況,如果圖層放入圖層組中,會檢索不到,從而不對圖層組中的圖層做任何處理
編譯插件文件下載地址: 鏈接: https://pan.baidu.com/s/1GUBJRe_dLV7657ozgTqVhw 密碼: djq2
