Arcgis Engine 实现单波段栅格图层色带渲染(包括色带反转)
生活随笔
收集整理的這篇文章主要介紹了
Arcgis Engine 实现单波段栅格图层色带渲染(包括色带反转)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? 最近有同事問我ArcMap中的色帶反轉怎么實現,剛好我在整理以前的項目,找到了一些源碼備忘。
? ? ? ? ? ??
? ? 先說下思路,簡單來說就是得到柵格圖層的IRasterRenderer,轉換為IRasterStretchColorRampRenderer,在將這個接口轉換為IRasterStretch,IRasterStretch中有個Invert的方法可以控制色帶是否反轉。下面詳細說下實現過程。
? ? 1、重寫一個可以添加圖片的ComboBox
public partial class ComboboxSymbol : ComboBox{public ComboboxSymbol(){DrawMode = DrawMode.OwnerDrawFixed;DropDownStyle = ComboBoxStyle.DropDownList;}//重寫函數protected override void OnDrawItem(DrawItemEventArgs e){e.DrawBackground();e.DrawFocusRectangle();try{//顯示圖片Image image = (Image)Items[e.Index];System.Drawing.Rectangle rect = e.Bounds;e.Graphics.DrawImage(image, rect);}catch{}finally{base.OnDrawItem(e);}}}2、設計一個窗體,就下圖中的幾個按鈕,另外添加一個隱藏顯示的AxSymbologyControl,用來調用顯示系統色帶
3、窗體下的代碼如下
private IRasterLayer _pRasyerLayer = null;public ColorRamp(IRasterLayer pRasterLayer,int X,int Y){InitializeComponent();_pRasyerLayer = pRasterLayer;this.Location = new System.Drawing.Point(X, Y); //得到當前鼠標位置,用來確定窗體顯示的位置}private void btnCancel_Click(object sender, EventArgs e){this.Close();}private void LoadSymbolProperty(IRasterLayer mRasterLayer){IRasterStretchColorRampRenderer pStretchRen;try{pStretchRen = (IRasterStretchColorRampRenderer)mRasterLayer.Renderer;IRasterStretch pRasterStretch = pStretchRen as IRasterStretch;if (pRasterStretch.Invert){ckInvert.Checked = true;}}catch (Exception ex){WriteLog.LogWritter.WriteLogToFile(ex.Message);return;}try{//加載系統樣式string sInstall = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path;string defaultStyle = System.IO.Path.Combine(sInstall, "Styles\\ESRI.ServerStyle");axSymbologyControl1.LoadStyleFile(defaultStyle);axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassColorRamps;ISymbologyStyleClass symbologyStyleClass = axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassColorRamps);IStyleGalleryItem styleGalleryItem = new ServerStyleGalleryItem();styleGalleryItem.Item = pStretchRen.ColorRamp;styleGalleryItem.Name = "mySymbol";symbologyStyleClass.AddItem(styleGalleryItem, 0);symbologyStyleClass.SelectItem(0);//將樣式轉為圖片并添加入ComboBoxfor (int i = 0; i < symbologyStyleClass.get_ItemCount(symbologyStyleClass.StyleCategory); i++){stdole.IPictureDisp picture = symbologyStyleClass.PreviewItem(symbologyStyleClass.GetItem(i), cbSymbol.Width, cbSymbol.Height);System.Drawing.Image image = System.Drawing.Image.FromHbitmap(new System.IntPtr(picture.Handle));cbSymbol.Items.Add(image);}if (cbSymbol.Items.Count > 0)cbSymbol.SelectedIndex = 0;}catch (Exception ex){WriteLog.LogWritter.WriteLogToFile(ex.Message);}}private void SetRasterSymbol(IRasterLayer mRasterLayer){try{//獲取選擇的序號int symbol_index = cbSymbol.SelectedIndex;ISymbologyStyleClass symbologyStyleClass = axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassColorRamps);IStyleGalleryItem mStyleGalleryItem = symbologyStyleClass.GetItem(symbol_index);//獲取選擇的符號IColorRamp colorramp_select = (IColorRamp)mStyleGalleryItem.Item;IRasterStretchColorRampRenderer pStretchRen = (IRasterStretchColorRampRenderer)mRasterLayer.Renderer;pStretchRen.ColorRamp = colorramp_select;IRasterStretch pRasterStretch = pStretchRen as IRasterStretch;//控制色帶是否反轉if (ckInvert.Checked){pRasterStretch.Invert = true;}else{pRasterStretch.Invert = false;}}catch (Exception ex){WriteLog.LogWritter.WriteLogToFile(ex.Message);this.Close();}}private void ColorRamp_Load(object sender, EventArgs e){LoadSymbolProperty(_pRasyerLayer);}private void btnOk_Click(object sender, EventArgs e){SetRasterSymbol(_pRasyerLayer);this.DialogResult = DialogResult.OK;this.Close();}}?
?
?
總結
以上是生活随笔為你收集整理的Arcgis Engine 实现单波段栅格图层色带渲染(包括色带反转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MEMS加速度计性能测评
- 下一篇: 电驴服务器搜索文件排序,【图文教程】搜索