public static byte[] LoadBitmap(Bitmap bmp, ImagePalette palette)
{
byte[] result = new byte[bmp.Width*bmp.Height];
BitmapData data = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
for(int y = 0; y < bmp.Height; y++)
for(int x = 0; x < bmp.Width; x++)
{
byte r = Marshal.ReadByte(data.Scan0, y*data.Stride+x*3);
byte g = Marshal.ReadByte(data.Scan0, y*data.Stride+x*3+1);
byte b = Marshal.ReadByte(data.Scan0, y*data.Stride+x*3+2);
result[y*bmp.Width+x] = (byte)palette.GetNearestColorIndex(Color.FromArgb(r,g,b));
}
return result;
}