ArcEngine实现色带下拉框

news/2024/10/20 3:32:52/

效果如下:
在这里插入图片描述在这里插入图片描述
利用ArcEngine实现色带下拉框主要分两步。第一步:拖一个SymbologyControl到界面上,设置为不可见,通过SymbologyControl读取色带。第二步:重绘Combobox,将读取的色带转换为Image类型添加到Combobox中。
读取色带

        private void InitSymbologyControl(){this.axSymbologyControl1.LoadStyleFile(Application.StartupPath + "\\ESRI.ServerStyle");this.axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassColorRamps;this.pSymbologyStyleClass = axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassColorRamps);}

添加至Combobox

        private void InitColorRampCombobox(){this.cmbColorRamp.DrawMode = DrawMode.OwnerDrawFixed;this.cmbColorRamp.DropDownStyle = ComboBoxStyle.DropDownList;for (int i = 0; i < pSymbologyStyleClass.ItemCount; i++){IStyleGalleryItem pStyleGalleryItem = pSymbologyStyleClass.GetItem(i);IPictureDisp pPictureDisp = pSymbologyStyleClass.PreviewItem(pStyleGalleryItem, cmbColorRamp.Width, cmbColorRamp.Height);Image image = Image.FromHbitmap(new IntPtr(pPictureDisp.Handle));cmbColorRamp.Items.Add(image);}cmbColorRamp.SelectedIndex = 0;}private void cmbColorRamp_DrawItem_1(object sender, DrawItemEventArgs e){e.DrawBackground();e.DrawFocusRectangle();e.Graphics.DrawImage(cmbColorRamp.Items[e.Index] as Image, e.Bounds);}

