Consider the following code sample, from msdn,
private void SetPixel_Example(PaintEventArgs e)
{
// Create a Bitmap object from a file.
Bitmap myBitmap = new Bitmap("Grapes.jpg");
// Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, myBitmap.Height);
// Set each pixel in myBitmap to black.
for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
{
for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
{
myBitmap.SetPixel(Xcount, Ycount, Color.Black);
}
}
// Draw myBitmap to the screen again.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, myBitmap.Height);
}
Note that the outer loop in the nest for loop iterates on indexes towards the bitmap's width, and the inner loop iterates on indexes towards the bitmap's height. I saw code snippets of the same style in several other places.
My question is: Does this mean that a Bitmap object stores its pixels information column by column internally, that is, thinking of all pixels as a matrix in the screen, it is stored in the main memory by column, as in programming language Fortran. The reasoning behind this question is to avoid cache miss, nested loop should be arranged according the memory format of a 2-D data structure.