2011-08-25 2 views
0

그 위에 그려지는 Rectangle 개체가 포함 된 비트 맵이 있습니다. 비트 맵을 RotateFlip하고 Rectangle의 x, y, 너비 및 높이를 조정하여 각 회전 또는 뒤집기 후에 비트 맵과 정렬되도록하고 싶습니다.사각형 회전 및 뒤집기

예를 들어 1000 x 800 픽셀의 비트 맵이있는 경우 지정된 점과 크기로 사각형 객체를 그릴 수 있습니다.

샘플 코드 :

// A bitmap that's 1000x800 size 
Bitmap bitmap = new Bitmap(fileName); 

// Any arbitrary rectangle that can be drawn inside the bitmap boundaries 
Rectangle rect = new Rectangle(200, 200, 100, 100); 

bitmap.RotateFlip(rotateFlipType); 

switch (rotateFlipType) 
{ 
    case Rotate90FlipNone: 
     // Adjust rectangle to match new bitmap orientation 
     rect = new Rectangle(?, ?, ?, ?); 
     break; 
    case RotateNoneFlip180: 
     rect = new Rectangle(?, ?, ?, ?); 
     break; 
    // ... etc. 
} 
+0

기존 코드? – Randy

+0

여기에 귀하의 질문은 무엇입니까? –

+0

실제 코드는 혼란을 야기하지만 기본 코드는 일반 코드로 전달 될 수 있습니다. 원래 게시물에 추가하겠습니다. –

답변

1

나는 사진 및 라벨 rect.Top, rect.Bottom, rect.Leftrect.Right을 그려 각각의 시나리오를 추론 할 가장 쉬운 방법을 찾을 수 있습니다. 끝나면 정신적으로 사진을 회전 시키거나 물리적으로 종이를 회전시킵니다. 거기에서 새로운 rect.Leftrect.Top이 어디에 살고 있는지 파악하는 것만 큼 간단합니다.

몇 가지 일반적인 팁 :

    90도 및 270도 회전 들어
  • , rect.Widthrect.Height는 교체해야합니다.
  • bitmap.Width-rect.Rightbitmap.Height-rect.Bottom을 사용하여 새로운 상단 또는 왼쪽을 계산하는 것이 가장 쉬운 경우가 많습니다. 여기

는 얻을 채워진 공백과의 두 가지 예는 당신이 시작됩니다

switch (rotateFlipType) 
{ 
    case Rotate90FlipNone: 
     // Adjust rectangle to match new bitmap orientation 
     rect = new Rectangle(bitmap.Height-rect.Bottom, 
          rect.Left, 
          rect.Height, 
          rect.Width); 
     break; 
    case RotateNoneFlipHorizontally: 
     rect = new Rectangle(bitmap.Width - rect.Right, 
          rect.Top, 
          rect.Width, 
          rect.Height); 
     break; 
    // ... etc. 
} 
0

나는 바로이 문제에 직면했다.

여기 내 결과는 - 아마 그들이 다른 사람 하구의 시간을 절약 할 수 ...

void RotateFlipRect(CRect & pRect, int pNewContainerWidth, int pNewContainerHeight, Gdiplus::RotateFlipType pCorrection) 
{ 
    CRect lTemp = pRect; 

    switch (pCorrection) 
    { 
    case RotateNoneFlipNone: // = Rotate180FlipXY 
     break; 
    case   Rotate90FlipNone: // = Rotate270FlipXY 
     pRect.left = lTemp.top; 
     pRect.top = pNewContainerHeight - lTemp.right; 
     pRect.right = lTemp.bottom; 
     pRect.bottom = pNewContainerHeight - lTemp.left; 
     break; 
    case   Rotate180FlipNone: // = RotateNoneFlipXY 
     pRect.left = pNewContainerWidth - lTemp.right; 
     pRect.top = pNewContainerHeight - lTemp.bottom; 
     pRect.right = pNewContainerWidth - lTemp.left; 
     pRect.bottom = pNewContainerHeight - lTemp.top; 
     break; 
    case   Rotate270FlipNone: // = Rotate90FlipXY 
     pRect.left = pNewContainerWidth - lTemp.bottom; 
     pRect.top = lTemp.left; 
     pRect.right = pNewContainerWidth - lTemp.top; 
     pRect.bottom = lTemp.right; 
     break; 
    case   RotateNoneFlipX: // = Rotate180FlipY 
     pRect.left = pNewContainerWidth - lTemp.right; 
     pRect.top = lTemp.top; 
     pRect.right = pNewContainerWidth - lTemp.left; 
     pRect.bottom = lTemp.bottom; 
     break; 
    case   Rotate90FlipX: // = Rotate270FlipY 
     pRect.left = pNewContainerWidth - lTemp.bottom; 
     pRect.top = pNewContainerHeight - lTemp.right; 
     pRect.right = pNewContainerWidth - lTemp.top; 
     pRect.bottom = pNewContainerHeight - lTemp.left; 
     break; 
    case   Rotate180FlipX: // = RotateNoneFlipY 
     pRect.left = lTemp.left; 
     pRect.top = pNewContainerHeight - lTemp.bottom; 
     pRect.right = lTemp.right; 
     pRect.bottom = pNewContainerHeight - lTemp.top; 
     break; 
    case   Rotate270FlipX: // = Rotate90FlipY 
     pRect.left = lTemp.top; 
     pRect.top = lTemp.left; 
     pRect.right = lTemp.bottom; 
     pRect.bottom = lTemp.right; 
     break; 
    default: 
     // ?!??! 
     break; 
    } 
}