Using C# I was trying to devide a photo in more than Photo. in Each Photo i have a piece colour. The way I am doing it have a problem and need your kind advice. the Problem is my Photo name will have an 8 ARGB Values! but i want just 6 values! i want the filename to take into account the color RGB value without the alpha.
public class PNG2PNGS
{
public static void Convert(string sourcePath)
{
foreach (var fileName in Directory.GetFiles(sourcePath, "*.png"))
{
Bitmap bitmap = new Bitmap(fileName);
List<Color> colors = new List<Color>();
for (int i = 0; i < bitmap.Width; i++)
{
for (int j = 0; j < bitmap.Height; j++)
{
Color color = bitmap.GetPixel(i, j);
if (!colors.Contains(color))
{
colors.Add(color);
}
}
}
foreach (Color color in colors)
{
Bitmap bitmap2 = new Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat);
for (int i = 0; i < bitmap.Width; i++)
{
for (int j = 0; j < bitmap.Height; j++)
{
if (bitmap.GetPixel(i, j) == color)
{
bitmap2.SetPixel(i, j, color);
}
else
{
bitmap2.SetPixel(i, j, Color.Transparent);
}
}
}
bitmap2.Save(Path.Combine(Path.GetDirectoryName(fileName), $"{Path.GetFileNameWithoutExtension(fileName)}_{color.ToArgb().ToString("X6")}.png"), ImageFormat.Png);
}
bitmap.GetPixel(0,0);
}
}
}