예제 #1
0
        public static void ProcessImage(MemoryTexture MemTex, String Filename, GraphicsDevice Device)
        {
            var palette = TextureTool.OptimizedPaletteFromMemoryTexture(MemTex);

            palette.Sort((a, b) => (a.R + a.G + a.B) - (b.R + b.G + b.B));

            for (var r = 0; r < MemTex.Height; ++r)
            {
                for (var c = 0; c < MemTex.Width; ++c)
                {
                    var index        = MemTex.Index(c, r);
                    var color        = MemTex.Data[index];
                    var paletteIndex = palette.IndexOf(color);
                    MemTex.Data[index] = new Color(32 * paletteIndex, 32 * paletteIndex, 32 * paletteIndex);
                }
            }

            for (var c = 0; c < palette.Count; ++c)
            {
                MemTex.Data[MemTex.Index(c, 0)] = palette[c];
            }

            TextureTool.Texture2DFromMemoryTexture(Device, MemTex).SaveAsPng(System.IO.File.OpenWrite(Filename), MemTex.Width, MemTex.Height);
        }