示例#1
0
        private void ExportImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_imageExportForm == null || _imageExportForm.IsDisposed)
            {
                _imageExportForm = new ImageExportOptionForm();
            }
            _imageExportForm.Show();
            _imageExportForm.BringToFront();

            _imageExportForm.ExportImage += (width, height) => // Called when export button is pressed in ImageExportOptionForm
            {
                if (width == 0 || height == 0)
                {
                    return;
                }
                var bitmap = new Bitmap(width, height);

                _renderer.Render(Graphics.FromImage(bitmap), new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                 _mapScale, _pos, _palette, _renderFlags);

                var result = exportFileDialog.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                var fileStream = exportFileDialog.OpenFile();

                bitmap.Save(fileStream, ImageFormat.Png);
                fileStream.Close();
                _imageExportForm.Hide();
            };
        }
示例#2
0
        private void SaveTileImage(int z, int x, int y, PointF pos, float zoom, string exportPath) // z = zoomLevel; x = row tile index; y = column tile index
        {
            var bitmap = new Bitmap(tileSize, tileSize);

            pos.X = (x == 0) ? pos.X : pos.X + (bitmap.Width / zoom) * x; // get tile start coords
            pos.Y = (y == 0) ? pos.Y : pos.Y + (bitmap.Height / zoom) * y;

            _renderer.Render(Graphics.FromImage(bitmap), new Rectangle(0, 0, bitmap.Width, bitmap.Height), zoom, pos, _palette, _renderFlags ^ RenderFlags.TextOverlay);

            Directory.CreateDirectory($"{exportPath}/{z}/{x}");
            bitmap.Save($"{exportPath}/{z}/{x}/{y}.png", ImageFormat.Png);
            bitmap.Dispose();
        }
示例#3
0
        private void SaveTileImage(int z, int x, int y, PointF pos, float zoom, string exportPath, RenderFlags renderFlags) // z = zoomLevel; x = row tile index; y = column tile index
        {
            using (var bitmap = new Bitmap(SettingsManager.Current.Settings.TileGenerator.TileSize, SettingsManager.Current.Settings.TileGenerator.TileSize))
            {
                using (var g = Graphics.FromImage(bitmap))
                {
                    pos.X = (x == 0) ? pos.X : pos.X + (bitmap.Width / zoom) * x; // get tile start coords
                    pos.Y = (y == 0) ? pos.Y : pos.Y + (bitmap.Height / zoom) * y;

                    if (z == savedZoomLevel && oldPos.Y != 0 && oldPos.X != 0 && movement == 0)
                    {
                        float difference = Math.Abs(oldPos.Y - pos.Y);
                        movement = difference / SettingsManager.Current.Settings.TileGenerator.TileSize;

                        Console.WriteLine($"{difference}, scale: {difference / SettingsManager.Current.Settings.TileGenerator.TileSize}");
                    }

                    _tilesGeneratorRenderer.Render(g, new Rectangle(0, 0, bitmap.Width, bitmap.Height), zoom, pos, _palette,
                                                   renderFlags & ~RenderFlags.TextOverlay);

                    Directory.CreateDirectory($"{exportPath}/Tiles/{z}/{x}");
                    bitmap.Save($"{exportPath}/Tiles/{z}/{x}/{y}.png", ImageFormat.Png);
                }
            }
        }
示例#4
0
文件: Program.cs 项目: KRtekTM/ts-map
        private static void Main(string[] args)
        {
            var mods = new System.Collections.Generic.List <Mod> {
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\promods-me-assets-v241.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\promods-me-defmap-v241.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\promods-def-st-v241.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\RusMap-map_v1.8.1.2.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\RusMap-model2_v1.8.1.2.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\RusMap-model_v1.8.1.2.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\promods-assets-v241.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\promods-map-v241.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\promods-media-v241.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\promods-model1-v241.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\promods-model2-v241.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\promods-model3-v241.scs"),
                new Mod(@"D:\Documents\Euro Truck Simulator 2\mod\RusMap-def_v1.8.1.2.scs"),
            };

            mods.ForEach(x => x.Load = true);
            TsMapper mapper = new TsMapper("D:/Apps/Steam/steamapps/common/Euro Truck Simulator 2/", mods);

            mapper.IsEts2 = true;
            mapper.Parse();

            var renderer = new TsMapRenderer(mapper);
            var palette  = new SimpleMapPalette();

            var path = @"F:/Screenshots";

            int width, height, scale;

            width = height = scale = 4000;

            int upperX = 160_000;  // 160_000;
            int lowerX = -120_000; // -120_000;

            int upperY = 130_000;  // 130_000;
            int lowerY = -210_000; // -210_000;

            for (int y = lowerY; y < upperY; y += scale * 2)
            {
                for (int x = lowerX; x < upperX; x += scale * 2)
                {
                    var bitmap = new Bitmap(width, height);

                    PointF pos = new PointF(x, y);

                    renderer.Render(Graphics.FromImage(bitmap), new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                    scale, pos, palette, RenderFlags.All);

                    using (FileStream fileStream = File.Open($"{path}/{x};{y}.png", FileMode.OpenOrCreate, FileAccess.ReadWrite))
                    {
                        bitmap.Save(fileStream, ImageFormat.Png);
                    }
                    bitmap.Dispose();
                    GC.Collect();
                }
            }
        }
示例#5
0
 private void MapPanel_Paint(object sender, PaintEventArgs e)
 {
     _renderer.Render(e.Graphics, e.ClipRectangle, _scale, _startPoint, _palette, _renderFlags);
 }
示例#6
0
 protected override void OnPaint(PaintEventArgs e)
 {
     _renderer.Render(e.Graphics, e.ClipRectangle, _mapScale, _pos);
     base.OnPaint(e);
 }