GreyDlg.cpp
上传用户:cdscwht
上传日期:2022-07-27
资源大小:264k
文件大小:2k
源码类别:

图形/文字识别

开发平台:

Visual Basic

  1. // GreyDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "dip.h"
  5. #include "GreyDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CGreyDlg dialog
  13. CGreyDlg::CGreyDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CGreyDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CGreyDlg)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. int i;
  20. for(i=0;i<256;i++)
  21. grey[i]=0;
  22. }
  23. void CGreyDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CGreyDlg)
  27. // NOTE: the ClassWizard will add DDX and DDV calls here
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CGreyDlg, CDialog)
  31. //{{AFX_MSG_MAP(CGreyDlg)
  32. ON_WM_PAINT()
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CGreyDlg message handlers
  37. int CGreyDlg::DoModal() 
  38. {
  39. // TODO: Add your specialized code here and/or call the base class
  40. return CDialog::DoModal();
  41. }
  42. void CGreyDlg::OnPaint() 
  43. {
  44. CPaintDC dc(this); // device context for painting
  45. // TODO: Add your message handler code here
  46. //显示背景框
  47. dc.Rectangle(10,10,300,400);
  48. int i;
  49. LONG greymax=0;
  50. for(i=0;i<256;i++)
  51. {
  52. if (grey[i]>greymax) greymax=grey[i];
  53. }
  54. //显示灰度直方图
  55. dc.MoveTo(283,395-int(grey[0]*1.0/greymax*380));
  56. for(i=1;i<256;i++)
  57. {
  58. dc.LineTo(283-i,395-int(grey[i]*1.0/greymax*380));
  59. dc.MoveTo(283-i,395-int(grey[i]*1.0/greymax*380));
  60. }
  61. // Do not call CDialog::OnPaint() for painting messages
  62. }