Histogram.cpp
上传用户:zbjinju
上传日期:2022-07-30
资源大小:11893k
文件大小:1k
源码类别:

图形图象

开发平台:

Visual C++

  1. // Histogram.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "DibLook.h"
  5. #include "Histogram.h"
  6. // CHistogram
  7. IMPLEMENT_DYNAMIC(CHistogram, CStatic)
  8. CHistogram::CHistogram()
  9. {
  10. }
  11. CHistogram::~CHistogram()
  12. {
  13. }
  14. BEGIN_MESSAGE_MAP(CHistogram, CStatic)
  15. ON_WM_PAINT()
  16. END_MESSAGE_MAP()
  17. // CHistogram message handlers
  18. void CHistogram::OnPaint()
  19. {
  20. CPaintDC dc(this); // device context for painting
  21. CPen pen(PS_SOLID, 1, RGB(255,0,0));
  22. CPen *pTempPen = dc.SelectObject(&pen);
  23. CRect rect;
  24. GetClientRect(rect);
  25. int height = rect.Height();
  26. int width = rect.Width();
  27. int i;
  28. int maxValue = 0;
  29. for(i=0; i<256; ++i)
  30. if(values[i] > maxValue)
  31. maxValue = values[i];
  32. double scaleFactor = 1.0;
  33. if(maxValue >= height){
  34. scaleFactor = (double)height/maxValue;
  35. }
  36. for(i=0; i<256; ++i){
  37. int lengthLine = (int)(scaleFactor * values[i]);
  38. dc.MoveTo(i, height);
  39. dc.LineTo(i, height-lengthLine);
  40. }
  41. dc.SelectObject(pTempPen);
  42. }