Пример #1
0
        public static void PaintCoast()
        {
            Bitmap img = LoadImage("terrain.bmp");
            var    p   = img.Palette;

            p.Entries[10] = Color.FromArgb(255, 247, 0);
            img.Palette   = p;
            LockBitmap lockImg = new LockBitmap(img);

            lockImg.LockBits();
            int pixelsPainted = 0;

            bool[] matchData = new bool[lockImg.Width * lockImg.Height];

            for (int y = 0; y < lockImg.Height; y++)
            {
                for (int x = 0; x < lockImg.Width; x++)
                {
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("Checking pixel (" + x + ", " + y + ")");
                    if (IsCoastPixel(x, y, lockImg, matchData))
                    {
                        lockImg.SetPixel(x, y, Color.FromArgb(255, 247, 0));
                        pixelsPainted++;
                        Console.WriteLine("Pixels Painted: " + pixelsPainted);
                    }
                }
            }

            lockImg.UnlockBits();
            SaveImage(img, "terrain_coast.bmp");
        }
Пример #2
0
        public static void ConvertToEU4Terrain()
        {
            Bitmap img          = LoadImage("terrain_eu3.bmp");
            Bitmap img2         = LoadImage("terrain_eu4.bmp");
            Bitmap table        = LoadImage("terrain_eu3_colortable.bmp");
            var    p            = table.Palette;
            var    tablePalette = new Dictionary <Color, int>();

            for (int i = 0; i < p.Entries.Length; i++)
            {
                if (!tablePalette.ContainsKey(p.Entries[i]))
                {
                    tablePalette.Add(p.Entries[i], i);
                }
            }
            var p2 = img2.Palette;
            //p.Entries[10] = Color.FromArgb(255, 247, 0);
            //img.Palette = p;
            LockBitmap lockImg  = new LockBitmap(img);
            LockBitmap lockImg2 = new LockBitmap(img2);

            lockImg.LockBits();
            lockImg2.LockBits();

            for (int y = 0; y < lockImg.Height; y++)
            {
                for (int x = 0; x < lockImg.Width; x++)
                {
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("At pixel (" + x + ", " + y + ")");
                    var c        = lockImg.GetPixel(x, y);
                    int indexIn  = tablePalette.ContainsKey(c) ? tablePalette[lockImg.GetPixel(x, y)] : 0;
                    int indexOut = (int)GetTerrainCategories(GetTerrainType((TerrainCategoriesEU3)indexIn));
                    //var color = p2.Entries[indexOut];
                    lockImg2.SetPixelIndex(x, y, indexOut);
                }
            }

            lockImg.UnlockBits();
            lockImg2.UnlockBits();
            SaveImage(img2, "terrain_converted.bmp");
        }
Пример #3
0
        public static void PaintHeightmap()
        {
            Bitmap     terrain   = LoadImage("terrain_eu3.bmp");
            Bitmap     heightmap = LoadImage("heightmap.bmp");
            LockBitmap lockT     = new LockBitmap(terrain);
            LockBitmap lockH     = new LockBitmap(heightmap);

            lockT.LockBits();
            lockH.LockBits();

            var tablePalette = new Dictionary <Color, int>();

            for (int i = 0; i < terrain.Palette.Entries.Length; i++)
            {
                if (!tablePalette.ContainsKey(terrain.Palette.Entries[i]))
                {
                    tablePalette.Add(terrain.Palette.Entries[i], i);
                }
            }

            for (int y = 0; y < lockT.Height; y++)
            {
                for (int x = 0; x < lockT.Width; x++)
                {
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("At pixel (" + x + ", " + y + ")");
                    var c       = lockT.GetPixel(x, y);
                    int indexIn = tablePalette.ContainsKey(c) ? tablePalette[lockT.GetPixel(x, y)] : 0;
                    int height  = GetHeight((TerrainCategoriesEU3)indexIn);
                    lockH.SetPixel(x, y, Color.FromArgb(height, height, height));
                }
            }

            lockT.UnlockBits();
            lockH.UnlockBits();
            SaveImage(heightmap, "heightmap_new.bmp");
        }