/// <summary> /// 根据单波段拉伸渲染 /// </summary> /// <param name="rasterDataset">栅格数据集</param> /// <param name="graypos">第几波段</param> /// <param name="stretchType">拉伸方式</param> /// <param name="pFromColor">fromColor</param> /// <param name="pToColor">toColor</param> /// <returns></returns> public static IRasterRenderer StretchRenderer(ESRI.ArcGIS.Geodatabase.IRasterDataset rasterDataset, int graypos, esriRasterStretchTypesEnum stretchType, IRgbColor pFromColor, IRgbColor pToColor) { try { //Create the color ramp. IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass(); colorRamp.Size = 255; colorRamp.FromColor = pFromColor; colorRamp.ToColor = pToColor; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); //Create a stretch renderer. IRasterStretchColorRampRenderer stretchRenderer = new RasterStretchColorRampRendererClass(); IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer; //Set the renderer properties. IRaster raster = rasterDataset.CreateDefaultRaster(); rasterRenderer.Raster = raster; rasterRenderer.Update(); stretchRenderer.BandIndex = graypos; stretchRenderer.ColorRamp = colorRamp; //Set the stretch type. IRasterStretch pRasterStretch = (IRasterStretch)rasterRenderer; pRasterStretch.StretchType = stretchType; pRasterStretch.StandardDeviationsParam = 2; return(rasterRenderer); } catch { return(null); } }
private void DisplayBandComForm_Load(object sender, EventArgs e) { //初始化拉伸方法 List <string> temp = new List <string>(); temp.Add("直方图均衡化"); temp.Add("标准差"); temp.Add("最大最小值"); temp.Add("百分比截断"); this.comBox_StretchType.DataSource = temp; this.comBox_StretchType.SelectedIndex = 0; this.stretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE; //根据波段数显示不同界面 this.nBand = TOCRightLayer.BandCount; if (this.nBand == 1) { this.panel_multi.Visible = false; this.panel_single.Visible = true; } else { List <string> bandnames = new List <string>(); bandnames = getBandName(TOCRightLayer); addToCombox(this.comBox_B, bandnames); addToCombox(this.comBox_G, bandnames); addToCombox(this.comBox_R, bandnames); this.panel_single.Visible = false; this.panel_multi.Visible = true; } }
private void btn_Display_Click(object sender, EventArgs e) { switch (this.comBox_StretchType.SelectedValue.ToString()) { case "直方图均衡化": this.stretchType = esriRasterStretchTypesEnum.esriRasterStretch_HistogramEqualize; break; case "标准差": this.stretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations; break; case "最大最小值": this.stretchType = esriRasterStretchTypesEnum.esriRasterStretch_MinimumMaximum; break; case "百分比截断": this.stretchType = esriRasterStretchTypesEnum.esriRasterStretch_PercentMinimumMaximum; break; } if (this.nBand == 1)//单波段拉伸显示 { drawImage(this.TOCRightLayer.Name.ToString(), this.axMapControl.Extent); this.axMapControl.Refresh(); this.axTOCControl.Refresh(); } else { //如果选择的不够三个波段,无法进行彩色合成 if (this.comBox_B.Text.Length == 0 || this.comBox_G.Text.Length == 0 || this.comBox_R.Text.Length == 0) { MessageBox.Show("请选择进行彩色合成的波段!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } this.rgbPos[0] = this.comBox_R.SelectedIndex; this.rgbPos[1] = this.comBox_G.SelectedIndex; this.rgbPos[2] = this.comBox_B.SelectedIndex; drawImage(this.TOCRightLayer.Name.ToString(), this.axMapControl.Extent); this.axMapControl.Refresh(); this.axTOCControl.Refresh(); } }
/// <summary> /// 获取拉伸类型 /// </summary> /// <param name="stretchType">类型名</param> /// <returns></returns> public static esriRasterStretchTypesEnum GetStretchType(string stretchType) { //默认标准差拉伸类型 esriRasterStretchTypesEnum schType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations; switch (stretchType) { case "None": schType = esriRasterStretchTypesEnum.esriRasterStretch_NONE; break; case "Custom": schType = esriRasterStretchTypesEnum.esriRasterStretch_Custom; break; case "StandardDeviations": schType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations; break; case "HistogramEqualize": schType = esriRasterStretchTypesEnum.esriRasterStretch_HistogramEqualize; break; case "MinimumMaximum": schType = esriRasterStretchTypesEnum.esriRasterStretch_MinimumMaximum; break; case "HistogramSpecification": schType = esriRasterStretchTypesEnum.esriRasterStretch_HistogramSpecification; break; case "PercentClip": schType = esriRasterStretchTypesEnum.esriRasterStretch_PercentMinimumMaximum; break; } return(schType); }
/// <summary> /// 拉伸渲染 /// </summary> /// <param name="rasterLayer">渲染图层</param> /// <param name="stretType">拉伸类型</param> /// <param name="pStyleGalleryItem">颜色带样式</param> public static void RasterStretchRenderer(IRasterLayer rasterLayer, esriRasterStretchTypesEnum stretType, IStyleGalleryItem pStyleGalleryItem) { if (pStyleGalleryItem == null) { MessageBox.Show(@"Color ramp cannot be empty"); return; } //创建拉伸渲染 IRasterStretchColorRampRenderer stretchRenderer = new RasterStretchColorRampRendererClass(); IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer; //设置拉伸渲染参数属性 IRaster raster = rasterLayer.Raster; rasterRenderer.Raster = raster; rasterRenderer.Update(); stretchRenderer.BandIndex = 0; stretchRenderer.ColorRamp = RenderHelper.GetColorRamp(pStyleGalleryItem, 255); //设置拉伸类型 IRasterStretch stretchType = (IRasterStretch)rasterRenderer; stretchType.StretchType = stretType; rasterLayer.Renderer = rasterRenderer; }