void CGdiexampleDlg::OnTransformationMatrix() { // TODO: Add your command handler code here CClientDC dc(this); //創(chuàng)建Graphics對象 Graphics graphics(dc); GraphicsPath path; path.AddRectangle(Rect(250, 20, 70, 70)); graphics.DrawPath(&Pen(Color::Black, 1), &path); // 在應(yīng)用變形矩陣之前繪制矩形 // 路徑變形 Matrix matrix1, matrix2; matrix1.Rotate(45.0f); //旋轉(zhuǎn)順時(shí)針45度 path.Transform(&matrix1); //應(yīng)用變形 graphics.DrawPath(&Pen(Color::Red, 3), &path); matrix2.Scale(1.0f, 0.5f); //轉(zhuǎn)化成為平行四邊形法則 path.Transform(&matrix2); //應(yīng)用變形 graphics.DrawPath(&Pen(Color::Blue, 3), &path); } |
![]() 圖5 GDI+變形和矩陣對象 |
void CGdiexampleDlg::OnScalableRegion() { // TODO: Add your command handler code here CClientDC dc(this); //創(chuàng)建Graphics對象 Graphics graphics(dc); //創(chuàng)建GraphicsPath GraphicsPath path; path.AddLine(100, 100, 150, 150); path.AddLine(50, 150, 150, 150); path.AddLine(50, 150, 100, 100); //創(chuàng)建Region Region region(&path); //填充區(qū)域 graphics.FillRegion(&SolidBrush(Color::Blue), ®ion); //區(qū)域變形 Matrix matrix; matrix.Rotate(10.0f); //旋轉(zhuǎn)順時(shí)針20度 matrix.Scale(1.0f, 0.3f); //拉伸 region.Transform(&matrix); //應(yīng)用變形 //填充變形后的區(qū)域 graphics.FillRegion(&SolidBrush(Color::Green), ®ion); } |
![]() 圖6 GDI+區(qū)域變形 |