Histogram.cpp
资源名称:lab5.rar [点击查看]
上传用户:zbjinju
上传日期:2022-07-30
资源大小:11893k
文件大小:1k
源码类别:
图形图象
开发平台:
Visual C++
- // Histogram.cpp : implementation file
- //
- #include "stdafx.h"
- #include "DibLook.h"
- #include "Histogram.h"
- // CHistogram
- IMPLEMENT_DYNAMIC(CHistogram, CStatic)
- CHistogram::CHistogram()
- {
- }
- CHistogram::~CHistogram()
- {
- }
- BEGIN_MESSAGE_MAP(CHistogram, CStatic)
- ON_WM_PAINT()
- END_MESSAGE_MAP()
- // CHistogram message handlers
- void CHistogram::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- CPen pen(PS_SOLID, 1, RGB(255,0,0));
- CPen *pTempPen = dc.SelectObject(&pen);
- CRect rect;
- GetClientRect(rect);
- int height = rect.Height();
- int width = rect.Width();
- int i;
- int maxValue = 0;
- for(i=0; i<256; ++i)
- if(values[i] > maxValue)
- maxValue = values[i];
- double scaleFactor = 1.0;
- if(maxValue >= height){
- scaleFactor = (double)height/maxValue;
- }
- for(i=0; i<256; ++i){
- int lengthLine = (int)(scaleFactor * values[i]);
- dc.MoveTo(i, height);
- dc.LineTo(i, height-lengthLine);
- }
- dc.SelectObject(pTempPen);
- }