Example #1
0
        private ITransformation CreateTransFromDC(int hDC, int lWidth, int lHeight)
        {
            // Calculate the parameters for the new transformation, based on the dimensions passed to this function.
            IEnvelope pBoundsEnvelope = new EnvelopeClass();

            pBoundsEnvelope.PutCoords(0, 0, lWidth, lHeight);
            tagRECT deviceRect;

            deviceRect.left   = 0;
            deviceRect.top    = 0;
            deviceRect.right  = lWidth;
            deviceRect.bottom = lHeight;

            //int dpi;
            //dpi = GetDeviceCaps(hDC, LOGPIXELSY);
            //if (dpi == 0) return null;
            // Create a new display transformation and set its properties.
            IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();


            pDisplayTransformation.VisibleBounds = pBoundsEnvelope;
            pDisplayTransformation.Bounds        = pBoundsEnvelope;
            pDisplayTransformation.set_DeviceFrame(ref deviceRect);
            pDisplayTransformation.Resolution = 300;
            return(pDisplayTransformation);
        }
        protected void DrawSymbol(int int_0, Rectangle rectangle_0, object object_0)
        {
            tagRECT grect;
            IDisplayTransformation transformation = new DisplayTransformationClass();
            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords((double)rectangle_0.Left, (double)rectangle_0.Top, (double)rectangle_0.Right,
                               (double)rectangle_0.Bottom);
            grect.left   = rectangle_0.Left;
            grect.right  = rectangle_0.Right;
            grect.bottom = rectangle_0.Bottom;
            grect.top    = rectangle_0.Top;
            transformation.set_DeviceFrame(ref grect);
            transformation.Bounds = envelope;
            ISymbol symbol = object_0 as ISymbol;

            if (symbol != null)
            {
                symbol.SetupDC(int_0, transformation);
                if (symbol is IMarkerSymbol)
                {
                    this.method_3((IMarkerSymbol)symbol, rectangle_0);
                }
                else if (symbol is ILineSymbol)
                {
                    this.method_4((ILineSymbol)symbol, rectangle_0);
                }
                else if (symbol is IFillSymbol)
                {
                    this.method_5((IFillSymbol)symbol, rectangle_0);
                }
                symbol.ResetDC();
            }
        }
Example #3
0
        /// <summary>
        /// 实现将Symbol转换为Bitmap
        /// </summary>
        /// <param name="Symbol">符号对象</param>
        /// <param name="Width">宽度值</param>
        /// <param name="Height">高度值</param>
        /// <returns>图像对象</returns>
        public static Bitmap PreviewItem(ISymbol Symbol, int Width, int Height)
        {
            Bitmap    bitmap    = new Bitmap(Width, Height);
            Graphics  mGraphics = Graphics.FromImage(bitmap);
            double    dpi       = mGraphics.DpiY;
            IEnvelope pEnvelope = new EnvelopeClass();

            pEnvelope.PutCoords(0, 0, bitmap.Width, bitmap.Height);
            tagRECT myRect = new tagRECT();

            myRect.bottom = bitmap.Height;
            myRect.left   = 0;
            myRect.right  = bitmap.Width;
            myRect.top    = 0;
            IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();

            pDisplayTransformation.VisibleBounds = pEnvelope;
            pDisplayTransformation.Bounds        = pEnvelope;
            pDisplayTransformation.set_DeviceFrame(ref myRect);
            pDisplayTransformation.Resolution = dpi;
            IntPtr pIntPtr = mGraphics.GetHdc();
            int    hDC     = pIntPtr.ToInt32();

            Symbol.SetupDC(hDC, pDisplayTransformation);
            IGeometry pGeometry = GetSymbolGeometry(Symbol, pEnvelope);

            Symbol.Draw(pGeometry);
            Symbol.ResetDC();
            mGraphics.ReleaseHdc(pIntPtr);
            mGraphics.Dispose();
            return(bitmap);
        }
        //设备句柄仿射变换
        private static ITransformation CreateTransformationFromHDC(IntPtr HDC, int width, int height)
        {
            IEnvelope env = new EnvelopeClass();

            env.PutCoords(0, 0, width, height);

            //目标矩形的大小
            tagRECT frame = new tagRECT();

            frame.left   = 0;
            frame.top    = 0;
            frame.right  = width;
            frame.bottom = height;

            double dpi  = Graphics.FromHdc(HDC).DpiY;//设备句柄的垂直分辨率
            long   lDpi = (long)dpi;

            if (lDpi == 0)
            {
                //XtraMessageBox.Show("获取设备比例尺失败!");

                return(null);
            }

            IDisplayTransformation dispTrans = new DisplayTransformationClass();

            dispTrans.Bounds        = env;
            dispTrans.VisibleBounds = env;
            dispTrans.set_DeviceFrame(ref frame);
            dispTrans.Resolution = dpi;

            return(dispTrans);
        }
