GDI+如何修改图片方向(VC编程)

发布网友

我来回答

1个回答

热心网友

这段代码将图片搬移到窗口中心,在旋转60度。

代码是在MFC的OnDraw函数中的。

注意到GDI+中的矩阵是将自己右乘行向量的。

void CScaleObjectView::OnDraw(CDC* pDC)

{

CScaleObjectDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

if (!pDoc)   return;

static const float fAngle = 3.1415926536f / 3.0f; //旋转角度为60度

static const float fSin = sinf(fAngle);

static const float fCos = cosf(fAngle);

static Matrix matWorld;  //矩阵,用于将对象变换到世界坐标

RECT rcClient;     //客户区域

this->GetClientRect(&rcClient);

float dx = (float)rcClient.right / 2.0f;   //dx dy用于将图片搬移到窗口中心

float dy = (float)rcClient.bottom / 2.0f;

matWorld.SetElements( //该矩阵相当于

fCos,    fSin,      //  Graphics::RotateTransform 乘以

-fSin,   fCos,    //   Graphics::TranslateTransform

dx,      dy);

Graphics g(pDC->GetSafeHdc());

g.SetTransform(&matWorld);

g.DrawImage(

m_bitmap,

-((float)m_bitmap->GetWidth() / 2.0f),

-((float)m_bitmap->GetHeight() / 2.0f));

}

//效果如图:

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com