I am trying to rotate images via SetWorldTransform, but its not working...
Below is the code i have written. It is in its simplest form, but still cant make it to work.. any help appreciated in advance..
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 );
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);
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;
HBITMAP hbmResult = ::CreateCompatibleBitmap(CClientDC(NULL), w, h);
HBITMAP hbmOldSource = (HBITMAP)::SelectObject( sourceDC.m_hDC, hBitmap );
HBITMAP hbmOldDest = (HBITMAP)::SelectObject( destDC.m_hDC, hbmResult );
HBRUSH hbrBack = CreateSolidBrush( RGB(0,0,0) );
HBRUSH hbrOld = (HBRUSH)::SelectObject( destDC.m_hDC, hbrBack );
::DeleteObject( ::SelectObject( destDC.m_hDC, hbrOld ) );
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 );
destDC.BitBlt(0,0,bm.bmWidth, bm.bmHeight, &sourceDC, 0, 0, SRCCOPY) ;
pDC->BitBlt(0, 0,bm.bmWidth, bm.bmHeight, &destDC, 0, 0, SRCCOPY);
::SelectObject( sourceDC.m_hDC, hbmOldSource );
::SelectObject( destDC.m_hDC, hbmOldDest );