Пример #1
0
        public async Task <ImageObj> GetImagesAsync(string tag, int page = 1)
        {
            var flickrUrl = $"https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key={key}&tags={tag}&page={page}&format=json&nojsoncallback=1";

            var json = await httpClient.GetStringAsync(flickrUrl);

            var flickr = JsonConvert.DeserializeObject <FlickrJson>(json);

            var imageObj = new ImageObj();

            if (flickr.Stat == "ok")
            {
                imageObj.Page   = flickr.Photos.Page;
                imageObj.Pages  = flickr.Photos.Pages;
                imageObj.Total  = int.TryParse(flickr.Photos.Total, out var total) ? total : 0;
                imageObj.images = new List <string>();

                foreach (var photo in flickr.Photos.Photo)
                {
                    imageObj.images.Add(GetUrlFromPhoto(photo));
                }
            }
            else
            {
                // Something went wrong, return error message
                imageObj.ErrorMessage = !string.IsNullOrEmpty(flickr.Message) ? flickr.Message : "Something went wrong with Flickr API";
            }

            return(imageObj);
        }
Пример #2
0
        public virtual bool Render_Draw(ImageObj img = null)
        {
            double pixResoultion = 0.0005;

            //提取数据信息
            if (_GdalRead == null)
            {
                return(false);
            }
            IMetadataR pMetadata = (IMetadataR)_GdalRead.GetMetadata();

            if (pMetadata == null)
            {
                return(false);
            }

            pMetadata.Cols = (int)Math.Floor((_Metadata.MaxX - _Metadata.MinX) / pixResoultion);
            pMetadata.Rows = (int)Math.Floor((_Metadata.MaxY - _Metadata.MinY) / pixResoultion);

            //绘图
            if (img == null)
            {
                if (_Image == null)
                {
                    _Image = new ImageObj(pMetadata.Cols, pMetadata.Rows);
                }
                else
                {
                    _Image = img;
                }
            }
            _Metadata = pMetadata;
            return(true);
        }
Пример #3
0
        public virtual bool Create_Legend(string path, string name)
        {
            //提取legendInfo
            string[] colors     = null;
            string[] titlesInfo = null;
            this.InitRenderInfos("titlesInfo", ref titlesInfo, "legendInfo");
            this.InitRenderInfos("colorsInfo", ref colors, "legendInfo");

            //计算图例区间
            ImageColor pBackground = new ImageColor("#192734");
            int        fontSize = 18, titleH = 46;
            int        nOffset_x = 10, nOffset_y = 10, nStepX = 10, nStepY = 10;
            int        nW_legend = 60, nH_legend = 20;
            int        nH   = colors.Length * (nH_legend + nStepY) - nStepY + nOffset_y * 2 + nStepX + titleH;
            int        nW   = nW_legend + nOffset_x * 2 + nW_legend + nStepY * 2;
            int        nNum = colors.Length - 1;

            string pathLengend = Directory.GetCurrentDirectory() + "/ModelData/Image/GIS/Legend.png";

            _Image_legend = new ImageObj();
            _Image_legend.Create(pathLengend, nW, nH);
            for (int i = 0; i < colors.Length; i++)
            {
                _Image_legend.DrawPolygon(nOffset_x, nOffset_y + titleH + i * (nH_legend + nStepY), _ImageColors[nNum - i].Color, 1, nW_legend, nH_legend, false);
                _Image_legend.DrawText(nOffset_x + nW_legend + nStepX, nOffset_y + titleH + i * (nH_legend + nStepY), _ImageColors[nNum - i].Color, titlesInfo[i], null, 11, true, false, Alignment.Near, Alignment.Near);
            }
            _Image_legend.DrawText(nW / 2, nOffset_y, pBackground.Color, "图例", null, fontSize, true, false, Alignment.Center, Alignment.Near);
            if (name + "" != "")
            {
                _Image_legend.Name = name;
            }
            return(_Image_legend.Save(path));
        }
Пример #4
0
        private void SetImageData(ImageObj images)
        {
            if (images == null)
            {
                Images       = null;
                ErrorMessage = " ";
            }
            else if (!string.IsNullOrEmpty(images.ErrorMessage))
            {
                Images       = null;
                ErrorMessage = images.ErrorMessage;
            }
            else if (images.images != null)
            {
                ErrorMessage = "";

                _lastPage = images.Pages;
                NoOfPage  = $"Page {images.Page} of {images.Pages}";
                Images    = new ObservableCollection <string>(images.images);
            }
            else
            {
                Images = null;
            }

            NotifyProperties();
            SpinnerActive = false;
        }
