I have an SDI mfc application in which a bitmap image loaded, i want to rotate that bitmap 90Deg, 180Deg & 270Deg. Am able to rotate it 180 degree. But am stuck at 90 and 270 deg. Here is the code.
void CBmpView::OnRotate180()
{
BYTE ptempBit ;
CBmpViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int nLenght = (pDoc->dwBitsSize);
if(pBitsView != NULL){
DeleteObject(pBitsView);
}
if(pDoc->m_bRotationFlag == FALSE){
pDoc->m_bmpHandle = CreateDIBSection(NULL, pDoc->m_bitmapinfo,DIB_RGB_COLORS,
(void **)&pBitsView, NULL, 0);
CopyMemory(pBitsView,pDoc->m_pBits,pDoc->dwBitsSize);
for(int i=0; i < ((nLenght-1)) ; i++ ){
ptempBit = pBitsView[i];
pBitsView[i] = pBitsView[nLenght - 1];
pBitsView[nLenght - 1] = ptempBit;
nLenght --;
}
pDoc->m_bRotationFlag = TRUE;
Invalidate();
}else if(pDoc->m_bRotationFlag == TRUE){
pDoc->m_bmpHandle = CreateDIBSection(NULL, pDoc->m_bitmapinfo,DIB_RGB_COLORS,
(void **)&pBitsView, NULL, 0);
CopyMemory(pBitsView,pDoc->m_pBits,pDoc->dwBitsSize);
pDoc->m_bRotationFlag = FALSE;
Invalidate();
}
}
Please tell me if any other method can be used. Thanks in advance