I want to load a palette from a bitmap file I have created. The file is 256 px wide and 1 px high.
I use
BitmapImage image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri("image.bmp", UriKind.RelativeOrAbsolute);
image.EndInit();
myPalette = new BitmapPalette(image, 256);
The strange thing is, that the Count property of myPalette.Colors is only 244!
Is there something wrong with my code?
There is nothing wrong with your code – BitmapPalette returns up to the number of colors specified. From here: http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmappalette.aspx
I created a test bitmap with the same dimensions and a single color, and
myPalette.Colors.Countreturned 1.Note however that you may actually want to use
BitmapfromSystem.Drawing, much simpler and this returns the full palette list (256) even if they are all the same:With the same test as above, that returns 256 entries