Exemple #1
0
        public static BackgroundWorker RenderMinimapWorker()
        {
            var worker = new BackgroundWorker();

            worker.WorkerReportsProgress      = true;
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += (sender, args) =>
            {
                var w = (BackgroundWorker)sender;
                var m = (IReadOnlyMapModel)args.Argument;

                using (var map = new MapPixelImageAdapter(m.Tile.TileGrid))
                {
                    int width, height;

                    if (map.Width > map.Height)
                    {
                        width  = 252;
                        height = (int)(252 * (map.Height / (float)map.Width));
                    }
                    else
                    {
                        height = 252;
                        width  = (int)(252 * (map.Width / (float)map.Height));
                    }

                    var wrapper = new NearestNeighbourPaletteWrapper(
                        new BilinearWrapper(map, width, height),
                        PaletteFactory.TAPalette);

                    var b = new Bitmap(wrapper.Width, wrapper.Height);
                    using (var g = Graphics.FromImage(b))
                    {
                        g.FillRectangle(Brushes.Black, new Rectangle(0, 0, b.Width, b.Height));
                    }

                    for (var y = 0; y < wrapper.Height; y++)
                    {
                        if (w.CancellationPending)
                        {
                            args.Cancel = true;
                            return;
                        }

                        for (var x = 0; x < wrapper.Width; x++)
                        {
                            b.SetPixel(x, y, wrapper.GetPixel(x, y));
                        }

                        var percentComplete = ((y + 1) * 100) / wrapper.Height;

                        w.ReportProgress(percentComplete);
                    }

                    args.Result = b;
                }
            };
            return(worker);
        }
Exemple #2
0
        public static Bitmap GenerateMinimapLinear(IPixelImage map)
        {
            int width, height;

            if (map.Width > map.Height)
            {
                width  = 252;
                height = (int)(252 * (map.Height / (float)map.Width));
            }
            else
            {
                height = 252;
                width  = (int)(252 * (map.Width / (float)map.Height));
            }

            var wrapper = new NearestNeighbourPaletteWrapper(
                new BilinearWrapper(map, width, height),
                PaletteFactory.TAPalette);

            return(ToBitmap(wrapper));
        }