private static ImageData LoadFromBitmap(string path, int i, GfxFileReader file) { GfxImage image = file.GetImage(i); Bitmap map = new Bitmap($"export/{path}/{i}.png"); ImageData data = new ImageData(map.Height, map.Width); image.Width = map.Width; image.Height = map.Height; data.data = new Byte[map.Height * map.Width * 4]; int index = 0; for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { Color c = map.GetPixel(x, y); data.data[index + 0] = c.R; data.data[index + 1] = c.G; data.data[index + 2] = c.B; data.data[index + 3] = 255; index += 4; } } return(data); }
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); } }
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()}"); } }
private static ImageData[] LoadFromBitmap(string path, int i, GfxFileReader file) { GfxImage image = file.GetImage(i); bool saveByIndex = file.HasDIL; string basePath = $"export/{path}/{(saveByIndex ? $"{image.jobIndex}/" : "")}"; List <ImageData> imgs = new List <ImageData>(); foreach (string filePath in Directory.GetFiles(basePath)) { Bitmap map = new Bitmap(filePath); ImageData data = new ImageData(map.Height, map.Width); image.Width = map.Width; image.Height = map.Height; data.data = new Byte[map.Height * map.Width * 4]; int index = 0; for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { Color c = map.GetPixel(x, y); data.data[index + 0] = c.R; data.data[index + 1] = c.G; data.data[index + 2] = c.B; data.data[index + 3] = 255; index += 4; } } imgs.Add(data); } return(imgs.ToArray()); }