public Thematic(IMapControl3 mapControl) { if (mapControl != null) { this._mapControl = mapControl; } _renderer = new ClassBreaksRendererClass(); _classify = new QuantileClass(); _tableHistogram = new BasicTableHistogramClass(); _colorFrom = new HsvColorClass(); _colorTo = new HsvColorClass(); _algClrRamp = new AlgorithmicColorRampClass(); }
private void UpdateRamp() { // // Create a new AlgorithmicColorRamp object, and get it's // IAlgorithmicColorRamp interface. // IAlgorithmicColorRamp AlgortihmicColorRamp = null; AlgortihmicColorRamp = new ESRI.ArcGIS.Display.AlgorithmicColorRamp(); // // Set the size of the color ramp to the number of classes // to be renderered. // AlgortihmicColorRamp.Size = m_lngClasses; // // Set the color ramps properties. // IRgbColor RGBColor = null; RGBColor = new RgbColor(); RGBColor.RGB = System.Drawing.ColorTranslator.ToOle(txtStartColor.BackColor); AlgortihmicColorRamp.FromColor = RGBColor; RGBColor.RGB = System.Drawing.ColorTranslator.ToOle(txtEndColor.BackColor); AlgortihmicColorRamp.ToColor = RGBColor; AlgortihmicColorRamp.Algorithm = (esriColorRampAlgorithm)cmbAlgorithm.SelectedIndex; bool boolRamp = false; if (AlgortihmicColorRamp.Size > 0) { boolRamp = true; AlgortihmicColorRamp.CreateRamp(out boolRamp); if (boolRamp) { m_enumNewColors = AlgortihmicColorRamp.Colors; m_enumNewColors.Reset(); cmdOK.Enabled = true; // // Check if we should be showing the colors. // if (chkShowColors.CheckState == System.Windows.Forms.CheckState.Checked) { // // Populate the Colors textbox array and it's labels. // m_lngColors = 0; ShowColorsArray(); } } } }
public static IRasterRenderer CreateDEMColorRamp(Raster gRaster) { IColor pStartColor = (IColor)CreateRGBColor(255, 235, 176); IColor pEndColor = (IColor)CreateRGBColor(38, 115, 0); IAlgorithmicColorRamp pColorRamp1 = CreateAlgorithmicColorRamp(pStartColor, pEndColor); pStartColor = (IColor)CreateRGBColor(38, 115, 0); pEndColor = (IColor)CreateRGBColor(115, 77, 0); IAlgorithmicColorRamp pColorRamp2 = CreateAlgorithmicColorRamp(pStartColor, pEndColor); pStartColor = (IColor)CreateRGBColor(115, 77, 0); pEndColor = (IColor)CreateRGBColor(255, 255, 255); IAlgorithmicColorRamp pColorRamp3 = CreateAlgorithmicColorRamp(pStartColor, pEndColor); List <IColorRamp> lColorRamps = new List <IColorRamp>(new IColorRamp[] { pColorRamp1, pColorRamp2, pColorRamp3 }); IMultiPartColorRamp pMultiPartColorRamp = CreateMultiPartColorRamp(lColorRamps); return(CreateContinuousRenderer(gRaster, pMultiPartColorRamp)); }
private ESRI.ArcGIS.Display.IColor GetCombinedColor(IColor pColor1, IColor pColor2, EColorCombinationType eCombinationMethod, IColor pOriginColor) { // combines the input colors based on m_eColorCombinationMethod // (11/08/04) -- RGB and enuLabLChColorRamp aren't used by GUI IColor pOutColor = null; long MyOLE_COLOR = 0; // As OLE_COLOR in VB6 IRgbColor pMainRGBColor = null; IRgbColor pVariationRGBColor = null; IRgbColor pMergedRGBColor = null; bool bOK = false; IAlgorithmicColorRamp pAlgorithmicCR = null; // if either of the colors are null, then don't run the color through any algorithm, // instead, just return the other color. if both are null, then return a null color if (pColor1.NullColor) { pOutColor = pColor2; } else if (pColor2.NullColor) { pOutColor = pColor1; } else if (eCombinationMethod == EColorCombinationType.enuComponents) { // HSV components // create a new HSV color IHsvColor pHSVDrawColor = null; pHSVDrawColor = new HsvColor(); // get HSV values from Color1 and Color2 and assign to pHSVDrawColor IHsvColor pHSVColor1 = null; IHsvColor pHSVColor2 = null; // (new 4/27/04) didn't think I had to do this... //pHSVColor1 = pColor1 //pHSVColor2 = pColor2 pHSVColor1 = new HsvColor(); pHSVColor1.RGB = pColor1.RGB; pHSVColor2 = new HsvColor(); pHSVColor2.RGB = pColor2.RGB; pHSVDrawColor.Hue = pHSVColor1.Hue; pHSVDrawColor.Saturation = pHSVColor2.Saturation; pHSVDrawColor.Value = pHSVColor2.Value; pOutColor = pHSVDrawColor; } else if (eCombinationMethod == EColorCombinationType.enuRGBAverage) { // use additive color model to merge the two colors MyOLE_COLOR = pColor1.RGB; pMainRGBColor = new RgbColor(); pMainRGBColor.RGB = (int)MyOLE_COLOR; MyOLE_COLOR = pColor2.RGB; pVariationRGBColor = new RgbColor(); pVariationRGBColor.RGB = (int)MyOLE_COLOR; // merged color = RGB average of the two colors pMergedRGBColor = new RgbColor(); pMergedRGBColor.Red = (pMainRGBColor.Red + pVariationRGBColor.Red) / 2; pMergedRGBColor.Green = (pMainRGBColor.Green + pVariationRGBColor.Green) / 2; pMergedRGBColor.Blue = (pMainRGBColor.Blue + pVariationRGBColor.Blue) / 2; pOutColor = pMergedRGBColor; } else if ((eCombinationMethod == EColorCombinationType.enuCIELabColorRamp) | (eCombinationMethod == EColorCombinationType.enuLabLChColorRamp)) { // use color ramp and take central color between the two colors pAlgorithmicCR = new AlgorithmicColorRamp(); if (m_eColorCombinationMethod == EColorCombinationType.enuCIELabColorRamp) pAlgorithmicCR.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; else pAlgorithmicCR.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm; pAlgorithmicCR.Size = 3; pAlgorithmicCR.FromColor = pColor1; pAlgorithmicCR.ToColor = pColor2; pAlgorithmicCR.CreateRamp(out bOK); pOutColor = pAlgorithmicCR.get_Color(1); // middle color in ramp } else // EColorCombinationType.enuCIELabMatrix { double[] iLab1 = new double[4]; // L, a, b values for Color1 double[] iLab2 = new double[4]; // L, a, b values for Color2 double[] iLabOrig = new double[4]; // L, a, b values for pOriginColor pColor1.GetCIELAB(out iLab1[0], out iLab1[1], out iLab1[2]); pColor2.GetCIELAB(out iLab2[0], out iLab2[1], out iLab2[2]); pOriginColor.GetCIELAB(out iLabOrig[0], out iLabOrig[1], out iLabOrig[2]); double[] iLabOut = new double[4]; // add color1 vector and color2 vector, then subtract the origin color vector iLabOut[0] = iLab1[0] + iLab2[0] - iLabOrig[0]; iLabOut[1] = iLab1[1] + iLab2[1] - iLabOrig[1]; iLabOut[2] = iLab1[2] + iLab2[2] - iLabOrig[2]; CorrectLabOutofRange(ref iLabOut[0], ref iLabOut[1], ref iLabOut[2]); IHsvColor pHSVColor = null; pHSVColor = new HsvColor(); pHSVColor.SetCIELAB(iLabOut[0], iLabOut[1], iLabOut[2]); pOutColor = pHSVColor; } return pOutColor; }
private Bitmap DrawToPictureBox(ISymbol pSym, PictureBox pBox) { IGeometry pGeometry = null; System.Drawing.Graphics pGraphics = null; pGraphics = System.Drawing.Graphics.FromHwnd(pBox.Handle); pGraphics.FillRectangle(System.Drawing.Brushes.White, pBox.ClientRectangle); Bitmap image = new Bitmap(pBox.Width, pBox.Height, pGraphics); IEnvelope pEnvelope = new EnvelopeClass(); if (pSym is IMarkerSymbol) { IPoint pPoint = new PointClass(); //the geometry of a MarkerSymbol pPoint.PutCoords(pBox.Width / 2, pBox.Height / 2); //center in middle of pBox pGeometry = pPoint; } if (pSym is ILineSymbol) { pEnvelope.PutCoords(0, pBox.Height / 2, pBox.Width, pBox.Height / 2); IPolyline pPolyline = new PolylineClass(); pPolyline.FromPoint = pEnvelope.LowerLeft; pPolyline.ToPoint = pEnvelope.UpperRight; pGeometry = pPolyline; } if (pSym is IFillSymbol) { pEnvelope.PutCoords(1, 1, pBox.Width - 1, pBox.Height - 1); pGeometry = pEnvelope; if (pSym is IMultiLayerFillSymbol) { IMultiLayerFillSymbol pMultiLayerFillSymbol = pSym as IMultiLayerFillSymbol; //For mLayers As Integer = 0 To pMultiLayerFillSymbol.LayerCount - 1 for (int i = 0; i < pMultiLayerFillSymbol.LayerCount; i++) { if (pMultiLayerFillSymbol.get_Layer(i) is IPictureFillSymbol) { IPictureFillSymbol pPictureFillSymbol = pMultiLayerFillSymbol.get_Layer(0) as IPictureFillSymbol; image = Bitmap.FromHbitmap(new IntPtr(pPictureFillSymbol.Picture.Handle)); //m.MakeTransparent(System.Drawing.ColorTranslator.FromOle(pPictureFillSymbol.Color.RGB)) return(image); } else if (pMultiLayerFillSymbol.get_Layer(i) is ISimpleFillSymbol) { pEnvelope.PutCoords(1, 1, pBox.Width - 1, pBox.Height - 1); pGeometry = pEnvelope; } else if (pMultiLayerFillSymbol.get_Layer(i) is IGradientFillSymbol) { IGradientFillSymbol pGradientFillSymbol = pMultiLayerFillSymbol.get_Layer(0) as IGradientFillSymbol; IAlgorithmicColorRamp pRamp = pGradientFillSymbol.ColorRamp as IAlgorithmicColorRamp; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), new System.Drawing.Size(pBox.Width, pBox.Height)); LinearGradientBrush lgBrush = new LinearGradientBrush(rect, System.Drawing.ColorTranslator.FromOle(pRamp.FromColor.RGB), System.Drawing.ColorTranslator.FromOle(pRamp.ToColor.RGB), 45); pGraphics.FillRectangle(lgBrush, rect); rect.Width = rect.Width - 1; rect.Height = rect.Height - 1; pGraphics.DrawRectangle(new Pen(ColorTranslator.FromOle(pGradientFillSymbol.Outline.Color.RGB), (float)pGradientFillSymbol.Outline.Width), rect); image = new Bitmap(pBox.Width, pBox.Height, pGraphics); } } } else if (pSym is IPictureFillSymbol) { IPictureFillSymbol pPictureFillSymbol = pSym as IPictureFillSymbol; image = Bitmap.FromHbitmap(new IntPtr(pPictureFillSymbol.Picture.Handle)); //m.MakeTransparent(System.Drawing.ColorTranslator.FromOle(pPictureFillSymbol.Color.RGB)) return(image); } } IntPtr hDC = GetDC(pBox.Handle); pSym.SetupDC(hDC.ToInt32(), null); pSym.ROP2 = esriRasterOpCode.esriROPCopyPen; if (pGeometry != null) { pSym.Draw(pGeometry); } pSym.ResetDC(); Graphics g2 = Graphics.FromImage(image); //获得屏幕的句柄 IntPtr dc3 = pGraphics.GetHdc(); //获得位图的句柄 IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, pBox.Width, pBox.Height, dc3, 0, 0, SRCCOPY); pGraphics.ReleaseHdc(dc3); //释放屏幕句柄 g2.ReleaseHdc(dc2); //释放位图句柄 //image.Save("c:\\MyJpeg.Icon", ImageFormat.Bmp); return(image); }
private void DrawToPictureBox(ISymbol pSym, PictureBox pBox) { IGeometry pGeometry = null; IntPtr hDC; IEnvelope pEnvelope; pEnvelope = new EnvelopeClass(); // Reset the PictureBox pBox.CreateGraphics().Clear(pBox.BackColor); try { if (pSym is IMarkerSymbol) { pEnvelope.PutCoords(pBox.Width / 2, pBox.Height / 2, pBox.Width / 2, pBox.Height / 2); IArea pArea = pEnvelope as IArea; pGeometry = pArea.Centroid; } else if (pSym is ILineSymbol) { pEnvelope.PutCoords(0, pBox.Height / 2, pBox.Width, pBox.Height / 2); IPolyline pPolyline = new PolylineClass(); pPolyline.FromPoint = pEnvelope.LowerLeft; pPolyline.ToPoint = pEnvelope.UpperRight; pGeometry = pPolyline; } else if (pSym is IFillSymbol) { if (pSym is SimpleFillSymbol) { pEnvelope.PutCoords(5, 5, pBox.Width - 5, pBox.Height - 5); pGeometry = pEnvelope; } else if (pSym is MultiLayerFillSymbol) { IMultiLayerFillSymbol pMultiLayerFillSymbol = pSym as IMultiLayerFillSymbol; //For mLayers As Integer = 0 To pMultiLayerFillSymbol.LayerCount - 1 if (pMultiLayerFillSymbol.get_Layer(0) is PictureFillSymbol) { IPictureFillSymbol pPictureFillSymbol = pMultiLayerFillSymbol.get_Layer(0) as IPictureFillSymbol; Bitmap m = Bitmap.FromHbitmap(new IntPtr(pPictureFillSymbol.Picture.Handle)); //m.MakeTransparent(System.Drawing.ColorTranslator.FromOle(pPictureFillSymbol.Color.RGB)) pBox.Image = m; return; } else if (pMultiLayerFillSymbol.get_Layer(0) is SimpleFillSymbol) { pEnvelope.PutCoords(5, 5, pBox.Width - 5, pBox.Height - 5); pGeometry = pEnvelope; } else if (pMultiLayerFillSymbol.get_Layer(0) is GradientFillSymbol) { IGradientFillSymbol pGradientFillSymbol = pMultiLayerFillSymbol.get_Layer(0) as IGradientFillSymbol; IAlgorithmicColorRamp pRamp = pGradientFillSymbol.ColorRamp as IAlgorithmicColorRamp; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), new System.Drawing.Size(pBox.Width, pBox.Height)); LinearGradientBrush lgBrush = new LinearGradientBrush(rect, System.Drawing.ColorTranslator.FromOle(pRamp.FromColor.RGB), System.Drawing.ColorTranslator.FromOle(pRamp.ToColor.RGB), 45); Graphics g = pBox.CreateGraphics(); g.FillRectangle(lgBrush, rect); rect.Width = rect.Width - 1; rect.Height = rect.Height - 1; g.DrawRectangle(new Pen(ColorTranslator.FromOle(pGradientFillSymbol.Outline.Color.RGB), (float)pGradientFillSymbol.Outline.Width), rect); } } else if (pSym is PictureFillSymbol) { IPictureFillSymbol pPictureFillSymbol = pSym as IPictureFillSymbol; Bitmap m = Bitmap.FromHbitmap(new IntPtr(pPictureFillSymbol.Picture.Handle)); //m.MakeTransparent(System.Drawing.ColorTranslator.FromOle(pPictureFillSymbol.Color.RGB)) pBox.Image = m; return; } } hDC = GetDC(pBox.Handle); pSym.SetupDC(hDC.ToInt32(), null); pSym.ROP2 = esriRasterOpCode.esriROPCopyPen; if (pGeometry != null) { pSym.Draw(pGeometry); } pSym.ResetDC(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// 分级色彩符号化 public static void GraduatedColors(IFeatureLayer featureLayer, string fieldName, int numClasses, IMapControl2 mapControl, AxTOCControl tocControl) { object dataFrequency; object dataValue; int breakIndex; ITable pTable = featureLayer.FeatureClass as ITable; ITableHistogram pTableHistogram = new BasicTableHistogramClass() { Field = fieldName, Table = pTable }; IBasicHistogram pBasicHistogram = (IBasicHistogram)pTableHistogram; // 获取渲染字段的值及其出现的频率 pBasicHistogram.GetHistogram(out dataValue, out dataFrequency); IClassifyGEN pClassifyGEN = new EqualIntervalClass(); try { pClassifyGEN.Classify(dataValue, dataFrequency, ref numClasses); } catch { } // 返回一个数组 double[] Classes = pClassifyGEN.ClassBreaks as double[]; int ClassesCount = Classes.GetUpperBound(0); IClassBreaksRenderer pRenderer = new ClassBreaksRendererClass() { // 分级字段 分级数目 分级后的图例是否按升级顺序排序 Field = fieldName, BreakCount = ClassesCount, SortClassesAscending = true }; // 设置分级说色所需颜色带的起止颜色 //IHsvColor pFromColor = GetHsvColor(0, 50, 96); //IHsvColor pToColor = GetHsvColor(80, 100, 96); IRgbColor pFromColor = GetRgbColor(255, 200, 200); IRgbColor pToColor = GetRgbColor(255, 0, 0); // 生成颜色带对象 IAlgorithmicColorRamp pColorRamp = CreateColorRamp(pFromColor, pToColor, ClassesCount); // 获取色带颜色集 IEnumColors pEnumColors = pColorRamp.Colors; // 逐一设置填充符号及每一分级的分级断点 for (breakIndex = 0; breakIndex < ClassesCount; breakIndex++) { IColor pColor = pEnumColors.Next(); ISymbol pSymbol = null; switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolygon: pSymbol = new SimpleFillSymbolClass() { Color = pColor, Style = esriSimpleFillStyle.esriSFSSolid }; break; case esriGeometryType.esriGeometryPolyline: pSymbol = new SimpleLineSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPoint: pSymbol = new SimpleMarkerSymbolClass() { Color = pColor }; break; } // 设置填充符号 pRenderer.set_Symbol(breakIndex, pSymbol); // 设置每一级的分级断点 pRenderer.set_Break(breakIndex, Classes[breakIndex + 1]); } (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); }