Esempio n. 1
0
        private void DrawColorRamp()
        {
            string               sInstall            = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path;
            string               styleFilePath       = sInstall + "\\Styles\\ESRI.ServerStyle";
            IStyleGallery        styleGallery        = new ServerStyleGalleryClass();
            IStyleGalleryItem    styleGalleryItem    = null;
            IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;

            styleGalleryStorage.AddFile(styleFilePath);

            IEnumStyleGalleryItem enumStyleGalleryItem = styleGallery.get_Items("Color Ramps", styleFilePath, "");

            enumStyleGalleryItem.Reset();

            styleGalleryItem = enumStyleGalleryItem.Next();

            while (styleGalleryItem != null)
            {
                m_ColorRamp = (IColorRamp)styleGalleryItem.Item;
                EnumStyleItem.Add(m_ColorRamp);
                m_FillSymbol = new GradientFillSymbol();
                m_FillSymbol.GradientAngle = 0;
                m_FillSymbol.ColorRamp     = m_ColorRamp;
                pictureBox1.Image          = SymbolToBitmap(m_FillSymbol, 0, pictureBox1.Width, pictureBox1.Height);
                imageList1.Images.Add(pictureBox1.Image);
                comboBoxColor.Items.Add(pictureBox1.Image);
                styleGalleryItem = enumStyleGalleryItem.Next();
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(enumStyleGalleryItem);
        }
Esempio n. 2
0
        private void DrawColorRamp()
        {
            string               strDefaultStyleFileName = string.Format("{0}\\CNUStyles\\ESRI.ServerStyle", Application.StartupPath);
            IStyleGallery        styleGallery            = new ServerStyleGalleryClass();
            IStyleGalleryItem    styleGalleryItem        = new ServerStyleGalleryItemClass();
            IStyleGalleryStorage styleGalleryStorage     = styleGallery as IStyleGalleryStorage;

            styleGalleryStorage.AddFile(strDefaultStyleFileName);
            IEnumStyleGalleryItem enumStyleGalleryItem = styleGallery.get_Items("Color Ramps", strDefaultStyleFileName, "");

            enumStyleGalleryItem.Reset();
            styleGalleryItem = enumStyleGalleryItem.Next();
            while (styleGalleryItem != null)
            {
                m_ColorRamp = (IColorRamp)styleGalleryItem.Item;
                EnumStyleItem.Add(m_ColorRamp);
                //新建m_FillSymbol和m_colorRamp
                m_FillSymbol = new GradientFillSymbol();
                m_FillSymbol.GradientPercentage = 1;
                m_FillSymbol.IntervalCount      = 255;
                m_FillSymbol.GradientAngle      = 0;
                m_FillSymbol.ColorRamp          = m_ColorRamp;
                pictureBox1.Image = SymbolToBitmap(m_FillSymbol, 0, pictureBox1.Width, pictureBox1.Height);
                pictureBox2.Image = SymbolToBitmap(m_FillSymbol, 0, pictureBox1.Width, pictureBox1.Height);
                imageList1.Images.Add(m_ColorRamp.Name, pictureBox1.Image);
                imageList2.Images.Add(m_ColorRamp.Name, pictureBox1.Image);
                colorComboBox.Items.Add(pictureBox1.Image);
                colorComboBox1.Items.Add(pictureBox2.Image);
                styleGalleryItem = enumStyleGalleryItem.Next();
            }
        }
Esempio n. 3
0
        private Image SymbolToBitmap(IGradientFillSymbol iSymbol, int iStyle, int iWidth, int iHeight)
        {
            IntPtr    iHDC      = new IntPtr();
            Bitmap    iBitmap   = new Bitmap(iWidth, iHeight);
            Graphics  iGraphics = System.Drawing.Graphics.FromImage(iBitmap);
            tagRECT   itagRECT;
            IEnvelope iEnvelope = new EnvelopeClass() as IEnvelope;
            IDisplayTransformation iDisplayTransformation;
            IPoint iPoint;
            IGeometryCollection iPolyline;
            IGeometryCollection iPolygon;
            IRing iRing;
            ISegmentCollection iSegmentCollection;
            IGeometry          iGeometry = null;
            object             Missing   = Type.Missing;

            iEnvelope.PutCoords(0, 0, iWidth, iHeight);
            itagRECT.left          = 0;
            itagRECT.right         = iWidth;
            itagRECT.top           = 0;
            itagRECT.bottom        = iHeight;
            iDisplayTransformation = new DisplayTransformationClass();
            iDisplayTransformation.VisibleBounds = iEnvelope;
            iDisplayTransformation.Bounds        = iEnvelope;
            iDisplayTransformation.set_DeviceFrame(ref itagRECT);
            iDisplayTransformation.Resolution = iGraphics.DpiX / 100000;
            iHDC = iGraphics.GetHdc();
            //获取Geometry;

            if (iSymbol is ESRI.ArcGIS.Display.IMarkerSymbol)
            {
                switch (iStyle)
                {
                case 0:
                    iPoint = new ESRI.ArcGIS.Geometry.Point();
                    iPoint.PutCoords(iWidth / 2, iHeight / 2);
                    iGeometry = iPoint;
                    break;

                default:
                    break;
                }
            }
            else
            {
                if (iSymbol is ESRI.ArcGIS.Display.ILineSymbol)
                {
                    iSegmentCollection = new ESRI.ArcGIS.Geometry.Path() as ISegmentCollection;
                    iPolyline          = new ESRI.ArcGIS.Geometry.Polyline() as IGeometryCollection;
                    switch (iStyle)
                    {
                    case 0:
                        iSegmentCollection.AddSegment(CreateLine(0, iHeight / 2, iWidth, iHeight / 2) as ISegment, ref Missing, ref Missing);

                        iPolyline.AddGeometry(iSegmentCollection as IGeometry, ref Missing, ref Missing);
                        iGeometry = iPolyline as IGeometry;
                        break;

                    case 1:
                        iSegmentCollection.AddSegment(CreateLine(0, iHeight / 4, iWidth / 4, 3 * iHeight / 4) as ISegment, ref Missing, ref Missing);
                        iSegmentCollection.AddSegment(CreateLine(iWidth / 4, 3 * iHeight / 4, 3 * iWidth / 4, iHeight / 4) as ISegment, ref Missing, ref Missing);
                        iSegmentCollection.AddSegment(CreateLine(3 * iWidth / 4, iHeight / 4, iWidth, 3 * iHeight / 4) as ISegment, ref Missing, ref Missing);
                        iPolyline.AddGeometry(iSegmentCollection as IGeometry, ref Missing, ref Missing);
                        iGeometry = iPolyline as IGeometry;
                        break;

                    default:
                        break;
                    }
                }
                else
                if (iSymbol is ESRI.ArcGIS.Display.IFillSymbol)
                {
                    iSegmentCollection = new ESRI.ArcGIS.Geometry.Ring() as ISegmentCollection;
                    iPolygon           = new ESRI.ArcGIS.Geometry.Polygon() as IGeometryCollection;
                    switch (iStyle)
                    {
                    case 0:
                        iSegmentCollection.AddSegment(CreateLine(5, iHeight - 5, iWidth - 6, iHeight - 5) as ISegment, ref Missing, ref Missing);
                        iSegmentCollection.AddSegment(CreateLine(iWidth - 6, iHeight - 5, iWidth - 6, 6) as ISegment, ref Missing, ref Missing);
                        iSegmentCollection.AddSegment(CreateLine(iWidth - 6, 6, 5, 6) as ISegment, ref Missing, ref Missing);
                        iRing = iSegmentCollection as IRing;
                        iRing.Close();
                        iPolygon.AddGeometry(iSegmentCollection as IGeometry, ref Missing, ref Missing);
                        iGeometry = iPolygon as IGeometry;
                        break;

                    default:
                        break;
                    }
                }
                else
                if (iSymbol is ESRI.ArcGIS.Display.ISimpleTextSymbol)
                {
                    switch (iStyle)
                    {
                    case 0:
                        iPoint = new ESRI.ArcGIS.Geometry.Point();
                        iPoint.PutCoords(iWidth / 2, iHeight / 2);
                        iGeometry = iPoint;
                        break;

                    default:
                        break;
                    }
                }
            }////////////////////////
            if (iGeometry == null)
            {
                MessageBox.Show("几何对象不符合!", "错误");
                return(null);
            }
            ISymbol pOutputSymbol = iSymbol as ISymbol;

            pOutputSymbol.SetupDC(iHDC.ToInt32(), iDisplayTransformation);
            pOutputSymbol.Draw(iGeometry);
            pOutputSymbol.ResetDC();
            iGraphics.ReleaseHdc(iHDC);
            iGraphics.Dispose();
            return(iBitmap);
        }
        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);
        }
Esempio n. 5
0
        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);
            }
        }