Exemplo n.º 1
0
        private void LabelHighWay(ILayer pLayer)
        {
            IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;

            if (pGeoFeatureLayer != null)
            {
                IAnnotateLayerPropertiesCollection panAnnotateLayerPropertiesCollection =
                    pGeoFeatureLayer.AnnotationProperties;
                panAnnotateLayerPropertiesCollection.Clear();


                IRgbColor pColor = new RgbColor();
                pColor.Red   = 0;
                pColor.Blue  = 0;
                pColor.Green = 0;
                IFormattedTextSymbol pTextSymbol = new TextSymbol();
                //ITextSymbol pTextSymbol = new TextSymbol();
                pTextSymbol.Background = CreateBalloonCallout() as ITextBackground;
                pTextSymbol.Color      = pColor;
                pTextSymbol.Size       = 10;
                pTextSymbol.Direction  = esriTextDirection.esriTDHorizontal;
                Font font = new System.Drawing.Font("宋体", 10);
                pTextSymbol.Font = ESRI.ArcGIS.ADF.COMSupport.OLE.GetIFontDispFromFont(font) as stdole.IFontDisp;
                IBasicOverposterLayerProperties properties = new BasicOverposterLayerProperties();
                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;

                switch (pFeatureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    properties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
                    break;

                case esriGeometryType.esriGeometryPoint:
                    properties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    properties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
                    break;
                }
                ILabelEngineLayerProperties2 properties2 =
                    new LabelEngineLayerProperties() as ILabelEngineLayerProperties2;
                if (properties2 != null)
                {
                    properties2.Expression = "[LXDM]";
                    properties2.Symbol     = pTextSymbol;
                    properties2.BasicOverposterLayerProperties = properties;

                    IAnnotateLayerProperties p = properties2 as IAnnotateLayerProperties;
//                    p.AnnotationMaximumScale = maxScale;
//                    p.AnnotationMinimumScale = minScale;
                    panAnnotateLayerPropertiesCollection.Add(p);
                }
            }
            if (pGeoFeatureLayer != null)
            {
                pGeoFeatureLayer.DisplayAnnotation = true;
            }
            _mxDocument.ActivatedView.Refresh();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 标注图层
        /// </summary>
        /// <param name="pLayer">需要标注的图层</param>
        /// <param name="fontSize">字体大小</param>
        /// <param name="labelField">标注字段</param>
        /// <param name="minScale">显示标注的最小比例尺</param>
        /// <param name="maxScale">显示标注的最大比例尺</param>
        /// 注意:一问最后两个参数是比例尺的分母,所有minScale的值应该比maxSacle的值大
        private void LabelLayer(ILayer pLayer, int fontSize, string labelField, double minScale, double maxScale)
        {
            IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;

            if (pGeoFeatureLayer != null)
            {
                IAnnotateLayerPropertiesCollection panAnnotateLayerPropertiesCollection =
                    pGeoFeatureLayer.AnnotationProperties;
                panAnnotateLayerPropertiesCollection.Clear();
                IRgbColor pColor = new RgbColor();
                pColor.Red   = 0;
                pColor.Blue  = 0;
                pColor.Green = 0;
                ITextSymbol pTextSymbol = new TextSymbol();
                pTextSymbol.Color = pColor;
                pTextSymbol.Size  = fontSize;
                Font font = new System.Drawing.Font("宋体", fontSize);
                pTextSymbol.Font = ESRI.ArcGIS.ADF.COMSupport.OLE.GetIFontDispFromFont(font) as stdole.IFontDisp;
                IBasicOverposterLayerProperties properties = new BasicOverposterLayerProperties();
                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;

                switch (pFeatureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    properties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
                    break;

                case esriGeometryType.esriGeometryPoint:
                    properties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    properties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
                    break;
                }
                ILabelEngineLayerProperties2 properties2 =
                    new LabelEngineLayerProperties() as ILabelEngineLayerProperties2;
                if (properties2 != null)
                {
                    properties2.Expression = "[" + labelField + "]";
                    properties2.Symbol     = pTextSymbol;
                    properties2.BasicOverposterLayerProperties = properties;

                    IAnnotateLayerProperties p = properties2 as IAnnotateLayerProperties;
                    p.AnnotationMaximumScale = maxScale;
                    p.AnnotationMinimumScale = minScale;
                    panAnnotateLayerPropertiesCollection.Add(p);
                }
            }

            if (pGeoFeatureLayer != null)
            {
                pGeoFeatureLayer.DisplayAnnotation = true;
            }
            _mxDocument.ActiveView.Refresh();
        }
Exemplo n.º 3
0
        private bool initializeGraphics()
        {
            try
            {
                // Initialize the DirectX drawing
                initialized = true;
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed           = true;
                presentParams.SwapEffect         = SwapEffect.Discard;
                presentParams.DeviceWindowHandle = this.Handle;

                device = new Device(0, DeviceType.Hardware,
                                    this,
                                    CreateFlags.SoftwareVertexProcessing,
                                    presentParams);

                // Set initial device parameters
                device.RenderState.CullMode = Cull.None;

                // Initialize the font
                Font systemFont = new System.Drawing.Font("Arial", 8f, FontStyle.Regular);
                drawingFont = new Microsoft.DirectX.Direct3D.Font(device, systemFont);

                // Set the timeseries device details
                foreach (oTimeseriesPlot plot in timeseriesPlots)
                {
                    plot.setDevice(device, drawingFont);
                }

                return(true);
            }
            catch (Exception ex)
            {
                initialized = false;

                //oConsole.printException(ex);
                return(false);
            }
        }
 public void DrawString(string s, System.Drawing.Font font, System.Drawing.SolidBrush brush, System.Drawing.RectangleF layoutRectangle)
 {
     _renderTarget2D.DrawText(s, _textFormatConverterAndCacher.Convert(font),
                              _rectangleFConverter.Convert(layoutRectangle), _solidColorBrushConverter.Convert(brush));
 }
Exemplo n.º 5
0
        private bool initializeGraphics()
        {
            try
            {
                lock(this)
                {
                    // Initialize the DirectX drawing
                    initialized = true;
                    lastInitializeTime = DateTime.Now;
                    PresentParameters presentParams = new PresentParameters();
                    presentParams.Windowed = true;
                    presentParams.SwapEffect = SwapEffect.Discard;
                    presentParams.DeviceWindowHandle = this.Handle;

                    device = new Device(0,
                                        DeviceType.Hardware,
                                        this,
                                        CreateFlags.SoftwareVertexProcessing,
                                        presentParams);

                    // Set initial device parameters
                    device.RenderState.FillMode = FillMode.WireFrame;
                    device.RenderState.CullMode = Cull.None;

                    // Initialize the font
                    Font systemFont = new System.Drawing.Font("Arial", 8f, FontStyle.Regular);
                    directxFont = new Microsoft.DirectX.Direct3D.Font(device, systemFont);
                }

                return true;
            }
            catch (Exception ex)
            {
                initialized = false;
                //oConsole.printException(ex);
                return false;
            }
        }
Exemplo n.º 6
0
        public static byte[] Watermark(byte[] image, string watermarkText)
        {
            var texts = watermarkText.Split(new string[] { "[@n@]" }, StringSplitOptions.RemoveEmptyEntries);

            var text1 = texts[0];
            var text2 = texts[1];
            var text3 = texts[2];

            using (var ms = new MemoryStream(image))
            {
                //Read the File into a Bitmap.
                using (Bitmap bmp = new Bitmap(ms))
                {
                    using (Graphics grp = Graphics.FromImage(bmp))
                    {
                        //Set the Color of the Watermark text.
                        Brush brush = new SolidBrush(Color.White);

                        //Set the Font and its size.
                        Font font = new System.Drawing.Font("Arial", 70, FontStyle.Bold, GraphicsUnit.Pixel);

                        //Determine the size of the Watermark text.
                        SizeF textSize1 = grp.MeasureString(text1, font);
                        SizeF textSize2 = grp.MeasureString(text2, font);
                        SizeF textSize3 = grp.MeasureString(text3, font);

                        //Prepare the background rectangle and draw
                        int bgRectWidth;
                        int bgRectHeight = (int)(textSize1.Height + textSize2.Height + textSize3.Height) + 20;
                        if (textSize2.Width >= textSize3.Width)
                        {
                            bgRectWidth = (int)textSize2.Width + 20;
                        }
                        else
                        {
                            bgRectWidth = (int)textSize3.Width + 20;
                        }
                        Brush rectBrush = new SolidBrush(Color.FromArgb(180, 219, 70, 153));
                        grp.FillRectangle(rectBrush, 0, (bmp.Height - bgRectHeight), bgRectWidth, bgRectHeight);

                        //Position the text and draw it on the image.
                        Point position1 = new Point(10, (bmp.Height - ((int)(textSize1.Height + textSize2.Height + textSize3.Height) + 10)));
                        grp.DrawString(text1, font, brush, position1);


                        Point position2 = new Point(10, (bmp.Height - ((int)(textSize2.Height + textSize3.Height) + 10)));
                        grp.DrawString(text2, font, brush, position2);

                        Point position3 = new Point(10, (bmp.Height - ((int)(textSize3.Height) + 10)));
                        grp.DrawString(text3, font, brush, position3);

                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            //Save the Watermarked image to the MemoryStream.
                            bmp.Save(memoryStream, ImageFormat.Jpeg);
                            memoryStream.Position = 0;

                            return(memoryStream.ToArray());
                        }
                    }
                }
            }
        }