Thanks Jast_In for your reply...
i actually implemented a code that uses SetWorldTransform, but can't get it working..
below is the code:
int iAngleInDeg = 90;
HBITMAP hBitmap;
CString m_csBitmap;
m_csBitmap = "C://Aircraft.bmp";
hBitmap = (HBITMAP)LoadImage(NULL,m_csBitmap.GetBuffer(m_csBitmap.GetLength()),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
CDC sourceDC, destDC;
sourceDC.CreateCompatibleDC( NULL );
destDC.CreateCompatibleDC( NULL );
// Get logical coordinates
BITMAP bm;
::GetObject( hBitmap, sizeof( bm ), &bm );
float radians = radians=(2*3.1416*iAngleInDeg)/360;
float cosine = (float)cos(radians);
float sine = (float)sin(radians);
// Compute dimensions of the resulting bitmap
// First get the coordinates of the 3 corners other than origin
int x1 = (int)(bm.bmHeight * sine);
int y1 = (int)(bm.bmHeight * cosine);
int x2 = (int)(bm.bmWidth * cosine + bm.bmHeight * sine);
int y2 = (int)(bm.bmHeight * cosine - bm.bmWidth * sine);
int x3 = (int)(bm.bmWidth * cosine);
int y3 = (int)(-bm.bmWidth * sine);
int minx = min(0,min(x1, min(x2,x3)));
int miny = min(0,min(y1, min(y2,y3)));
int maxx = max(0,max(x1, max(x2,x3)));
int maxy = max(0,max(y1, max(y2,y3)));
int w = maxx - minx;
int h = maxy - miny;
// Create a bitmap to hold the result
HBITMAP hbmResult = ::CreateCompatibleBitmap(CClientDC(NULL), w, h);
HBITMAP hbmOldSource = (HBITMAP)::SelectObject( sourceDC.m_hDC, hBitmap );
HBITMAP hbmOldDest = (HBITMAP)::SelectObject( destDC.m_hDC, hbmResult );
// Draw the background color before we change mapping mode
HBRUSH hbrBack = CreateSolidBrush( RGB(0,0,0) );
HBRUSH hbrOld = (HBRUSH)::SelectObject( destDC.m_hDC, hbrBack );
//destDC.PatBlt( 0, 0, w, h, PATCOPY );
::DeleteObject( ::SelectObject( destDC.m_hDC, hbrOld ) );
// We will use world transform to rotate the bitmap
SetGraphicsMode(destDC.m_hDC, GM_ADVANCED);
XFORM xform;
xform.eM11 = cosine;
xform.eM12 = -sine;
xform.eM21 = sine;
xform.eM22 = cosine;
xform.eDx = (float)-minx;
xform.eDy = (float)-miny;
SetWorldTransform( destDC.m_hDC, &xform );
// Now do the actual rotating - a pixel at a time
destDC.BitBlt(0,0,bm.bmWidth, bm.bmHeight, &sourceDC, 0, 0, SRCCOPY) ;
//now draw the rotated bitmap on final DC, i.e. pDC
pDC->BitBlt(0, 0,bm.bmWidth, bm.bmHeight, &destDC, 0, 0, SRCCOPY);
// Restore DCs
::SelectObject( sourceDC.m_hDC, hbmOldSource );
::SelectObject( destDC.m_hDC, hbmOldDest );
Well Eugen Podsypalnikov, Thanks for your reply...
By Not working, I didnt mean that SetWorldTransform and Bitblt are not working. I meant to say that my implementation is not helping me out.. In my case, the Aircraft.bmp is a 17x17 or 35x35 bmp image that is loaded in the very beginning of program.As mentioned in the case of sample code I posted earlier, a sourcedc contains this small bitmap, which is to be rotated onto a destDC and then blitted to a final DC.
If you could copy the code I posted and run it, you will see that its drawing noting although I'm following a step by step implementation.