Alex Rivera | Logout

Travel through pixels in BMP

Asked 2011-05-16T16:30:21.367
30

enter image description here

Hi i have a bmp loaded to a BMP object and im required to travel though the pixels as the above image from (1,1) pixel to (100,100) px . using getpixel() method. I was using was ONE loop but it was not successful .

If im using the concept of multidimensional array what should be variable values ?

Edit
Report

1 Answer

9

if you want to traverse it right, left, right, ... in one loop, this would do it:

for (int i = 0 ; i < bmp.Height * bmp.Width; ++i) {
    int row = i / bmp.Height;
    int col = i % bmp.Width;
    if (row%2 != 0) col = bmp.Width - col-1;
    var pixel = bmp.GetPixel(col, row);
}
answered 2011-05-25T14:27:02.030

Your Answer