ComparePhoto.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 dialog
  13. CComparePhoto::CComparePhoto(CWnd* pParent /*=NULL*/)
  14. : CDialog(CComparePhoto::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CComparePhoto)
  17. // NOTE: the ClassWizard will add member initialization here
  18. m_pImage=m_pImage2=m_pImage3=m_pImage4=NULL;
  19. //}}AFX_DATA_INIT
  20. }
  21. void CComparePhoto::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CComparePhoto)
  25. // NOTE: the ClassWizard will add DDX and DDV calls here
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(CComparePhoto, CDialog)
  29. //{{AFX_MSG_MAP(CComparePhoto)
  30. ON_WM_PAINT()
  31. ON_WM_DESTROY()
  32. ON_WM_ERASEBKGND()
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CComparePhoto message handlers
  37. BOOL CComparePhoto::OnEraseBkgnd(CDC* pDC)
  38. {
  39. // TODO: Add your message handler code here and/or call default
  40. return 1;
  41. }
  42. BOOL CComparePhoto::OnInitDialog()
  43. {
  44. CDialog::OnInitDialog();
  45. // TODO: Add extra initialization here
  46. ::LoadImageFromBuf(&m_pImage, m_path1);
  47. ::LoadImageFromBuf(&m_pImage2, m_path2);
  48. if(m_path3!="")::LoadImageFromBuf(&m_pImage3, m_path3);
  49. if(m_path4!="")::LoadImageFromBuf(&m_pImage4, m_path4);
  50. int orientation=GetOrientation(m_pImage);
  51. if(orientation==8)
  52. {
  53. m_pImage->RotateFlip( Rotate270FlipNone );
  54. }
  55. else if(orientation==6)
  56. {
  57. m_pImage->RotateFlip( Rotate90FlipNone );
  58. }
  59. orientation=GetOrientation(m_pImage2);
  60. if(orientation==8)
  61. {
  62. m_pImage2->RotateFlip( Rotate270FlipNone );
  63. }
  64. else if(orientation==6)
  65. {
  66. m_pImage2->RotateFlip( Rotate90FlipNone );
  67. }
  68. orientation=GetOrientation(m_pImage3);
  69. if(orientation==8)
  70. {
  71. m_pImage3->RotateFlip( Rotate270FlipNone );
  72. }
  73. else if(orientation==6)
  74. {
  75. m_pImage3->RotateFlip( Rotate90FlipNone );
  76. }
  77. orientation=GetOrientation(m_pImage4);
  78. if(orientation==8)
  79. {
  80. m_pImage4->RotateFlip( Rotate270FlipNone );
  81. }
  82. else if(orientation==6)
  83. {
  84. m_pImage4->RotateFlip( Rotate90FlipNone );
  85. }
  86. ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_screenwid,g_screenhei,SWP_SHOWWINDOW);
  87. return TRUE; // return TRUE unless you set the focus to a control
  88. // EXCEPTION: OCX Property Pages should return FALSE
  89. }
  90. void CComparePhoto::OnPaint()
  91. {
  92. CPaintDC dc(this); // device context for painting
  93. // TODO: Add your message handler code here
  94. try
  95. {
  96. CRect rc,rc2,rc3,rc4;
  97. GetClientRect(rc);
  98. rc2=rc;
  99. int wid=rc.Width ();
  100. int hei=rc.Height ();
  101. if(m_pImage && m_pImage2 && m_pImage3==NULL)
  102. {
  103. rc.right -=wid/2;
  104. rc2.left +=wid/2-2;
  105. Graphics graph(dc.GetSafeHdc ());
  106. graph.Clear(Color(255,0,0,0));
  107. int width=m_pImage->GetWidth();
  108. int height=m_pImage->GetHeight();
  109. RectFitDes(width, height, rc);
  110. Rect destinationRect( rc.left , rc.top , rc.Width (), rc.Height () );
  111. graph.DrawImage(m_pImage, destinationRect, 0,0,width,height,UnitPixel);
  112. width=m_pImage2->GetWidth();
  113. height=m_pImage2->GetHeight(); RectFitDes(width, height, rc2);
  114. Rect destinationRect2( rc2.left , rc2.top , rc2.Width (), rc2.Height () );
  115. graph.DrawImage(m_pImage2, destinationRect2, 0,0,width,height,UnitPixel);
  116. }
  117. else if(m_pImage && m_pImage2 && m_pImage3)
  118. {
  119. rc3=rc;rc4=rc;
  120. rc.right -=wid/2;
  121. rc.bottom -=hei/2;
  122. rc2.left +=wid/2-2;
  123. rc2.bottom =rc.bottom;
  124. rc3.top=rc.bottom;
  125. rc4.top=rc.bottom;
  126. rc3.right=rc.right;
  127. rc4.left=rc2.left;
  128. Graphics graph(dc.GetSafeHdc ());
  129. graph.Clear(Color(255,0,0,0));
  130. int width=m_pImage->GetWidth();
  131. int height=m_pImage->GetHeight();
  132. RectFitDes(width, height, rc);
  133. Rect destinationRect( rc.left , rc.top , rc.Width (), rc.Height () );
  134. graph.DrawImage(m_pImage, destinationRect, 0,0,width,height,UnitPixel);
  135. width=m_pImage2->GetWidth();
  136. height=m_pImage2->GetHeight(); RectFitDes(width, height, rc2);
  137. Rect destinationRect2( rc2.left , rc2.top , rc2.Width (), rc2.Height () );
  138. graph.DrawImage(m_pImage2, destinationRect2, 0,0,width,height,UnitPixel);
  139. if(m_pImage3)
  140. {
  141. width=m_pImage3->GetWidth();
  142. height=m_pImage3->GetHeight(); RectFitDes(width, height, rc3);
  143. Rect destinationRect2( rc3.left , rc3.top , rc3.Width (), rc3.Height () );
  144. graph.DrawImage(m_pImage3, destinationRect2, 0,0,width,height,UnitPixel);
  145. }
  146. if(m_pImage4)
  147. {
  148. width=m_pImage4->GetWidth();
  149. height=m_pImage4->GetHeight(); RectFitDes(width, height, rc4);
  150. Rect destinationRect2( rc4.left , rc4.top , rc4.Width (), rc4.Height () );
  151. graph.DrawImage(m_pImage4, destinationRect2, 0,0,width,height,UnitPixel);
  152. }
  153. }
  154. else
  155. {
  156. // dc.FillSolidRect (rc, 0);
  157. }
  158. }
  159. catch(...)
  160. {
  161. }
  162. // Do not call CDialog::OnPaint() for painting messages
  163. }
  164. void CComparePhoto::OnDestroy()
  165. {
  166. // TODO: Add your message handler code here
  167. if(m_pImage)delete m_pImage;
  168. if(m_pImage2)delete m_pImage2;
  169. if(m_pImage3)delete m_pImage3;
  170. if(m_pImage4)delete m_pImage4;
  171. CDialog::OnDestroy();
  172. }