Example #5
0
 public unsafe ITransformation CreateTransFromDC(int iWidth, int iHeight, long lDpi)
 {
     try
     {
         if (iWidth == 0)
         {
             return(null);
         }
         if (iHeight == 0)
         {
             return(null);
         }
         if (lDpi == 0L)
         {
             return(null);
         }
         IEnvelope envelope = null;
         envelope = new EnvelopeClass();
         envelope.PutCoords(0.0, 0.0, (double)iWidth, (double)iHeight);
         tagRECT grect = new tagRECT();
         IDisplayTransformation transformation = null;
         transformation = new DisplayTransformationClass();
         IDisplayTransformation transformation2 = transformation;
         transformation2.VisibleBounds = envelope;
         transformation2.Bounds        = envelope;
         transformation2.set_DeviceFrame(ref grect);
         transformation2.Resolution = lDpi;
         return(transformation);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.SymbolFun", "CreateTransFromDC", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(null);
     }
 }
Example #6
0
        private static ITransformation CreateTransFromDC(int hDC, double dblWidth, double dblHeight)
        {
            IEnvelope pBoundsEnvelope = new EnvelopeClass();

            pBoundsEnvelope.PutCoords(0, 0, dblWidth, dblHeight);

            tagRECT deviceRect = new tagRECT();

            deviceRect.left   = 0;
            deviceRect.top    = 0;
            deviceRect.right  = (int)dblWidth;
            deviceRect.bottom = (int)dblHeight;

            IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();

            pDisplayTransformation.VisibleBounds = pBoundsEnvelope;
            pDisplayTransformation.Bounds        = pBoundsEnvelope;
            pDisplayTransformation.set_DeviceFrame(ref deviceRect);
            pDisplayTransformation.Resolution = 96;

            return(pDisplayTransformation as ITransformation);
        }
Example #7
0
        /// <summary>
        /// Previews the item.
        /// </summary>
        /// <param name="Symbol">The symbol.</param>
        /// <param name="Width">The width.</param>
        /// <param name="Height">The height.</param>
        /// <returns>System.Drawing.Bitmap.</returns>
        public static System.Drawing.Bitmap PreviewItem(ISymbol Symbol, int Width, int Height)
        {
            if (Symbol == null)
            {
                return(null);
            }
            System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(Width, Height);
            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            double    resolution = (double)graphics.DpiY;
            IEnvelope envelope   = new EnvelopeClass();

            envelope.PutCoords(0.0, 0.0, (double)bitmap.Width, (double)bitmap.Height);
            tagRECT tagRECT = default(tagRECT);

            tagRECT.bottom = bitmap.Height;
            tagRECT.left   = 0;
            tagRECT.right  = bitmap.Width;
            tagRECT.top    = 0;
            IDisplayTransformation displayTransformation = new DisplayTransformationClass();

            displayTransformation.VisibleBounds = envelope;
            displayTransformation.Bounds        = envelope;
            displayTransformation.set_DeviceFrame(ref tagRECT);
            displayTransformation.Resolution = resolution;
            System.IntPtr hdc = graphics.GetHdc();
            int           hDC = hdc.ToInt32();

            Symbol.SetupDC(hDC, displayTransformation);
            IGeometry symbolGeometry = CommonAPI.GetSymbolGeometry(Symbol, envelope);

            Symbol.Draw(symbolGeometry);
            Symbol.ResetDC();
            graphics.ReleaseHdc(hdc);
            graphics.Dispose();
            return(bitmap);
        }