Пример #5
0
        public override bool Render_Draw(ImageObj img = null)
        {
            //提取元数据、初始绘图对象
            if (base.Render_Draw(img) == false)
            {
                return(false);
            }
            IMetadataR pMetadata = (IMetadataR)_Metadata;

            if (pMetadata == null)
            {
                return(false);
            }

            //循环绘制
            ImageColor pColor = null;

            float[] datas   = null;
            bool    bResult = _GdalReadR.GetDatas(1, ref datas);

            for (int i = 0; i < pMetadata.Rows; i++)
            {
                for (int j = 0; j < pMetadata.Cols; j++)
                {
                    pColor = GetColor(datas[i * pMetadata.Cols + j]);
                    //Task.Run(() => _Image.Draw(i, j, pColor.Color));
                    _Image.Draw(j, i, pColor.Color);
                }
                ;
                //Task.Run(() => Draws(pMetadata, i, datas));
            }
            return(bResult);
        }
Пример #6
0
        public override bool Render(ImageObj img = null)
        {
            DateTime dtStart = DateTime.Now;
            bool     bResult = base.Render(img);

            bResult = bResult & Render_Draw(img);

            DateTime dtEnd = DateTime.Now;

            Console.WriteLine(string.Format("{0}渲染耗时 {1}s!", this.RenderType, (dtEnd - dtStart).TotalSeconds));
            return(true);
        }
Пример #7
0
        public override bool Render(ImageObj img = null)
        {
            //初始颜色对象集
            for (int i = 0; i < _Colors.Length; i++)
            {
                _ImageColors.Add(new ImageColor(_Colors[i]));
            }

            _Result             = new JObject();
            _Result["params"]   = _Params;
            _Result["renderer"] = new JObject();
            return(true);
        }
Пример #8
0
        public virtual bool Render(ImageObj img = null)
        {
            //初始颜色对象集
            if (_Colors == null)
            {
                return(true);
            }
            for (int i = 0; i < _Colors.Length; i++)
            {
                _ImageColors.Add(new ImageColor(_Colors[i]));
            }

            _Image              = img;
            _Result             = new JObject();
            _Result["params"]   = _Params;
            _Result["renderer"] = new JObject();
            return(true);
        }
Пример #9
0
        protected override void MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                if (m_EditorMode == EditorMode.Lasso)
                {
                    if (m_Canvas.BackgroundImage != null)
                    {
                        Rectangle rec = m_Canvas.RectangleToClient(
                            Rectangle.FromLTRB(m_StartPoint.X,  //- m_Canvas.HorizontalScroll.Value,
                                               m_StartPoint.Y,  //- m_Canvas.VerticalScroll.Value,
                                               m_CurrentPoint.X, m_CurrentPoint.Y));

                        if (rec.Width > 0 && rec.Height > 0)
                        {
                            ImageObj obj = new ImageObj(m_Canvas.BackgroundImage as Bitmap, rec);
                            m_Canvas.m_ImgList.Add(obj);
                            return;
                        }
                    }
                }
                else if (m_EditorMode == EditorMode.Edit)
                {
                    foreach (var obj in m_Canvas.m_SelectedImgList)
                    {
                        switch (obj.Selection)
                        {
                        case SelectionType.Resize:
                            m_Canvas.Invalidate(obj.Rect.InflateEx());
                            return;

                        case SelectionType.Rotate:
                            m_Angle = float.NaN;
                            break;
                        }
                    }
                }
                m_Canvas.Invalidate();
            }
            finally
            {
                m_EditorMode = EditorMode.None;
            }
        }
Пример #10
0
        public override bool Render_Draw(ImageObj img = null)
        {
            //提取元数据、初始绘图对象
            if (base.Render_Draw(img) == false)
            {
                return(false);
            }
            if (_Metadata == null)
            {
                return(false);
            }

            //循环绘制
            for (int i = 0; i < _GdalRead.FeatureCount; i++)
            {
                Geometry pGeometry = _GdalRead.GetGeometry(i);
            }
            return(true);
        }
