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.

Check this link for some more infor on rotation. These methods will still be pretty slow, especially for large bitmaps. Normally graphics card manufacturers will provide optimised api functions for handling rotations.

http://www.leunen.com/cbuilder/rotbmp.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.