当前位置: 首页>>代码示例>>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;未经允许,请勿转载。