当前位置:网站首页>Image matrix transformation in gdi+

Image matrix transformation in gdi+

2022-06-09 12:45:00 litanyuan

background

Graph transformation refers to the translation of the drawn graph 、 rotate 、 Telescoping and other operations , from Graphics Class provides corresponding member functions for implementation .

stay GDI+ in , The matrix involved in matrix transformation , By a special matrix class Matrix To express , It's a 3x3 Matrix .

Translation transformation

void DemoGDI::DrawUser(HDC hdc)
{
    
  Graphics graphics(hdc);// structure  Graphics  object 
  Pen m_pen(Color::Blue, 2);
  Rect m_rect(30, 30, 180, 120);

  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 

  Matrix m_matrix;// Unit rectangle 
  m_matrix.Translate(10, 20);// translation 
  graphics.SetTransform(&m_matrix);// Set the matrix transformation 
  
  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 
  
}

 Insert picture description here

Rotation transformation

void DemoGDI::DrawUser(HDC hdc)
{
    
  Graphics graphics(hdc);// structure  Graphics  object 
  Pen m_pen(Color::Blue, 2);
  Rect m_rect(30, 30, 180, 120);

  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 

  Matrix m_matrix;// Unit rectangle 
  m_matrix.Rotate(10);// rotate 10
  graphics.SetTransform(&m_matrix);// Set the matrix transformation 
  
  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 
  
}

 Insert picture description here

Specify point rotation

void DemoGDI::DrawUser(HDC hdc)
{
    
  Graphics graphics(hdc);// structure  Graphics  object 
  Pen m_pen(Color::Blue, 2);
  Rect m_rect(30, 30, 180, 120);

  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 

  Matrix m_matrix;// Unit rectangle 
  m_matrix.RotateAt(20, PointF(120, 75));// Rotate around the center 
  graphics.SetTransform(&m_matrix);// Set the matrix transformation 
  
  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 
  
}

 Insert picture description here

Scaling transformation

void DemoGDI::DrawUser(HDC hdc)
{
    
  Graphics graphics(hdc);// structure  Graphics  object 
  Pen m_pen(Color::Blue, 2);
  Rect m_rect(30, 30, 180, 120);

  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 

  Matrix m_matrix;// Unit rectangle 
  m_matrix.Scale(0.3f,0.3f);// Projection transformation 
  graphics.SetTransform(&m_matrix);// Set the matrix transformation 
  
  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 
  
}

 Insert picture description here

Projection transformation

void DemoGDI::DrawUser(HDC hdc)
{
    
  Graphics graphics(hdc);// structure  Graphics  object 
  Pen m_pen(Color::Blue, 2);
  Rect m_rect(30, 30, 180, 120);

  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 

  Matrix m_matrix;// Unit rectangle 
  m_matrix.Shear(0.5f,0.5f);// Projection transformation 
  graphics.SetTransform(&m_matrix);// Set the matrix transformation 
  
  graphics.DrawRectangle(&m_pen, m_rect);// Draw a rectangle 
  
}

 Insert picture description here

 Insert picture description here

原网站

版权声明
本文为[litanyuan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091152531782.html