Пример #11
0
        public override bool Render_Draw(ImageObj img = null)
        {
            //提取数据信息
            if (_GdalReadR == null)
            {
                return(false);
            }
            IMetadataR pMetadata = _GdalReadR.GetMetadataR(1);

            //绘图
            if (img == null)
            {
                if (_Image == null)
                {
                    _Image = new ImageObj(pMetadata.Cols, pMetadata.Rows);
                }
                else
                {
                    _Image = img;
                }
            }
            _Metadata = pMetadata;
            return(true);
        }
Пример #12
0
        public virtual ImageObj Create_Scale(float length = 10000, string unit = "km")
        {
            string   pathScale = Directory.GetCurrentDirectory() + "/ModelData/Image/GIS/Scale.png";
            ImageObj imgScale  = new ImageObj(100, 100);

            //计算图例区间
            double W          = _Metadata.MaxX - _Metadata.MinX;
            double ratioScale = W * 111000 / _Image.Width;
            int    nPixels    = (int)(length / ratioScale);

            var font = imgScale.defaultFont(11, "");
            var sizeText = imgScale.Graphic.MeasureString(unit, font);
            int nOffset_x = 10, nOffset_y = 8;
            int nW = nPixels + nOffset_x * 3 + (int)sizeText.Width;
            int nH = nOffset_y * 3 + (int)sizeText.Height;

            imgScale.Create(pathScale, nPixels, nOffset_y);

            //绘制
            ImageColor pColor = new ImageColor("#192734");
            ImageObj   img    = new ImageObj(nW, nH);

            img.DrawImage(nOffset_x, nOffset_y + (int)sizeText.Height, imgScale, 1);

            int hUnit = nOffset_y + (int)(sizeText.Height - imgScale.Height / 2 - 1);

            img.DrawText(nOffset_x * 2 + nPixels, hUnit, pColor.Color, unit, font, 0, true, false, Alignment.Near, Alignment.Near);

            int hDis = (int)(sizeText.Height / 2 - 1);

            img.DrawText(nOffset_x, hDis, pColor.Color, "0", font, 0, true, false, Alignment.Center, Alignment.Near);
            img.DrawText(nOffset_x + nPixels / 2 / 2, hDis, pColor.Color, (length / 1000 / 2 / 2).ToString(), font, 0, true, false, Alignment.Center, Alignment.Near);
            img.DrawText(nOffset_x + nPixels / 2, hDis, pColor.Color, (length / 1000 / 2).ToString(), font, 0, true, false, Alignment.Center, Alignment.Near);
            img.DrawText(nOffset_x + nPixels, hDis, pColor.Color, (length / 1000).ToString(), font, 0, true, false, Alignment.Center, Alignment.Near);
            return(img);
        }
Пример #13
0
        /// <summary>
        /// Copy the properties of this <see cref="ZedGraphWebImageObj"/> to the specified
        /// <see cref="ZedGraph.ImageObj"/> object.
        /// </summary>
        /// <param name="item">The destination <see cref="ZedGraph.ImageObj"/> object</param>
        internal void CopyTo( ImageObj item )
        {
            base.CopyTo( item );
            item.IsScaled = this.IsScaled;

            item.Image = null;
            try
            {
                if ( ( this.ImageUrl != null ) && ( this.ImageUrl != string.Empty ) )
                {
                    string path = System.AppDomain.CurrentDomain.BaseDirectory;
                    path = System.IO.Path.Combine( path, this.ImageUrl );
                    item.Image = Image.FromFile( path );
                }
            }
            catch ( Exception )
            {
                //TODO: deal with failure?
            }
        }
