コード例 #1
0
        public static void RenderTopoPngFromRegion(byte[][] HeightData, string ImgPath, int Xs, int Zs)
        {
            byte[] hMap  = HeightData[0];
            byte[] hWMap = HeightData[1];

            Bitmap bit = new Bitmap(512, 512);

            Color[][] pal  = Palettes();
            Color[]   tRGB = pal[0];
            Color[]   wRGB = pal[1];

            for (int zz = 0; zz < 512; zz++)
            {
                for (int xx = 0; xx < 512; xx++)
                {
                    int gI = (zz * 512) + xx;

                    if (hWMap[gI] < 255)
                    {
                        if (zz > 1)
                        {
                            int cI = ((zz - 1) * 512) + xx;
                            if (hMap[cI] > hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, wRGB[hMap[gI]], Color.White, 0));
                            }
                            else if (hMap[cI] < hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, wRGB[hMap[gI]], Color.DarkGray, 0));
                            }
                            else
                            {
                                bit.SetPixel(xx, zz, wRGB[hMap[gI]]);
                            }
                        }
                        else
                        {
                            int cI = ((zz + 1) * 512) + xx;
                            if (hMap[cI] > hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, wRGB[hMap[gI]], Color.White, 0));
                            }
                            else if (hMap[cI] < hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, wRGB[hMap[gI]], Color.DarkGray, 0));
                            }
                            else
                            {
                                bit.SetPixel(xx, zz, wRGB[hMap[gI]]);
                            }
                        }
                    }
                    else
                    {
                        if (zz > 1)
                        {
                            int cI = ((zz - 1) * 512) + xx;

                            if (hMap[cI] > hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, tRGB[hMap[gI]], Color.White, 0));
                            }
                            else if (hMap[cI] < hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, tRGB[hMap[gI]], Color.DarkGray, 0));
                            }
                            else
                            {
                                bit.SetPixel(xx, zz, tRGB[hMap[gI]]);
                            }
                        }
                        else
                        {
                            int cI = ((zz + 1) * 512) + xx;

                            if (hMap[cI] > hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, tRGB[hMap[gI]], Color.White, 0));
                            }
                            else if (hMap[cI] < hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, tRGB[hMap[gI]], Color.DarkGray, 0));
                            }
                            else
                            {
                                bit.SetPixel(xx, zz, tRGB[hMap[gI]]);
                            }
                        }
                    }
                }
            }



            DirectoryInfo imgDir     = new DirectoryInfo(ImgPath);
            string        SaveBitMap = string.Format(Path.Combine(imgDir.FullName, string.Format("topo.{0}.{1}.png", Xs, Zs)));

            bit.Save(SaveBitMap, System.Drawing.Imaging.ImageFormat.Png);
            bit.Dispose();
        }
コード例 #2
0
        public static void RenderBlockPngFromRegion(byte[][] TopoData, Color[] BlockData, string ImgPath, int Xs, int Zs)
        {
            byte[] hMap = TopoData[0];
            byte[] wMap = TopoData[1];

            Bitmap bit = new Bitmap(512, 512);

            Color[][] pal  = Palettes();
            Color[]   tRGB = pal[0];
            Color[]   wRGB = pal[1];

            for (int zz = 0; zz < 512; zz++)
            {
                for (int xx = 0; xx < 512; xx++)
                {
                    int gI = (zz * 512) + xx;

                    if (wMap[gI] < 255)
                    {
                        if (zz > 1)
                        {
                            int cI = ((zz - 1) * 512) + xx;

                            if (hMap[cI] > hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(25, 25, 175), 0));
                            }
                            else if (hMap[cI] < hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(75, 75, 255), 0));
                            }
                            else
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(50, 50, 200), 0));
                            }
                        }
                        else
                        {
                            int cI = ((zz + 1) * 512) + xx;

                            if (hMap[cI] > hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(75, 75, 255), 0));
                            }
                            else if (hMap[cI] < hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(25, 25, 175), 0));
                            }
                            else
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(50, 50, 200), 0));
                            }
                        }
                    }
                    //if (xx > 1 && xx < 511 && zz > 1 && zz < 511)
                    //{
                    //    int cI = ((zz - 1) * 512) + xx - 1;

                    //     if (hMap[cI] > hMap[gI])
                    //        bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(25, 25, 175), 0));
                    //    else if (hMap[cI] < hMap[gI])
                    //        bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(75, 75, 255), 0));
                    //    else
                    //        bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(50, 50, 200), 0));
                    //}
                    //else
                    //    bit.SetPixel(xx, zz, ColorStep.MixColors(10, BlockData[gI], Color.FromArgb(50, 50, 200), 0));
                    else
                    {
                        if (zz > 1)
                        {
                            int cI = ((zz - 1) * 512) + xx;

                            if (hMap[cI] > hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, BlockData[gI], Color.FromArgb(80, 80, 80), 0));
                            }
                            else if (hMap[cI] < hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, BlockData[gI], Color.FromArgb(200, 200, 200), 0));
                            }
                            else
                            {
                                bit.SetPixel(xx, zz, BlockData[gI]);
                            }
                        }
                        else
                        {
                            int cI = ((zz + 1) * 512) + xx;

                            if (hMap[cI] > hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, BlockData[gI], Color.FromArgb(80, 80, 80), 0));
                            }
                            else if (hMap[cI] < hMap[gI])
                            {
                                bit.SetPixel(xx, zz, ColorStep.MixColors(0, BlockData[gI], Color.FromArgb(200, 200, 200), 0));
                            }
                            else
                            {
                                bit.SetPixel(xx, zz, BlockData[gI]);
                            }
                        }
                    }
                }
            }



            DirectoryInfo imgDir     = new DirectoryInfo(ImgPath);
            string        SaveBitMap = string.Format(Path.Combine(imgDir.FullName, string.Format("tile.{0}.{1}.png", Xs, Zs)));

            bit.Save(SaveBitMap, System.Drawing.Imaging.ImageFormat.Png);
            bit.Dispose();
        }