Ejemplo n.º 1
0
        public static void Merge(FileInfo src, ref Bitmap target, PaletteSet palette)
        {
            Bitmap img = new Bitmap(Image.FromFile(src.FullName));

            if (target == null)
            {
                target = new Bitmap(img.Width, img.Height, img.PixelFormat);
                var transPixel = Color.FromArgb(0, 0, 0, 0);

                for (var y = 0; y < target.Height; y++)
                {
                    for (var x = 0; x < target.Width; x++)
                    {
                        target.SetPixel(x, y, transPixel);
                    }
                }
            }

            for (var y = 0; y < img.Height; y++)
            {
                for (var x = 0; x < img.Width; x++)
                {
                    var pixel = img.GetPixel(x, y);
                    if (pixel.A > 0)
                    {
                        if (palette != null)
                        {
                            pixel = palette.GetColor(pixel);
                        }
                        target.SetPixel(x, y, pixel);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static Bitmap Generate(
            DirectoryInfo source,
            string[] parts,
            FileInfo paletteFile,                               // Can be null
            string imageExtension = ".png"                      // Case insensitive, used for input
            )
        {
            var rand = new System.Random();

            // Enumerate all source files
            var src = new Inputs(source, imageExtension);

            // Read palette info
            PaletteSet palette = null;

            if (paletteFile != null)
            {
                palette = new PaletteSet(paletteFile);
            }

            // Select source files by random
            var srcFiles = new FileInfo[parts.Length];

            for (var i = 0; i < srcFiles.Length; i++)
            {
                var srcSet = src.GetParts(parts[i]);
                srcFiles[i] = srcSet[rand.Next(0, srcSet.Length)];
            }

            // Draw the layers together OMG
            Bitmap target = null;

            for (var i = 0; i < srcFiles.Length; i++)
            {
                ImageMerger.Merge(srcFiles[i], ref target, palette);
            }

            return(target);
        }