简单实用图片任意旋转

const double PI = 3.1415925;
const int widthOfPic = 502;
const int heightOfPic = 374;

void CView::OnDraw(CDC* pDC)
{

 CDCDemoDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 
 CBitmap bmSrc;
 bmSrc.LoadBitmap(IDB_SRC);

 CDC dcSrc;
 dcSrc.CreateCompatibleDC(NULL);
 dcSrc.SelectObject(&bmSrc);

 ::SetGraphicsMode(pDC->GetSafeHdc(), GM_ADVANCED);
    double dbRadian = g_Angle * PI / 180;
    XFORM xForm;
    xForm.eM11 = (FLOAT) cos(dbRadian);
    xForm.eM12 = (FLOAT) sin(dbRadian);
    xForm.eM21 = (FLOAT) -sin(dbRadian);
    xForm.eM22 = (FLOAT) cos(dbRadian);
    xForm.eDx  = (FLOAT) 150;   // 这里是位置,你自己去算
    xForm.eDy  = (FLOAT) 150;   // 同上
    SetWorldTransform(pDC->GetSafeHdc(), &xForm);

 pDC->BitBlt(0, 0, widthOfPic, heightOfPic, &dcSrc, 0, 0, SRCCOPY);
 UpdateData(false);
}

你可能感兴趣的:(简单实用图片任意旋转)