Пример #14
0
 /// <summary>
 /// Add the <see cref="ZedGraphWebGraphObj" /> objects defined in the webcontrol to
 /// the <see cref="GraphPane" /> as <see cref="GraphObj" /> objects.
 /// </summary>
 /// <param name="g">The <see cref="Graphics" /> instance of interest.</param>
 /// <param name="pane">The <see cref="GraphPane" /> object to receive the
 /// <see cref="GraphObj" /> objects.</param>
 protected void AddWebGraphItems(IGraphics g, GraphPane pane)
 {
     try
     {
         ZedGraphWebGraphObj draw;
         for (int i = 0; i < GraphObjList.Count; i++)
         {
             draw = GraphObjList[i];
             if (draw is ZedGraphWebTextObj)
             {
                 var item = (ZedGraphWebTextObj) draw;
                 var x = new TextObj();
                 item.CopyTo(x);
                 pane.GraphObjList.Add(x);
             }
             else if (draw is ZedGraphWebArrowObj)
             {
                 var item = (ZedGraphWebArrowObj) draw;
                 var x = new ArrowObj();
                 item.CopyTo(x);
                 pane.GraphObjList.Add(x);
             }
             else if (draw is ZedGraphWebImageObj)
             {
                 var item = (ZedGraphWebImageObj) draw;
                 var x = new ImageObj();
                 item.CopyTo(x);
                 pane.GraphObjList.Add(x);
             }
             else if (draw is ZedGraphWebBoxObj)
             {
                 var item = (ZedGraphWebBoxObj) draw;
                 var x = new BoxObj();
                 item.CopyTo(x);
                 pane.GraphObjList.Add(x);
             }
             else if (draw is ZedGraphWebEllipseObj)
             {
                 var item = (ZedGraphWebEllipseObj) draw;
                 var x = new EllipseObj();
                 item.CopyTo(x);
                 pane.GraphObjList.Add(x);
             }
         }
     }
     catch (Exception ex)
     {
         Log.Debug("Exception thrown at AddWebGraphItems: " + ex.Message, ex);
     }
 }