Example #8
0
        private ITransformation getTransformation(PictureBox picTarget)
        {
            RECT boundsRect;

            GetWindowRect(picTarget.Handle.ToInt32(), out boundsRect);
            int lWidth  = boundsRect.Right - boundsRect.Left;
            int lHeight = boundsRect.Bottom - boundsRect.Top;

            IDisplayTransformation pDispTrans = new DisplayTransformationClass();
            IEnvelope pBounds = new EnvelopeClass();

            pBounds.PutCoords(picTarget.Left, picTarget.Top, picTarget.Right, picTarget.Bottom);
            //pBounds.PutCoords(0, 0, lHeight, lWidth);
            pDispTrans.VisibleBounds = pBounds;
            pDispTrans.Bounds        = pBounds;

            tagRECT deviceRect;

            deviceRect.left   = 0;
            deviceRect.top    = 0;
            deviceRect.right  = lWidth;
            deviceRect.bottom = lHeight;
            pDispTrans.set_DeviceFrame(ref deviceRect);


            IntPtr lHDC = picTarget.Handle;
            int    lDpi = GetDeviceCaps(lHDC, LOGPIXELSY);

            if (lDpi == 0)
            {
                lDpi = 300;
            }

            pDispTrans.Resolution = lDpi;
            return(pDispTrans);
        }
Example #9
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);
        }
