I was afraid that my suggestion to "think a bit" could possibly offend you a bit, so I probably have to illustrate what this thinking could mean.
Suppose you have some bit data, which tells you (forget the "format", it is irrelevant):
you have
width = 3, height = 2, and pixels data 123456
It means that first line is 123 and the second line is 456:
123
456
If you swap width and height, you would have
width = 2, height = 3:
12
34
56
But turn original picture 90° clockwise (you can just turn your computer screen 90° clockwise and look at the same numbers), what will you see? apparently,
41
52
63
and counterclickwise:
36
25
14
The last two images are correct, and the previous one is "corrupted". What could be not obvious here?
This is what nv3 meant by telling you "to rotate the bitmap data pixel by pixel".
I hope now the problem should be clear to you.
—SA