private static void SaveToBitmap(string path, int i, ICollectionFileReader file) { bool saveByIndex = file.HasDIL; IGfxImage 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; if (index >= data.data.Length) { break; } 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; } } int jobIndex = saveByIndex ? (image as GfxImage).jobIndex : 0; string basePath = $"export/{path}/{(saveByIndex ? $"{jobIndex}/" : "")}"; Directory.CreateDirectory(basePath); b.Bitmap.Save(basePath + $"{i}.png", System.Drawing.Imaging.ImageFormat.Png); } }