Пример #1
0
        private static void SaveToBitmap(string path, int i, GfxFileReader file)
        {
            bool saveByIndex = file.HasDIL;

            GfxImage image  = file.GetImage(i);
            int      width  = image.Width;
            int      height = image.Height;

            using (DirectBitmap b = new DirectBitmap(image.Width, image.Height)) {
                ImageData data = image.GetImageData();

                int index = 0;
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        int  alpha = 255;
                        byte red   = data.data[index + 0];
                        byte green = data.data[index + 1];
                        byte blue  = data.data[index + 2];

                        if (red == 255 && green + blue == 0)
                        {
                            alpha = removeAlpha ? 0 : alpha;
                        }
                        if (green == 255 && red + blue == 0)
                        {
                            alpha = removeShadows ? 0 : alpha;
                        }
                        else if (onlyShadows)
                        {
                            red   = 0;
                            green = 0;
                            blue  = 0;
                            alpha = 0;
                        }

                        b.SetPixel(x, y, Color.FromArgb(alpha, red, green, blue));

                        index += 4;
                    }
                }

                string basePath = $"export/{path}/{(saveByIndex ? $"{image.jobIndex}/" : "")}";
                Directory.CreateDirectory(basePath);
                b.Bitmap.Save(basePath + $"{i}.png", System.Drawing.Imaging.ImageFormat.Png);
            }
        }
Пример #2
0
        private static void SaveToBitmap(string path, int i, GfxFileReader file)
        {
            GfxImage image  = file.GetImage(i);
            int      width  = image.Width;
            int      height = image.Height;

            using (DirectBitmap b = new DirectBitmap(image.Width, image.Height)) {
                ImageData data = image.GetImageData();

                int index = 0;
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        int  alpha = 255;
                        byte red   = data.data[index + 0];
                        byte green = data.data[index + 1];
                        byte blue  = data.data[index + 2];

                        if (red == 255 && green + blue == 0)
                        {
                            alpha = removeAlpha ? 0 : alpha;
                        }
                        if (green == 255 && red + blue == 0)
                        {
                            alpha = removeShadows ? 0 : alpha;
                        }

                        b.SetPixel(x, y, Color.FromArgb(alpha, red, green, blue));

                        index += 4;
                    }
                }

                Directory.CreateDirectory("export/" + path);
                b.Bitmap.Save($"export/{path}/{i}.png", System.Drawing.Imaging.ImageFormat.Png);
                //if( i % 50 == 0)
                //Console.WriteLine($"Saved {i}/{gfxFile.GetImageCount()}");
            }
        }