完整代码如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using stdole;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.SystemUI;
using System.Collections;namespace WindowsFormsApplication1
{public partial class Form1 : DevComponents.DotNetBar.Metro.MetroForm{private ISymbologyStyleClass pSymbologyStyleClass;private Dictionary<int, IColorRamp> colorRampDictionary;// 构造函数public Form1(){InitializeComponent();InitSymbologyControl();InitColorRampCombobox();InitDictionary();}// 初始化符号库private void InitSymbologyControl(){this.axSymbologyControl1.LoadStyleFile(Application.StartupPath + "\\ESRI.ServerStyle");this.axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassColorRamps;this.pSymbologyStyleClass = axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassColorRamps);}// 初始化色带下拉框private void InitColorRampCombobox(){this.cmbColorRamp.DrawMode = DrawMode.OwnerDrawFixed;this.cmbColorRamp.DropDownStyle = ComboBoxStyle.DropDownList;for (int i = 0; i < pSymbologyStyleClass.ItemCount; i++){IStyleGalleryItem pStyleGalleryItem = pSymbologyStyleClass.GetItem(i);IPictureDisp pPictureDisp = pSymbologyStyleClass.PreviewItem(pStyleGalleryItem, cmbColorRamp.Width, cmbColorRamp.Height);Image image = Image.FromHbitmap(new IntPtr(pPictureDisp.Handle));cmbColorRamp.Items.Add(image);}cmbColorRamp.SelectedIndex = 0;}// 初始化字典private void InitDictionary(){this.colorRampDictionary = new Dictionary<int, IColorRamp>();for (int i = 0; i < pSymbologyStyleClass.ItemCount; i++){IStyleGalleryItem pStyleGalleryItem = pSymbologyStyleClass.GetItem(i);IColorRamp pColorRamp = pStyleGalleryItem.Item as IColorRamp;colorRampDictionary.Add(i, pColorRamp);}}// 重绘下拉框条目private void cmbColorRamp_DrawItem_1(object sender, DrawItemEventArgs e){e.DrawBackground();e.DrawFocusRectangle();e.Graphics.DrawImage(cmbColorRamp.Items[e.Index] as Image, e.Bounds);}// 渲染private void btnRenderer_Click(object sender, EventArgs e){IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, true);// 统计唯一值IDataStatistics pDataStatistics = new DataStatistics();pDataStatistics.Field = "name";pDataStatistics.Cursor = pFeatureCursor as ICursor;IEnumerator pEnumerator = pDataStatistics.UniqueValues;int uniqueValuesCount = pDataStatistics.UniqueValueCount;// 设置渲染字段IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRenderer();pUniqueValueRenderer.FieldCount = 1;pUniqueValueRenderer.set_Field(0, "name");// 添加唯一值IEnumColors pEnumColors = CreateColorRamp(uniqueValuesCount);while (pEnumerator.MoveNext()){ISymbol pSymbol = CreateSymbol(pFeatureClass.ShapeType,pEnumColors.Next());string p = pEnumerator.Current.ToString();pUniqueValueRenderer.AddValue(p, "", pSymbol);}// 刷XINDITUIGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;pGeoFeatureLayer.Renderer = pUniqueValueRenderer as IFeatureRenderer;axMapControl1.ActiveView.Refresh();}// 创建色带private IEnumColors CreateColorRamp(int size){bool ok = false;IColorRamp pColorRamp = colorRampDictionary[cmbColorRamp.SelectedIndex];pColorRamp.Size = size;pColorRamp.CreateRamp(out ok);return pColorRamp.Colors;}// 创建符号private ISymbol CreateSymbol(esriGeometryType geomerryType, IColor pColor){ISymbol pSymbol = null;if (geomerryType == esriGeometryType.esriGeometryPoint){ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbol();pSimpleMarkerSymbol.Color = pColor;pSymbol = pSimpleMarkerSymbol as ISymbol;}else if (geomerryType == esriGeometryType.esriGeometryPolyline){ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol();pSimpleLineSymbol.Color = pColor;pSymbol = pSimpleLineSymbol as ISymbol;}else{ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol();pSimpleFillSymbol.Color = pColor;pSymbol = pSimpleFillSymbol as ISymbol;}return pSymbol;}}
}

http://www.ppmy.cn/news/162363.html

相关文章

【光通信-1】根据光模块拉环颜色区分光模块

1. 通过光模块的拉环颜色来分辨波长 1.1 常用的光模颜色区分&#xff1a; 常用的光模块有四种波长&#xff0c;850nm&#xff0c;1310nm&#xff0c;1490nm&#xff0c;1550nm。其中千兆SPF光模块850nm对应的拉环颜色为黑色&#xff0c;1310nm对应的拉环颜色为蓝色&#xff0…

热转印打码色带产品类别及介绍

适用场合 热转印色带&#xff0c;常作为打码设备的耗材用于标签、卷膜等承印材料上打印信息用&#xff0c;是标签打印机和热转印打码机专用打码耗材。 产品特点 铂高热转印色带具有耐高温、抗污渍、耐摩擦、耐腐蚀性能&#xff1b;高敏感度确保优异的打印效果&#xff0c;高分…

什么是TTO热转印色带?

什么是热转印色带&#xff1f; 热转印色带是一种用途非常广泛、用量非常巨大的产品。随着我国信息技术的迅猛发展以及计算机应用领域的不断拓展和深入&#xff0c;人们对高速、高质量输出的打印需求越来越大&#xff0c;而市场上传统的打印方式在价格、打印质量、打印速度等方…

matlab 生成色带和彩色图像

直接用命令colorbar&#xff0c;或者在图像的编辑窗口选择插入&#xff0c;然后选择色带。 用imshow可以直接show出一个由n*n的矩阵生成的灰度图像。之后&#xff0c;可以采用用colormap(jet)转换为彩色图像。 也可以直接用imagesc(A)生成彩色图像。这里&#xff0c;MATLAB能够…

色带通用型号表_Excel表中基于日期的色带

色带通用型号表 When you create a named table in Excel, you can colour the alternating rows with one of the built-in Table Styles. But how could you colour alternating groups of information, such as dates? This example shows show to create colour bands, ba…

ATK-LORA 无线通信模块

文章目录 前言一、ATK-LORA二、AT指令集及工作模式三、传输模式四、上位机配置五、stm32通信设计 前言 一、ATK-LORA ATK-LORA是正点原子推出的一款小体积、微功率、低功耗、高性能的远距离 LoRa 无线串口模块&#xff0c;该模块采用高效的 ISM 频段射频 SX1278 扩频芯片&…

破解色带现象(下)

编者按&#xff1a;本文是“破解色带现象”文章的第二部分&#xff0c;Fabio Sonnati进一步 分析了色带现象产生的原因&#xff0c;并提供了新的检测办法。本文已获得作者授权转载。 翻译&#xff1a;Argus 原文链接&#xff1a;https://sonnati.wordpress.com/2022/09/16/def…

APA102C全彩色LED控制IC

简 介&#xff1a; 测试了APA102C的工作机制。利用MM32F3277 MicroPython中的SPI控制APA102C工作。 关键词&#xff1a; APA102C&#xff0c;MM32F3277&#xff0c;SPI #mermaid-svg-1dMRs5eydBfToic6 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-si…