當前位置: 首頁>>代碼示例>>C#>>正文


C# Image.Encode方法代碼示例

本文整理匯總了C#中System.Image.Encode方法的典型用法代碼示例。如果您正苦於以下問題:C# Image.Encode方法的具體用法?C# Image.Encode怎麽用?C# Image.Encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Image的用法示例。


在下文中一共展示了Image.Encode方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Render

        public byte[] Render(Envelope envelope, string format, int tileWidth, int tileHeight)
        {
            // Lock map object for rendering
            // TO DO: better strategy is to create a pool of map objects
            lock (mapLock)
            {
                _map.Width = Convert.ToUInt32(tileWidth);
                _map.Height = Convert.ToUInt32(tileHeight);
                _map.ZoomToBox(envelope.Minx, envelope.Miny, envelope.Maxx, envelope.Maxy);

                format = format.ToLower();
                // Render Image
                if (format == "png" || format == "jpg")
                {
                    Image img = new Image(Convert.ToInt32(_map.Width), Convert.ToInt32(_map.Height));
                    _map.Render(img);
                    if (format == "png")
                    {
                        format = this._pngOptions;
                    }
                    if (format == "jpg")
                    {
                        format = this._jpegOptions;
                    }
                    return img.Encode(format);
                }

                // Render UTFGrid
                else if (format == "json")
                {
                    NETMapnik.Grid grd = new NETMapnik.Grid(_map.Width, _map.Height);
                    _map.Render(grd, Convert.ToUInt32(this._gridLayerIndex), this._gridFields);
                    string json = JsonConvert.SerializeObject(grd.Encode("utf", true, Convert.ToUInt32(this._gridResolution)));
                    return Encoding.UTF8.GetBytes(json);
                }

                // Render vector tile
                else if (format == "pbf")
                {
                    //tile coord (i.e., 0/0/0 not needed for pbf rendering
                    VectorTile vTile = new VectorTile(0,0,0, _map.Width,_map.Height);
                    _map.Render(vTile);
                    byte[] bytes =  vTile.GetBytes();

                    //compress vector tile bytes
                    if (bytes.Length > 0)
                    {
                        bytes = Compress(bytes);
                    }
                    return bytes;
                }
                // Format not expected so throw exception
                throw new InvalidTileFormatException(
                    string.Format("Invalid tile FORMAT {0}", format)
                );
            }
        }
開發者ID:jbrwn,項目名稱:tc,代碼行數:57,代碼來源:MapnikProvider.cs

示例2: Image_Encode

 public void Image_Encode()
 {
     Map m = new Map(10, 10);
     Image i1 = new Image(10, 10);
     m.Background = new Color("green");
     m.Render(i1);
     byte[] bytes1 = i1.Encode("png");
     byte[] bytes2 = File.ReadAllBytes(@".\data\10x10green.png");
     CollectionAssert.AreEqual(bytes1, bytes2);
 }
開發者ID:rouen-sk,項目名稱:NET-Mapnik,代碼行數:10,代碼來源:ImageTests.cs

示例3: Image_Encode_InvalidFormat

 public void Image_Encode_InvalidFormat()
 {
     Image im = new Image(256, 256);
     im.Encode("foo");
 }
開發者ID:rouen-sk,項目名稱:NET-Mapnik,代碼行數:5,代碼來源:ImageTests.cs

示例4: Render

        public byte[] Render(Coord coord, string format, int tileWidth, int tileHeight)
        {
            byte[] tileBytes = this._tileSource.GetTile(coord, "pbf");

            // Uncompress bytes
            if (tileBytes.Length > 0)
            {
                tileBytes = Decompress(tileBytes);
            }

            // Set vector tile bytes
            // mapnik vector tile assumes top left origin
            int y = coord.Y;
            if (!coord.TopOrigin)
                y = this._tileSource.GridSet.GridHeight(coord.Z) - coord.Y - 1;

            VectorTile vTile = new VectorTile(coord.Z, coord.X, y, Convert.ToUInt32(tileWidth), Convert.ToUInt32(tileHeight));
            vTile.SetBytes(tileBytes);

            // Get coord envelope
            Envelope envelope = this._tileSource.GridSet.CoordToEnvelope(coord);

            // Lock map object for rendering
            // TO DO: better strategy is to create a pool of map objects
            lock (mapLock)
            {
                _map.Width = Convert.ToUInt32(tileWidth);
                _map.Height = Convert.ToUInt32(tileHeight);
                _map.ZoomToBox(envelope.Minx, envelope.Miny, envelope.Maxx, envelope.Maxy);
                Image img = new Image(Convert.ToInt32(_map.Width), Convert.ToInt32(_map.Height));
                vTile.Render(_map, img);

                format = format.ToLower();
                if (format == "png" || format == "jpg")
                {
                    if (format == "png")
                    {
                        format = this._pngOptions;
                    }
                    if (format == "jpg")
                    {
                        format = this._jpegOptions;
                    }
                    return img.Encode(format);
                }
                // Format not expected so throw exception
                throw new InvalidTileFormatException(
                    string.Format("Invalid tile FORMAT {0}", format)
                );

            }
        }
開發者ID:jbrwn,項目名稱:tc,代碼行數:52,代碼來源:MapnikVectorTileProvider.cs


注:本文中的System.Image.Encode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。