Example #10
0
 protected void DrawSymbol(int int_3, System.Drawing.Rectangle rectangle_0, object object_0)
 {
     if (object_0 != null)
     {
         IDisplayTransformation displayTransformation = new DisplayTransformationClass();
         IEnvelope envelope = new EnvelopeClass();
         envelope.PutCoords((double)rectangle_0.Left, (double)rectangle_0.Top, (double)rectangle_0.Right,
                            (double)rectangle_0.Bottom);
         tagRECT tagRECT;
         tagRECT.left   = rectangle_0.Left;
         tagRECT.right  = rectangle_0.Right;
         tagRECT.bottom = rectangle_0.Bottom;
         tagRECT.top    = rectangle_0.Top;
         displayTransformation.set_DeviceFrame(ref tagRECT);
         displayTransformation.Bounds         = envelope;
         displayTransformation.Resolution     = 96.0;
         displayTransformation.ReferenceScale = 1.0;
         displayTransformation.ScaleRatio     = 1.0;
         ISymbol symbol;
         if (object_0 is ISymbol)
         {
             symbol = (ISymbol)object_0;
         }
         else if (object_0 is IColorRamp)
         {
             IGradientFillSymbol gradientFillSymbol = new GradientFillSymbolClass();
             ILineSymbol         outline            = gradientFillSymbol.Outline;
             outline.Width = 0.0;
             gradientFillSymbol.Outline            = outline;
             gradientFillSymbol.ColorRamp          = (IColorRamp)object_0;
             gradientFillSymbol.GradientAngle      = 180.0;
             gradientFillSymbol.GradientPercentage = 1.0;
             gradientFillSymbol.IntervalCount      = 100;
             gradientFillSymbol.Style = esriGradientFillStyle.esriGFSLinear;
             symbol = (ISymbol)gradientFillSymbol;
         }
         else if (object_0 is IColor)
         {
             symbol = (ISymbol) new ColorSymbolClass
             {
                 Color = (IColor)object_0
             };
         }
         else if (object_0 is IAreaPatch)
         {
             symbol = new SimpleFillSymbolClass();
             IRgbColor rgbColor = new RgbColorClass();
             rgbColor.Red   = 227;
             rgbColor.Green = 236;
             rgbColor.Blue  = 19;
             ((IFillSymbol)symbol).Color = rgbColor;
         }
         else if (object_0 is ILinePatch)
         {
             symbol = new SimpleLineSymbolClass();
         }
         else
         {
             if (object_0 is INorthArrow)
             {
                 IDisplay display = new ScreenDisplayClass();
                 display.StartDrawing(int_3, 0);
                 display.DisplayTransformation = displayTransformation;
                 ((IMapSurround)object_0).Draw(display, null, envelope);
                 display.FinishDrawing();
                 ((IMapSurround)object_0).Refresh();
                 return;
             }
             if (object_0 is IMapSurround)
             {
                 IDisplay display = new ScreenDisplayClass();
                 display.StartDrawing(int_3, 0);
                 display.DisplayTransformation = displayTransformation;
                 IEnvelope envelope2 = new EnvelopeClass();
                 envelope2.PutCoords((double)(rectangle_0.Left + 5), (double)(rectangle_0.Top + 5),
                                     (double)(rectangle_0.Right - 5), (double)(rectangle_0.Bottom - 5));
                 ((IMapSurround)object_0).QueryBounds(display, envelope, envelope2);
                 bool flag;
                 ((IMapSurround)object_0).FitToBounds(display, envelope2, out flag);
                 ((IMapSurround)object_0).Draw(display, null, envelope2);
                 display.FinishDrawing();
                 ((IMapSurround)object_0).Refresh();
                 return;
             }
             if (object_0 is IBackground)
             {
                 IDisplay display = new ScreenDisplayClass();
                 display.StartDrawing(int_3, 0);
                 display.DisplayTransformation = displayTransformation;
                 IGeometry geometry = ((IBackground)object_0).GetGeometry(display, envelope);
                 ((IBackground)object_0).Draw(display, geometry);
                 display.FinishDrawing();
                 return;
             }
             if (object_0 is IShadow)
             {
                 IDisplay display = new ScreenDisplayClass();
                 display.StartDrawing(int_3, 0);
                 display.DisplayTransformation = displayTransformation;
                 double horizontalSpacing = ((IShadow)object_0).HorizontalSpacing;
                 double verticalSpacing   = ((IShadow)object_0).VerticalSpacing;
                 ((IShadow)object_0).HorizontalSpacing = 0.0;
                 ((IShadow)object_0).VerticalSpacing   = 0.0;
                 IGeometry geometry = ((IShadow)object_0).GetGeometry(display, envelope);
                 ((IShadow)object_0).Draw(display, geometry);
                 ((IShadow)object_0).HorizontalSpacing = horizontalSpacing;
                 ((IShadow)object_0).VerticalSpacing   = verticalSpacing;
                 display.FinishDrawing();
                 return;
             }
             if (object_0 is IBorder)
             {
                 IDisplay display = new ScreenDisplayClass();
                 display.StartDrawing(int_3, 0);
                 display.DisplayTransformation = displayTransformation;
                 IPointCollection pointCollection = new PolylineClass();
                 object           value           = System.Reflection.Missing.Value;
                 IPoint           point           = new PointClass();
                 point.PutCoords((double)(rectangle_0.X + 4), (double)rectangle_0.Top);
                 pointCollection.AddPoint(point, ref value, ref value);
                 point.PutCoords((double)(rectangle_0.X + 4), (double)rectangle_0.Bottom);
                 pointCollection.AddPoint(point, ref value, ref value);
                 point.PutCoords((double)(rectangle_0.Right - 4), (double)rectangle_0.Bottom);
                 pointCollection.AddPoint(point, ref value, ref value);
                 IGeometry geometry = ((IBorder)object_0).GetGeometry(display, (IGeometry)pointCollection);
                 ((IBorder)object_0).Draw(display, geometry);
                 display.FinishDrawing();
                 return;
             }
             return;
         }
         if (symbol is IPictureFillSymbol || symbol is IPictureLineSymbol)
         {
             symbol.SetupDC(int_3, null);
         }
         else
         {
             symbol.SetupDC(int_3, displayTransformation);
         }
         if (object_0 is IPatch)
         {
             this.method_3(symbol, (IPatch)object_0, rectangle_0);
         }
         else if (symbol is IMarkerSymbol)
         {
             this.method_2((IMarkerSymbol)symbol, rectangle_0);
         }
         else if (symbol is ILineSymbol)
         {
             this.method_4((ILineSymbol)symbol, rectangle_0);
         }
         else if (symbol is IFillSymbol)
         {
             this.method_5((IFillSymbol)symbol, rectangle_0);
         }
         else if (symbol is ITextSymbol)
         {
             this.method_7((ITextSymbol)symbol, rectangle_0);
         }
         symbol.ResetDC();
     }
 }
Example #11
0
 protected void DrawSymbol(int int_3, Rectangle rectangle_0, object object_0)
 {
     if (object_0 != null)
     {
         tagRECT grect;
         ISymbol symbol;
         IDisplayTransformation transformation = new DisplayTransformationClass();
         IEnvelope bounds = new EnvelopeClass();
         bounds.PutCoords((double)rectangle_0.Left, (double)rectangle_0.Top, (double)rectangle_0.Right,
                          (double)rectangle_0.Bottom);
         grect.left   = rectangle_0.Left;
         grect.right  = rectangle_0.Right;
         grect.bottom = rectangle_0.Bottom;
         grect.top    = rectangle_0.Top;
         transformation.set_DeviceFrame(ref grect);
         transformation.Bounds         = bounds;
         transformation.Resolution     = 96.0;
         transformation.ReferenceScale = 1.0;
         transformation.ScaleRatio     = 1.0;
         if (object_0 is ISymbol)
         {
             symbol = object_0 as ISymbol;
         }
         else if (object_0 is IColorRamp)
         {
             IGradientFillSymbol symbol2 = new GradientFillSymbolClass();
             ILineSymbol         outline = symbol2.Outline;
             outline.Width              = 0.0;
             symbol2.Outline            = outline;
             symbol2.ColorRamp          = object_0 as IColorRamp;
             symbol2.GradientAngle      = 180.0;
             symbol2.GradientPercentage = 1.0;
             symbol2.IntervalCount      = 100;
             symbol2.Style              = esriGradientFillStyle.esriGFSLinear;
             symbol = (ISymbol)symbol2;
         }
         else if (object_0 is IColor)
         {
             IColorSymbol symbol4 = new ColorSymbolClass
             {
                 Color = object_0 as IColor
             };
             symbol = (ISymbol)symbol4;
         }
         else if (object_0 is IAreaPatch)
         {
             symbol = new SimpleFillSymbolClass();
             IRgbColor color = new RgbColorClass
             {
                 Red   = 227,
                 Green = 236,
                 Blue  = 19
             };
             ((IFillSymbol)symbol).Color = color;
         }
         else
         {
             if (!(object_0 is ILinePatch))
             {
                 IDisplay display;
                 if (object_0 is INorthArrow)
                 {
                     display = new ScreenDisplayClass();
                     display.StartDrawing(int_3, 0);
                     display.DisplayTransformation = transformation;
                     ((IMapSurround)object_0).Draw(display, null, bounds);
                     display.FinishDrawing();
                     ((IMapSurround)object_0).Refresh();
                 }
                 else if (object_0 is IMapSurround)
                 {
                     bool flag;
                     display = new ScreenDisplayClass();
                     display.StartDrawing(int_3, 0);
                     display.DisplayTransformation = transformation;
                     IEnvelope newBounds = new EnvelopeClass();
                     newBounds.PutCoords((double)(rectangle_0.Left + 5), (double)(rectangle_0.Top + 5),
                                         (double)(rectangle_0.Right - 5), (double)(rectangle_0.Bottom - 5));
                     ((IMapSurround)object_0).QueryBounds(display, bounds, newBounds);
                     ((IMapSurround)object_0).FitToBounds(display, newBounds, out flag);
                     ((IMapSurround)object_0).Draw(display, null, newBounds);
                     display.FinishDrawing();
                     ((IMapSurround)object_0).Refresh();
                 }
                 else
                 {
                     IGeometry geometry;
                     if (object_0 is IBackground)
                     {
                         display = new ScreenDisplayClass();
                         display.StartDrawing(int_3, 0);
                         display.DisplayTransformation = transformation;
                         geometry = ((IBackground)object_0).GetGeometry(display, bounds);
                         ((IBackground)object_0).Draw(display, geometry);
                         display.FinishDrawing();
                     }
                     else if (object_0 is IShadow)
                     {
                         display = new ScreenDisplayClass();
                         display.StartDrawing(int_3, 0);
                         display.DisplayTransformation = transformation;
                         double horizontalSpacing = ((IShadow)object_0).HorizontalSpacing;
                         double verticalSpacing   = ((IShadow)object_0).VerticalSpacing;
                         ((IShadow)object_0).HorizontalSpacing = 0.0;
                         ((IShadow)object_0).VerticalSpacing   = 0.0;
                         geometry = ((IShadow)object_0).GetGeometry(display, bounds);
                         ((IShadow)object_0).Draw(display, geometry);
                         ((IShadow)object_0).HorizontalSpacing = horizontalSpacing;
                         ((IShadow)object_0).VerticalSpacing   = verticalSpacing;
                         display.FinishDrawing();
                     }
                     else if (object_0 is IBorder)
                     {
                         display = new ScreenDisplayClass();
                         display.StartDrawing(int_3, 0);
                         display.DisplayTransformation = transformation;
                         IPointCollection points  = new PolylineClass();
                         object           before  = Missing.Value;
                         IPoint           inPoint = new PointClass();
                         inPoint.PutCoords((double)(rectangle_0.X + 4), (double)rectangle_0.Top);
                         points.AddPoint(inPoint, ref before, ref before);
                         inPoint.PutCoords((double)(rectangle_0.X + 4), (double)rectangle_0.Bottom);
                         points.AddPoint(inPoint, ref before, ref before);
                         inPoint.PutCoords((double)(rectangle_0.Right - 4), (double)rectangle_0.Bottom);
                         points.AddPoint(inPoint, ref before, ref before);
                         geometry = ((IBorder)object_0).GetGeometry(display, (IGeometry)points);
                         ((IBorder)object_0).Draw(display, geometry);
                         display.FinishDrawing();
                     }
                 }
                 return;
             }
             symbol = new SimpleLineSymbolClass();
         }
         if ((symbol is IPictureFillSymbol) || (symbol is IPictureLineSymbol))
         {
             symbol.SetupDC(int_3, null);
         }
         else
         {
             symbol.SetupDC(int_3, transformation);
         }
         if (object_0 is IPatch)
         {
             this.method_3(symbol, (IPatch)object_0, rectangle_0);
         }
         else if (symbol is IMarkerSymbol)
         {
             this.method_2((IMarkerSymbol)symbol, rectangle_0);
         }
         else if (symbol is ILineSymbol)
         {
             this.method_4((ILineSymbol)symbol, rectangle_0);
         }
         else if (symbol is IFillSymbol)
         {
             this.method_5((IFillSymbol)symbol, rectangle_0);
         }
         else if (symbol is ITextSymbol)
         {
             this.method_7((ITextSymbol)symbol, rectangle_0);
         }
         symbol.ResetDC();
     }
 }
        private ITransformation getTransformation(PictureBox picTarget)
        {
            RECT boundsRect;
            GetWindowRect(picTarget.Handle.ToInt32(), out boundsRect);
            int lWidth = boundsRect.Right - boundsRect.Left;
            int lHeight = boundsRect.Bottom - boundsRect.Top;

            IDisplayTransformation pDispTrans = new DisplayTransformationClass();
            IEnvelope pBounds = new EnvelopeClass();
            pBounds.PutCoords(picTarget.Left, picTarget.Top, picTarget.Right, picTarget.Bottom);
            //pBounds.PutCoords(0, 0, lHeight, lWidth);
            pDispTrans.VisibleBounds = pBounds;
            pDispTrans.Bounds = pBounds;

            tagRECT deviceRect;
            deviceRect.left = 0;
            deviceRect.top = 0;
            deviceRect.right = lWidth;
            deviceRect.bottom = lHeight;
            pDispTrans.set_DeviceFrame(ref deviceRect);

            IntPtr lHDC = picTarget.Handle;
            int lDpi = GetDeviceCaps(lHDC, LOGPIXELSY);
            if (lDpi == 0) lDpi = 300;

            pDispTrans.Resolution = lDpi;
            return pDispTrans;
        }
        private ITransformation CreateTransFromDC(int hDC, int lWidth, int lHeight)
        {
            // Calculate the parameters for the new transformation, based on the dimensions passed to this function.
            IEnvelope pBoundsEnvelope = new EnvelopeClass();
            pBoundsEnvelope.PutCoords(0, 0, lWidth, lHeight);
            tagRECT deviceRect;

            deviceRect.left = 0;
            deviceRect.top = 0;
            deviceRect.right = lWidth;
            deviceRect.bottom = lHeight;

            //int dpi;
            //dpi = GetDeviceCaps(hDC, LOGPIXELSY);
            //if (dpi == 0) return null;
            // Create a new display transformation and set its properties.
            IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();

            pDisplayTransformation.VisibleBounds = pBoundsEnvelope;
            pDisplayTransformation.Bounds = pBoundsEnvelope;
            pDisplayTransformation.set_DeviceFrame(ref deviceRect);
            pDisplayTransformation.Resolution = 300;
            return pDisplayTransformation;
        }
