Not seen the project but for images you basically have two loops. The image data offset starts at 12, then it's 1 byte per colour (rgba).
So the way I do it you would have two nested loops, the first running 0 to height-1, the second to 1 to width. To get the position for each pixels it's done as such:
Offset=12+(height loop x width x 4) + (width loop x 4)
I've had the same results as you and it's for me been because of miscalculating the y offset......I started it at 1 to height, but that needs to start at 0 for how I do it.