I am using VC++ 2008. I want to rotate the Bitmap in my MFC application. I tried the GetPixel and SetPixel functions, but the performance is too slow. There seems no Bitmap rotation example using MFC class on the internet
Can anyone give me some idea? Sample code will be appreciated.

Thank in advance!

I am using VC++ 2008. I want to rotate the Bitmap in my MFC application. I tried the GetPixel and SetPixel functions, but the performance is too slow. There seems no Bitmap rotation example using MFC class on the internet
Can anyone give me some idea? Sample code will be appreciated.

Thank in advance!

Your bitmap will be represented by an array of pixel data eg.
pixel SrcBitmap[x][y]; // I made that up by the way but the theory is right

where x = bitmap width and Y is height. What you need to do is create a new bitmap array
eg.
pixel DestBitmap[y][x]; // for 90 degree rotation

and copy the data locations from the original bitmap to the new bitmap.

//Rotate one pixel at a time 
for (int x=0;x<width;x++) 
{ 
    for(int y=0;y<height;y++) 
    { 
    DestBitmap[y][width-1-x] = SrcBitmap[x][y]; 
    } 
}

basically swap the x and y coords.

Edited 6 Years Ago by mattjbond: n/a

This article has been dead for over six months. Start a new discussion instead.