Example #14
0
        /// <summary>
        /// 将符号转化为图片
        /// </summary>
        /// <param name="pSymbol">符号</param>
        /// <param name="width">图片宽度</param>
        /// <param name="height">图片高度</param>
        /// <returns>图片</returns>
        public static Image Symbol2Picture(ISymbol pSymbol, int width, int height)
        {
            if (pSymbol == null || width < 1 || height < 1)
            {
                return(null);
            }

            //根据高宽创建图象
            Bitmap   bmp    = new Bitmap(width, height);
            Graphics gImage = Graphics.FromImage(bmp);

            gImage.Clear(Color.White);
            double dpi = gImage.DpiX;

            ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            pEnvelope.PutCoords(0, 0, (double)bmp.Width, (double)bmp.Height);

            tagRECT deviceRect;

            deviceRect.left   = 0;
            deviceRect.right  = bmp.Width;
            deviceRect.top    = 0;
            deviceRect.bottom = bmp.Height;

            IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();

            pDisplayTransformation.VisibleBounds = pEnvelope;
            pDisplayTransformation.Bounds        = pEnvelope;
            pDisplayTransformation.set_DeviceFrame(ref deviceRect);
            pDisplayTransformation.Resolution = dpi;

            System.IntPtr hdc = new IntPtr();
            hdc = gImage.GetHdc();

            ESRI.ArcGIS.Geometry.IGeometry pGeo = CreateSymShape(pSymbol, pEnvelope);

            //将符号的形状绘制到图象中
            pSymbol.SetupDC((int)hdc, pDisplayTransformation);
            pSymbol.Draw(pGeo);
            pSymbol.ResetDC();
            gImage.ReleaseHdc(hdc);
            gImage.Dispose();
            return(bmp);

            ////IStyleGalleryClass pStyleClass = null;
            ////if (pSymbol is IMarkerSymbol)
            ////    pStyleClass = new ESRI.ArcGIS.Carto.MarkerSymbolStyleGalleryClassClass();
            ////else if (pSymbol is ILineSymbol)
            ////    pStyleClass = new ESRI.ArcGIS.Carto.LineSymbolStyleGalleryClassClass();
            ////else if (pSymbol is IFillSymbol)
            ////    pStyleClass = new ESRI.ArcGIS.Carto.FillSymbolStyleGalleryClassClass();
            ////else
            ////    return null;

            //IStyleGalleryItem pStyleItem = new ServerStyleGalleryItemClass();
            //pStyleItem.Name = "tempSymbol";
            //pStyleItem.Item = pSymbol;

            //Bitmap bitmap = new Bitmap(width, height);
            //System.Drawing.Graphics pGraphics = System.Drawing.Graphics.FromImage(bitmap);
            //tagRECT rect = new tagRECT();
            //rect.right = bitmap.Width;
            //rect.bottom = bitmap.Height;
            ////生成预览
            //IntPtr hdc = new IntPtr();
            //hdc = pGraphics.GetHdc();

            //pStyleClass.Preview(pStyleItem, hdc.ToInt32(), ref rect);

            //pGraphics.ReleaseHdc(hdc);
            //pGraphics.Dispose();

            //return bitmap;
        }