设为首页 加入收藏

TOP

17.9.3 电子相册浏览模块的设计与实现(4)
2013-10-07 14:39:46 来源: 作者: 【 】 浏览:58
Tags:17.9.3 电子相册 浏览 模块 设计 实现

17.9.3  电子相册浏览模块的设计与实现(4)

【代码解析】

m_pGPage在PraparePage()函数中会将相应的相片绘制到4个参与翻动的页面。

(5)PrapatePage()函数将开始的4张相片分别绘制到4个参与翻动的页面上。

  1. 01  void CMyBookDlg::PraparePage()  
  2. 02  {  
  3. 03      Color clrPen(255,0,0,0);  
  4. 04      Pen penDraw(clrPen,1 );  
  5. 05      SolidBrush solidBrush(Color(255, 255, 255, 255));  
  6. 06      m_pGPage[0]->DrawRectangle(&penDraw,m_rectPL.left,m_rectPL.top,  
  7. 07                                  m_rectPL.Width(),m_rectPL.Height());  
  8. 08      //相片的宽度大于高度  
  9. 09      if(m_pImage[0]->GetWidth()/float(m_rectPL.Width()) >=  
  10. 10          m_pImage[0]->GetHeight()/float(m_rectPL.Height()))    
  11. 11      {   //相片的宽度比大于高度比时按照宽度比绘制  
  12. 12          m_rectPLm_rectPL.right = m_rectPL.left + m_rectPL.Width();  
  13. 13          int temp_height = (float(m_rectPL.Width())/  
  14. 14                          m_pImage[0]->GetWidth())*m_pImage[0]-> 
  15.                             GetHeight();  
  16. 15          m_rectPL.top += (m_rectPL.Height() - temp_height) / 2;  
  17.                                                         //计算高度  
  18. 16          m_rectPLm_rectPL.bottom = m_rectPL.top + temp_height;  
  19. 17          m_pGPage[0]->DrawImage(m_pImage[0],m_rectPL.left +1 ,m_   
  20.             rectPL.top +1,  
  21. 18                                  m_rectPL.Width() -1 ,m_rectPL.Height()   
  22.                                     -1);  
  23. 19      }  
  24. 20      else  
  25. 21      {   //相片的高度大于宽度比时按照宽度比绘制图像  
  26. 22          m_rectPLm_rectPL.bottom = m_rectPL.top + m_rectPL.Height();  
  27. 23          int temp_width  = (float(m_rectPL.Height())/  
  28. 24                          m_pImage[0]->GetHeight())*m_pImage[0]->Get-  
  29.                             Width();  
  30. 25          m_rectPL.left +=(m_rectPL.Width()-temp_width)/2;; //计算宽度  
  31. 26          m_rectPLm_rectPL.right = m_rectPL.left + temp_width   
  32. 27          m_pGPage[0]->DrawImage(m_pImage[0],m_rectPL.left +1 ,m_  
  33.             rectPL.top +1,  
  34. 28                                  m_rectPL.Width() -1 ,m_rectPL.Height()                                  -1);  
  35. 29      }  
  36. 30  …       //页面2、3、4的绘制方法同上  
  37. 31  }  

【代码解析】

PraparePage()函数主要是根据图像的宽度比与高度比来绘制图像,当图像的宽度比大于高度比时说明图像在相框中宽占满整个相框,而高则不足,需要根据宽度比计算。当高度比大于宽度比时,则相反,如图17.39所示。

 
图17.39  高度比与宽度比

(6)在对话框初始化函数中定义一个定时器:

  1. 01  BOOL CMyBookDlg::OnInitDialog()   
  2. 02  {  
  3. 03      PraparePage();  
  4. 04      SetTimer(m_hWnd,1,100,NULL);        //开始定时器  
  5. 05  }  

实现定时器函数,增加m_x并重绘界面。
  1. 01  void CMyBookDlg::OnTimer(UINT nIDEvent)   
  2. 02  {  
  3. 03      if(m_bAuto || m_bTOnce)  
  4. 04      {  
  5. 05          m_x+= 20;               //增加m_x  
  6. 06      }  
  7. 07      CRect rect(m_photoFrameLeft,0, m_photoFrameLeft + 1080,m_photo  
  8.         FrameTop + 600);  
  9. 08      InvalidateRect(rect);       //重绘相册  
  10. 09      CDialog::OnTimer(nIDEvent);  
  11. 10  }  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇17.9.3 电子相册浏览模块的设计与.. 下一篇17.9.3 电子相册浏览模块的设计与..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: