ComparePhoto.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // ComparePhoto.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ComparePhoto.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. CComparePhoto::CComparePhoto(CWnd* pParent /*=NULL*/)
  13. : CDialog(CComparePhoto::IDD, pParent)
  14. {
  15. m_pImage = m_pImage2 = m_pImage3 = m_pImage4 = NULL;
  16. }
  17. void CComparePhoto::DoDataExchange(CDataExchange* pDX)
  18. {
  19. CDialog::DoDataExchange(pDX);
  20. }
  21. BEGIN_MESSAGE_MAP(CComparePhoto, CDialog)
  22. //{{AFX_MSG_MAP(CComparePhoto)
  23. ON_WM_PAINT()
  24. ON_WM_DESTROY()
  25. ON_WM_ERASEBKGND()
  26. //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28. /////////////////////////////////////////////////////////////////////////////
  29. BOOL CComparePhoto::OnEraseBkgnd(CDC* pDC)
  30. {
  31. return 1;
  32. }
  33. BOOL CComparePhoto::OnInitDialog()
  34. {
  35. CDialog::OnInitDialog();
  36. ::LoadImageFromBuf(&m_pImage, m_path1);
  37. ::LoadImageFromBuf(&m_pImage2, m_path2);
  38. if (m_path3 != "")::LoadImageFromBuf(&m_pImage3, m_path3);
  39. if (m_path4 != "")::LoadImageFromBuf(&m_pImage4, m_path4);
  40. int orientation = GetOrientation(m_pImage);
  41. if (orientation == 8)
  42. {
  43. m_pImage->RotateFlip(Rotate270FlipNone);
  44. }
  45. else if (orientation == 6)
  46. {
  47. m_pImage->RotateFlip(Rotate90FlipNone);
  48. }
  49. orientation = GetOrientation(m_pImage2);
  50. if (orientation == 8)
  51. {
  52. m_pImage2->RotateFlip(Rotate270FlipNone);
  53. }
  54. else if (orientation == 6)
  55. {
  56. m_pImage2->RotateFlip(Rotate90FlipNone);
  57. }
  58. orientation = GetOrientation(m_pImage3);
  59. if (orientation == 8)
  60. {
  61. m_pImage3->RotateFlip(Rotate270FlipNone);
  62. }
  63. else if (orientation == 6)
  64. {
  65. m_pImage3->RotateFlip(Rotate90FlipNone);
  66. }
  67. orientation = GetOrientation(m_pImage4);
  68. if (orientation == 8)
  69. {
  70. m_pImage4->RotateFlip(Rotate270FlipNone);
  71. }
  72. else if (orientation == 6)
  73. {
  74. m_pImage4->RotateFlip(Rotate90FlipNone);
  75. }
  76. ::SetWindowPos(m_hWnd, HWND_TOP, 0, 0, g_screenwid, g_screenhei, SWP_SHOWWINDOW);
  77. return TRUE;
  78. }
  79. void CComparePhoto::OnPaint()
  80. {
  81. CPaintDC dc(this); // device context for painting
  82. try
  83. {
  84. CRect rc, rc2, rc3, rc4;
  85. GetClientRect(rc);
  86. rc2 = rc;
  87. int wid = rc.Width();
  88. int hei = rc.Height();
  89. if (m_pImage && m_pImage2 && m_pImage3 == NULL)
  90. {
  91. rc.right -= wid / 2;
  92. rc2.left += wid / 2 - 2;
  93. Graphics graph(dc.GetSafeHdc());
  94. graph.Clear(Color(255, 0, 0, 0));
  95. int width = m_pImage->GetWidth();
  96. int height = m_pImage->GetHeight();
  97. RectFitDes(width, height, rc);
  98. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  99. graph.DrawImage(m_pImage, destinationRect, 0, 0, width, height, UnitPixel);
  100. width = m_pImage2->GetWidth();
  101. height = m_pImage2->GetHeight(); RectFitDes(width, height, rc2);
  102. Rect destinationRect2(rc2.left, rc2.top, rc2.Width(), rc2.Height());
  103. graph.DrawImage(m_pImage2, destinationRect2, 0, 0, width, height, UnitPixel);
  104. }
  105. else if (m_pImage && m_pImage2 && m_pImage3)
  106. {
  107. rc3 = rc; rc4 = rc;
  108. rc.right -= wid / 2;
  109. rc.bottom -= hei / 2;
  110. rc2.left += wid / 2 - 2;
  111. rc2.bottom = rc.bottom;
  112. rc3.top = rc.bottom;
  113. rc4.top = rc.bottom;
  114. rc3.right = rc.right;
  115. rc4.left = rc2.left;
  116. Graphics graph(dc.GetSafeHdc());
  117. graph.Clear(Color(255, 0, 0, 0));
  118. int width = m_pImage->GetWidth();
  119. int height = m_pImage->GetHeight();
  120. RectFitDes(width, height, rc);
  121. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  122. graph.DrawImage(m_pImage, destinationRect, 0, 0, width, height, UnitPixel);
  123. width = m_pImage2->GetWidth();
  124. height = m_pImage2->GetHeight(); RectFitDes(width, height, rc2);
  125. Rect destinationRect2(rc2.left, rc2.top, rc2.Width(), rc2.Height());
  126. graph.DrawImage(m_pImage2, destinationRect2, 0, 0, width, height, UnitPixel);
  127. if (m_pImage3)
  128. {
  129. width = m_pImage3->GetWidth();
  130. height = m_pImage3->GetHeight(); RectFitDes(width, height, rc3);
  131. Rect destinationRect2(rc3.left, rc3.top, rc3.Width(), rc3.Height());
  132. graph.DrawImage(m_pImage3, destinationRect2, 0, 0, width, height, UnitPixel);
  133. }
  134. if (m_pImage4)
  135. {
  136. width = m_pImage4->GetWidth();
  137. height = m_pImage4->GetHeight(); RectFitDes(width, height, rc4);
  138. Rect destinationRect2(rc4.left, rc4.top, rc4.Width(), rc4.Height());
  139. graph.DrawImage(m_pImage4, destinationRect2, 0, 0, width, height, UnitPixel);
  140. }
  141. }
  142. else
  143. {
  144. // dc.FillSolidRect (rc, 0);
  145. }
  146. }
  147. catch (...)
  148. {
  149. }
  150. // Do not call CDialog::OnPaint() for painting messages
  151. }
  152. void CComparePhoto::OnDestroy()
  153. {
  154. if (m_pImage)delete m_pImage;
  155. if (m_pImage2)delete m_pImage2;
  156. if (m_pImage3)delete m_pImage3;
  157. if (m_pImage4)delete m_pImage4;
  158. CDialog::OnDestroy();
  159. }