How do take a screenshot correctly with xlib?

You are mistaken about the way array is laid out in memory, as you can find out by declaring img before the loop and adding this printf to your inner loop: printf(“%ld %ld %u %u %u\n”,x,y,pic.offset(x,y,0),pic.offset(x,y,1),pic.offset(x,y,2)); This yields (on my 1920×1200 screen): 0 0 0 2304000 4608000 0 1 1920 2305920 4609920 0 2 3840 … Read more