public static Microsoft.Xna.Framework.Color[] QuantizeFrame(SPR2Frame frame, out byte[] bytes)
{
var bmps = GetPixelAlpha(frame, frame.Width, frame.Height, new Vector2());
var quantpx = (Bitmap)ImageBuffer.QuantizeImage(bmps[0], new DistinctSelectionQuantizer(), null, 255, 4);
var palt = quantpx.Palette.Entries;
var data = quantpx.LockBits(new System.Drawing.Rectangle(0, 0, quantpx.Width, quantpx.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
bytes = new byte[data.Height * data.Width];
// copy the bytes from bitmap to array
for (int i = 0; i < data.Height; i++)
{
Marshal.Copy(data.Scan0 + i * data.Stride, bytes, i * data.Width, data.Width);
}
var result = new Microsoft.Xna.Framework.Color[palt.Length];
for (int i=0; i<palt.Length; i++)
{
var c = palt[i];
result[i] = new Microsoft.Xna.Framework.Color(c.R, c.G, c.B, c.A);
}
return result;
}