CSharp examples for System.Drawing:Image Operation
Get Palette from Bitmap
using System.Drawing.Imaging; using System.Drawing; using System.Text; using System.Collections.Generic; using System;//w w w . j av a2 s . c o m public class Main{ static public List<Color> GetPalette(Bitmap bitmap) { List<Color> palette = new List<Color>(0x100); if ((bitmap.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) { palette.AddRange(bitmap.Palette.Entries); } else { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { Color color = bitmap.GetPixel(i, j); if (!palette.Contains(color)) { palette.Add(color); } } } } return palette; } }