Пример #15
0
        protected byte[] GetThumbNailSizeImage(byte[] binaryData)
        {
            byte[] ThumbNailBinaryData = null;
            try
            {
                System.IO.MemoryStream TempMemStream = new System.IO.MemoryStream(binaryData);
                System.Drawing.Image   ImageObj;
                System.Drawing.Image   ThumbSizeImageObj;
                ImageObj = System.Drawing.Image.FromStream(TempMemStream);
                int temHeight;
                int temWidth;
                temHeight = ImageObj.Height;
                temWidth  = ImageObj.Width;
                System.IO.MemoryStream TempFileStream = new System.IO.MemoryStream();
                // If Imagesize is less than 20*20 then return the original image
                if (((temWidth < 20) &&
                     (temHeight < 20)))
                {
                    byte[] ImageBinaryData;
                    try
                    {
                        //load as raw format so that the image can have transparency is retained.
                        ImageObj.Save(TempFileStream, ImageObj.RawFormat);
                    }
                    catch
                    {
                        //if exception happens which can be for .ico, then load as jpeg but transparency cannot be retained.
                        ImageObj.Save(TempFileStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                    ImageBinaryData = new byte[] { ((byte)(TempFileStream.Length)) };
                    ImageBinaryData = TempFileStream.ToArray();
                    return(ImageBinaryData);
                }
                double percentSize = this.ImagePercentSize;

                // If the ImagePercentSize is 0.2 then the actual percent calculation will result in generating
                // temHeight and temWidth as Zero. When the height and width is zero, GetThumbnailImage()
                // will generate image of arbitrary size. Hence the image will not display as predicted,
                // ie, with size 0.2%. For this purpose, to maintain consistant image size, when ImagePercentSize
                // is less than 1, it is taken as actual percentage for eg. when ImagePercentSize is 0.2, it is considered as 20%
                // and image will displayed with 20% of original size.
                if (this.ImagePercentSize <= 1)
                {
                    percentSize = this.ImagePercentSize * 100;
                }
                //Actual percentage calculation. as ImagePercentSize value provided by client is a number not a percent
                percentSize = percentSize / 100;
                temHeight   = (int)((percentSize * temHeight));
                temWidth    = (int)((percentSize * temWidth));
                // Create thumbnail size of the original Image ImageObj
                if (this.ImagePercentSize == 0)
                {
                    ThumbSizeImageObj = ImageObj.GetThumbnailImage(this.ImageWidth, this.ImageHeight, null, IntPtr.Zero);
                }
                else
                {
                    ThumbSizeImageObj = ImageObj.GetThumbnailImage(temWidth, temHeight, null, IntPtr.Zero);
                }
                try
                {
                    //load as raw format so that the image can have transparency is retained.
                    ThumbSizeImageObj.Save(TempFileStream, ImageObj.RawFormat);
                }
                catch
                {
                    //if exception happens which can be for .ico, then load as jpeg but transparency cannot be retained.
                    ThumbSizeImageObj.Save(TempFileStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                ThumbNailBinaryData = new byte[] {
                    ((byte)(TempFileStream.Length))
                };
                ThumbNailBinaryData = TempFileStream.ToArray();
            }
            catch
            {
            }
            return(ThumbNailBinaryData);
        }
Пример #16
0
        public Image Read(string path)
        {
            var data = File.ReadAllLines(path);

            Vertexes  = new List <Vector3>();
            Normals   = new List <Vector3>();
            Faces     = new List <List <Vertex> >();
            Triangles = new List <Triangle>();

            foreach (var str in data)
            {
                var line = str.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                if (line.Length == 0)
                {
                    continue;
                }

                switch (line[0])
                {
                case "v":
                    ProcessVertex(line);
                    break;

                case "vn":
                    ProcessNormal(line);
                    break;

                case "f":
                    ProcessFace(line);
                    break;
                }
            }

            foreach (var face in Faces)
            {
                var triangle = new Triangle(
                    Vertexes[face[0].V],
                    Vertexes[face[1].V],
                    Vertexes[face[2].V],
                    Normals[face[0].Vn],
                    Normals[face[1].Vn],
                    Normals[face[2].Vn]);
                Triangles.Add(triangle);
            }

            var vectorColors = _renderer.Render(Triangles);
            var colors       = _converter.ConvertFromVectorToColors(vectorColors);
            var cool         = new List <Color>();

            for (int i = 0; i < colors.GetLength(0); i++)
            {
                for (int j = 0; j < colors.GetLength(1); j++)
                {
                    if (colors[i, j].R != 255 && colors[i, j].G != 255 && colors[i, j].B != 255)
                    {
                        cool.Add(colors[i, j]);
                    }
                }
            }
            ImageObj result = new ImageObj()
            {
                Bitmap = colors,
                Header = new HeaderObj()
                {
                    BitsPerComponent = 32,
                    Height           = colors.GetLength(0),
                    Width            = colors.GetLength(1)
                },
                Path = path
            };

            return(result);

            void ProcessVertex(string[] lines)
            {
                Vertexes.Add(new Vector3(
                                 float.Parse(lines[1], CultureInfo.InvariantCulture.NumberFormat),
                                 float.Parse(lines[2], CultureInfo.InvariantCulture.NumberFormat),
                                 float.Parse(lines[3], CultureInfo.InvariantCulture.NumberFormat)));
            }

            void ProcessNormal(string[] lines)
            {
                Normals.Add(new Vector3(
                                float.Parse(lines[1], CultureInfo.InvariantCulture.NumberFormat),
                                float.Parse(lines[2], CultureInfo.InvariantCulture.NumberFormat),
                                float.Parse(lines[3], CultureInfo.InvariantCulture.NumberFormat)));
            }

            void ProcessFace(string[] lines)
            {
                var temp = new List <Vertex>();

                foreach (var line in lines.Skip(1).ToArray())
                {
                    var vertices = line.Split('/');
                    var vertex   = new Vertex()
                    {
                        V  = int.Parse(vertices[0], CultureInfo.InvariantCulture.NumberFormat) - 1,
                        Vn = int.Parse(vertices[2], CultureInfo.InvariantCulture.NumberFormat) - 1
                    };
                    temp.Add(vertex);
                }
                Faces.Add(temp);
            }
        }
Пример #17
0
 /// <summary>
 /// Add the <see cref="ZeeGraphWebGraphObj" /> objects defined in the webcontrol to
 /// the <see cref="GraphPane" /> as <see cref="GraphObj" /> objects.
 /// </summary>
 /// <param name="g">The <see cref="Graphics" /> instance of interest.</param>
 /// <param name="pane">The <see cref="GraphPane" /> object to receive the
 /// <see cref="GraphObj" /> objects.</param>
 protected void AddWebGraphItems( Graphics g, GraphPane pane )
 {
     try
     {
         ZeeGraphWebGraphObj draw;
         for ( int i = 0; i < GraphObjList.Count; i++ )
         {
             draw = GraphObjList[i];
             if ( draw is ZeeGraphWebTextObj )
             {
                 ZeeGraphWebTextObj item = (ZeeGraphWebTextObj)draw;
                 TextObj x = new TextObj();
                 item.CopyTo( x );
                 pane.GraphObjList.Add( x );
             }
             else if ( draw is ZeeGraphWebArrowObj )
             {
                 ZeeGraphWebArrowObj item = (ZeeGraphWebArrowObj)draw;
                 ArrowObj x = new ArrowObj();
                 item.CopyTo( x );
                 pane.GraphObjList.Add( x );
             }
             else if ( draw is ZeeGraphWebImageObj )
             {
                 ZeeGraphWebImageObj item = (ZeeGraphWebImageObj)draw;
                 ImageObj x = new ImageObj();
                 item.CopyTo( x );
                 pane.GraphObjList.Add( x );
             }
             else if ( draw is ZeeGraphWebBoxObj )
             {
                 ZeeGraphWebBoxObj item = (ZeeGraphWebBoxObj)draw;
                 BoxObj x = new BoxObj();
                 item.CopyTo( x );
                 pane.GraphObjList.Add( x );
             }
             else if ( draw is ZeeGraphWebEllipseObj )
             {
                 ZeeGraphWebEllipseObj item = (ZeeGraphWebEllipseObj)draw;
                 EllipseObj x = new EllipseObj();
                 item.CopyTo( x );
                 pane.GraphObjList.Add( x );
             }
         }
     }
     catch ( Exception )
     {
     }
 }
Пример #18
0
        public override bool Renderer(string strParams_renderer = "")
        {
            bool bResult = true;

            _FloderRenderer = _FloderOutput;
            if (base.Renderer(strParams_renderer))
            {
                //载入结果栅格
                if (_dstRasterFile == "")
                {
                    return(true);
                }
                GdalRead_TIFF gdalRead_TIFF = new GdalRead_TIFF();
                gdalRead_TIFF.InitDataset(_dstRasterFile, 0, false);

                string          fileName = _Datas["title"] + _dtTag;
                IRasterRenderer pRender  = (IRasterRenderer)Renderer_Factory.CreateRenderer(emRenderType.Classify, gdalRead_TIFF);
                pRender.InitParams(_Renderer);
                pRender.Render();
                pRender.Output(_FloderRenderer, fileName);


                //图例处理等
                JObject renderInfo = (JObject)pRender.ToRendererStr(false);
                _Result["renderer"] = renderInfo;
                _Renderer           = (JObject)_Params["rendererParms"];
                if (_Renderer != null)
                {
                    //创建图例
                    if (Convert.ToBoolean(_Renderer["rendererOutputLegend"]))
                    {
                        bResult = bResult && pRender.Create_Legend(_FloderRenderer, "Legend_" + _Datas["title"]);
                        if (bResult)
                        {
                            _Result["renderer"]["renderer"]["nameLegend"] = pRender.Image_Legend.Name + pRender.Image_Legend.Suffix;
                        }
                    }

                    //创建发布图
                    if (Convert.ToBoolean(_Renderer["rendererOutputPublish"]))
                    {
                        //含图例的渲染图
                        ImageObj _Image = pRender.Image, _Image_legend = pRender.Image_Legend;
                        if (_Image_legend == null)
                        {
                            bResult       = bResult && pRender.Create_Legend(_FloderRenderer, "Legend_" + _Datas["title"]);
                            _Image_legend = pRender.Image_Legend;
                        }

                        ImageColor pColor       = new ImageColor("#192734");
                        ImageObj   _Image_Scale = pRender.Create_Scale();
                        ImageObj   img          = new ImageObj(_Image.Width + _Image_legend.Width, _Image.Height > _Image_legend.Height ? _Image.Height : _Image_legend.Height);
                        img.DrawImage(_Image_legend.Width, 0, _Image, 1);
                        img.DrawImage(0, (int)((img.Height - _Image_legend.Height)), _Image_legend, 1);
                        img.DrawImage((int)(_Image_legend.Width * 1.2), (int)((img.Height - _Image_Scale.Height * 1.2)), _Image_Scale, 1);
                        img.DrawPolygon(0, 20, pColor.Color, 1, img.Width - 1, img.Height - 21);
                        img.Name = fileName + "_publish";
                        bResult  = bResult && img.Save(_FloderRenderer);
                        if (bResult)
                        {
                            _Result["renderer"]["renderer"]["namePublish"] = img.Name + img.Suffix;
                        }
                    }
                }
            }
            return(true);
        }
Пример #19
0
        protected void zgwCtl_OnRenderGraph(ZedGraphWeb zgw, Graphics g, MasterPane masterPane)
        {
            if (g != null)
            {
                g.Clear(Color.White);
            }
            double[]  valuesY   = TranslateSpeedValues(this.speedValues);
            XDate[]   valuesX   = TranslateTimeValues(this.timeLabels);
            GraphPane graphPane = null;

            if (masterPane != null)
            {
                graphPane = masterPane[0];
            }
            else
            {
                graphPane = new GraphPane();
            }
            PointPairList listMean       = new PointPairList();
            PointPairList listMax        = new PointPairList();
            PointPairList listMin        = new PointPairList();
            PointPairList listSplineMax  = new PointPairList();
            PointPairList listSplineMin  = new PointPairList();
            PointPairList listSplineMean = new PointPairList();

            //Create PointPair lists to use later. (Either to plot them directly, or as below)
            for (int i = 0; i < valuesX.Length; i++)
            {
                listMean.Add(valuesX[i], valuesY[i]);
                listMax.Add(valuesX[i], maxSpeedValues[i]);
                listMin.Add(valuesX[i], minSpeedValues[i]);
            }
            listMax.Sort();
            listMin.Sort();
            listMean.Sort();

            //I´d whish the charts to be nice and "round", not edgy. Zed has a way of interpolating with Splines, making it easy
            //So lets create 150 new points to plot instead.
            int count = 150;

            for (int i = 0; i < count && valuesX.Length != 0; i++)
            {
                //interval size
                double x = listMax[0].X + (double)i * (listMax[valuesX.Length - 1].X - listMax[0].X) / count;

                // Zedgraph throws an exception here if we do not have enough data.
                try
                {
                    listSplineMax.Add(x, listMax.SplineInterpolateX(x, 0.2));
                    listSplineMin.Add(x, listMin.SplineInterpolateX(x, 0.2));
                    listSplineMean.Add(x, listMean.SplineInterpolateX(x, 0.5));
                }
                catch (Exception)
                {
                    break;
                    // ignore
                }
            }

            // because next added Curve place in back to from, we display first max & min lines
            if (minSpeedValues != null || minSpeedValues.Length != 0)
            {
                LineItem minLineCurve = graphPane.AddCurve("Minimum Wind", listSplineMin, Color.Red, SymbolType.None);
                minLineCurve.Line.Width = 1.6f;
                //minLineCurve.Line.Fill = new Fill(Color.FromArgb(0, 230, 0), Color.FromArgb(0, 94, 0), 90F);
                minLineCurve.Line.Fill = new Fill(Color.White);
            }

            LineItem myCurve = graphPane.AddCurve("Average Wind", listSplineMean, Color.FromArgb(43, 75, 157), SymbolType.None);

            // Fill the area under the curve with a white-red gradient at 90 degrees
            //myCurve.Line.Fill = new Fill(Color.FromArgb(118, 164, 251), Color.FromArgb(118, 164, 251), 90F);
            myCurve.Line.Fill        = new Fill(Color.FromArgb(152, 251, 152), Color.FromArgb(0, 255, 127), 90F);
            myCurve.Line.Width       = 1.6f;
            myCurve.Line.IsAntiAlias = true;
            // Make the symbols opaque by filling them with white
            myCurve.Symbol.Fill = new Fill(Color.DarkGray);

            graphPane.XAxis.Scale.FontSpec.FontColor = Color.Black;

            graphPane.XAxis.Type = AxisType.Date;
            if (valuesX.Length > 0)
            {
                graphPane.XAxis.Scale.Min = (double)valuesX[valuesX.Length - 1];
                graphPane.XAxis.Scale.Max = (double)valuesX[0];
            }
            graphPane.XAxis.MajorGrid.IsVisible = true;

            graphPane.YAxis.Scale.Min = 0;
            graphPane.YAxis.Scale.Max = 15;
            if (GetMaxValue(maxSpeedValues) > 15)
            {
                graphPane.YAxis.Scale.Max = GetMaxValue(maxSpeedValues) + 1;
            }
            graphPane.YAxis.IsAxisSegmentVisible = false;

            graphPane.Y2Axis.Scale.Align        = AlignP.Inside;
            graphPane.YAxis.Title.Text          = "m/s";
            graphPane.YAxis.Title.FontSpec.Size = 22;

            graphPane.YAxis.MajorTic.IsBetweenLabels = false;
            graphPane.YAxis.MajorTic.Color           = Color.DarkGray;
            graphPane.YAxis.MajorTic.IsInside        = false;
            graphPane.YAxis.MajorTic.IsOpposite      = false;
            graphPane.YAxis.MinorTic.Color           = Color.DarkGray;
            graphPane.YAxis.MinorTic.IsInside        = false;
            graphPane.YAxis.MinorTic.IsOpposite      = false;
            graphPane.YAxis.MinorTic.IsOutside       = false;
            graphPane.YAxis.MajorGrid.IsVisible      = true;
            graphPane.YAxis.MinorGrid.IsVisible      = false;
            graphPane.YAxis.Scale.Align = AlignP.Inside;
            graphPane.YAxis.Title.FontSpec.FontColor = Color.DarkGray;
            graphPane.YAxis.Color = Color.DarkGray;

            if (maxSpeedValues != null || maxSpeedValues.Length != 0)
            {
                LineItem maxLineCurve = graphPane.AddCurve("Maximum Wind", /*listMax*/ listSplineMax, Color.Red, SymbolType.None);
                maxLineCurve.Line.Width = 1.6f;
                maxLineCurve.Line.Fill  = new Fill(Color.FromArgb(152, 251, 152), Color.FromArgb(0, 255, 127), 90F);
            }

            // disable legend
            graphPane.Legend.IsVisible         = false;
            graphPane.Legend.FontSpec.Size     = 20;
            graphPane.Border.Color             = Color.White;
            graphPane.BarSettings.Type         = BarType.SortedOverlay;
            graphPane.Chart.Border.Color       = Color.DarkGray;
            graphPane.Title.FontSpec.FontColor = Color.DarkGray;
            // to disable scaling
            //graphPane.IsPenWidthScaled = false;
            //graphPane.IsFontsScaled = false;

            masterPane.AxisChange(g);

            // Draw wind direction arrows

            ImageObj[] dirImages  = new ImageObj[dirValues.Length];
            int        nbrOfPlots = Math.Min(20, dirImages.Length);

            float  step, xMin, xMax;
            double next, yMin, yMax;

            step = 0;
            xMin = xMax = 0;
            if (valuesX.Length != 0)
            {
                xMin = valuesX[valuesX.Length - 1];
                xMax = valuesX[0];
            }

            yMin = yMax = 0;
            if (valuesY.Length != 0)
            {
                yMin = 0;
                yMax = graphPane.YAxis.Scale.Max;
            }

            step = (xMax - xMin) / nbrOfPlots;
            next = 0;

            Image image = Image.FromFile(Server.MapPath("~/design/wind_arrow.png"));

            float[] rot;

            rot = getDirections(dirValues, (float)dirValues.Length / (float)nbrOfPlots, nbrOfPlots);

            if (rot != null)
            {
                if (dirImages.Length < nbrOfPlots)
                {
                    for (int i = 0; i < nbrOfPlots - dirImages.Length; i++)
                    {
                        next += step;
                    }
                }
                for (int i = 0; i < dirImages.Length && i < rot.Length && i < nbrOfPlots; i++)
                {
                    dirImages[i] = new ImageObj(rotateImage(image, rot[i]), xMin + next, (yMax / 10) * 9, step, yMax / 7);
                    graphPane.GraphObjList.Add(dirImages[i]);
                    next += step;
                }
            }

            // Write the date
            if (valuesX.Length > 0)
            {
                DateTime date = valuesX[0];
                graphPane.Title.Text = getInfoText(date);
            }
            graphPane.Title.FontSpec.Size       = 24;
            graphPane.Title.FontSpec.Fill.Color = Color.Black;

            // Get interval so we can name the picture
            String name = "graph_" + this.interval + ".png";


            try
            {
                String path = HttpContext.Current.Server.MapPath("/") + "Applet/" + location;
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                masterPane.GetImage().Save(Server.MapPath("~/Applet/" + location + "/" + name), System.Drawing.Imaging.ImageFormat.Png);
            }
            catch (Exception)
            {
                Debug.WriteLine("Problem3");
                Debug.WriteLine("Exception raised. Location: " + location);
            }
        }