Пример #1
0
        static void TileGen(Bitmap srcBitmap, float srcZoomFactor, int tileSize, int tilePadding,
                            string dstBasePath, string dstFileNameFormat)
        {
            if (srcZoomFactor != 1.0f)
            {
                int      w         = (int)(srcBitmap.Width * srcZoomFactor);
                int      h         = (int)(srcBitmap.Height * srcZoomFactor);
                Bitmap   newSource = new Bitmap(w, h);
                Graphics g         = Graphics.FromImage(newSource);
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.DrawImage(srcBitmap, 0, 0, w, h);
                srcBitmap = newSource;
            }

            Bitmap tile = new Bitmap(tileSize + tilePadding, tileSize + tilePadding, srcBitmap.PixelFormat);

            for (int x = 0, iX = 0; x < srcBitmap.Width; x += tileSize, iX++)
            {
                for (int y = 0, iY = 0; y < srcBitmap.Height; y += tileSize, iY++)
                {
                    Graphics.FromImage(tile).Clear(Clear);
                    GraphicsUtil.BitBlt(srcBitmap, x, y, tileSize + tilePadding, tileSize + tilePadding, tile, 0, 0);
                    string        savePath = Path.Combine(dstBasePath, string.Format(dstFileNameFormat, iX, iY));
                    DirectoryInfo dir      = new DirectoryInfo(Path.GetDirectoryName(savePath));
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                    tile.Save(savePath);
                }
            }
        }