Exemplo n.º 1
0
        public virtual bool Output(string path, string name = "")
        {
            bool bResult = true;

            if (_Image != null)
            {
                if (name + "" != "")
                {
                    _Image.Name = name;
                }
                bResult = _Image.Save(path);
                name    = _Image.Name + _Image.Suffix;
            }

            if (_Result != null)
            {
                if (_Result["renderer"] != null)
                {
                    _Result["renderer"]["route"]       = path;
                    _Result["renderer"]["name"]        = name;
                    _Result["renderer"]["nameLegend"]  = "";
                    _Result["renderer"]["namePublish"] = "";
                }
            }
            return(bResult);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
 public bool Save(string path, string name = "")
 {
     if (name != "")
     {
         _img.Name = name;
     }
     return(_img.Save(path));
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }