private PureImage GetTileImageWithoutBranding(GPoint pos, int zoom)
        {
            PureImage cleanTile      = null;
            const int brandingHeight = 25;

            // we fetch a tile which is 25px bigger at the top as well as at the bottom

            var brandedTile = GetTileImage(pos, zoom, new Size(
                                               DefaultTileSize.Width,
                                               DefaultTileSize.Height + brandingHeight * 2));

            // now we cut away the additional 25px at the upper and lower border
            // this will automatically also cut away the branding / copyright of the tile

            if (brandedTile != null)
            {
                using (brandedTile)
                    using (var tempBitmap = new Bitmap(brandedTile.Data))
                        using (var cropped = CropImage(tempBitmap, new Rectangle(
                                                           0,                        // x
                                                           brandingHeight,           // y
                                                           DefaultTileSize.Width,    // width
                                                           DefaultTileSize.Height))) // height
                        {
                            var memoryStream = new MemoryStream();
                            cropped.Save(memoryStream, ImageFormat.Png);
                            memoryStream.Position = 0;
                            cleanTile             = TileImageProxy.FromStream(memoryStream);
                            cleanTile.Data        = memoryStream;
                        }
            }
            return(cleanTile);
        }
Exemplo n.º 2
0
        public PureImage ReadImageFile(GPoint pos, int zoom)
        {
            string tile_file = string.Format(tile_file_path, zoom, pos.X, pos.Y);

            if (!File.Exists(tile_file))
            {
                return(null);//文件不存在
            }
            //FileStream fs = File.OpenRead(tile_file); //OpenRead

            byte[]       data = File.ReadAllBytes(tile_file);
            MemoryStream ms   = new MemoryStream(data);

            //int filelength = 0;
            //filelength = (int)fs.Length; //获得文件长度
            //Byte[] image = new Byte[filelength]; //建立一个字节数组
            //fs.Read(image, 0, filelength); //按字节流读取

            PureImage ret = GMapProvider.TileImageProxy.FromStream(ms);

            if (ms.Length > 0)
            {
                ret = TileImageProxy.FromStream(ms);

                if (ret != null)
                {
                    ret.Data          = ms;
                    ret.Data.Position = 0;
                }
                else
                {
                    ms.Dispose();
                }
            }
            ms = null;

            //fs.Close();
            return(ret);
            //Bitmap bit = new Bitmap(result);
            //return bit;
        }