I'm trying to create a mini tool for my job. I'm using C# with Visual Studio 2010 to do that. Now I need to export an image to an act file.
Following here, http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmappalette.aspx
I wrote
class Palette : List<Color>
{
public static Palette GetFromImage(String PathToImage)
{
//Load imgae
BitmapImage image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri(PathToImage, UriKind.RelativeOrAbsolute);
image.EndInit();
//Load palette
BitmapPalette BitmapPalette = new BitmapPalette(image, 256);
//Convert it to list of Color
Palette pal = new Palette();
for (int i = 0; i < BitmapPalette.Colors.Count; i++)
{
pal.Add(Color.FromArgb(BitmapPalette.Colors[i].R, BitmapPalette.Colors[i].G, BitmapPalette.Colors[i].B));
}
//Return the palette has been creatted
return pal;
}
This code has effected, but the order of all colors in the result did not same as the order of all colors when I export by photoshop. So, when I write all colors to a act file, the act file is not correct.
Anybody can help me.
Many thank