If your image is monochrome you may try something like:
int[,] BitmapToMatrix(Bitmap bmp)
{
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.WriteOnly,
bmp.PixelFormat);
int bytesPerPixel = bmpData.Stride / bmp.Width;
int[,] matrix = new int[bmp.Height, bmp.Width];
unsafe
{
for (int i = 0; i < bmp.Height; i++)
{
byte* p = (byte*)bmpData.Scan0.ToPointer() +
(i * bmp.Height) * bmpData.Stride;
for (int j = 0; j < bmp.Width; j++)
{
byte* pixel = p + j * bytesPerPixel;
matrix[i, j] = (int)*pixel;
}
}
}
bmp.UnlockBits(bmpData);
return matrix;
}
If you don't want to use unsafe code, then you may have a look to:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.unlockbits.aspx
If you want to store the colors, then try something like:
Color[,] BitmapToMatrix(Bitmap bmp)
{
Color[,] matrix = new Color[bmp.Height, bmp.Width];
for (int i = 0; i < bmp.Height; i++)
{
for (int j = 0; j < bmp.Width; j++)
{
matrix[i, j] = bmp.GetPixel(j, i);
}
}
return matrix;
}