急求对话框中画直方图的代码,高分!

解决方案 »

  1.   

    在对话框中插入 MSChart ActiveX控件
      

  2.   

    可以在Picture控件中画图。为picture控件绑定变量m_HsitoFrame
    DrawHistogram()
    {
             CDC*        pDC = m_HistoFrame.GetDC();
    long  Histo;
    long        i, lMaxValue,lStartY;
             CRect rc,rcClient;
              m_HistoFrame.GetWindowRect (&rc);
    lStartY = rc.bottom - rc.top - 2;
    // caculate drawing rect within frame window
    rcClient.left   = 2;
    rcClient.top    = 2;
    rcClient.right  = rc.right  - rc.left - 2;
    rcClient.bottom = rc.bottom - rc.top  - 2;

    // calculate histogramm
    ImageHistogram ((IMG)m_cvdispR.GetImage(), 0, 1000, Area, Histo);//统计像素灰度函数(自己实现) 

    // normalize histogram for drawing
    lMaxValue = 1;
    for (i=0; i<256; i++)
    {
    lMaxValue = max (lMaxValue, Histo[i]);
    }
    for (i=0; i<256; i++)//划定坐标位置
    {
    Histo[i] = Histo[i] * (rcClient.bottom) / lMaxValue;
    }

    // overdraw old histogram
    pDC->FillRect(&rcClient, CBrush::FromHandle((HBRUSH)GetStockObject(LTGRAY_BRUSH)));
    // draw new histogram
    for (i=0; i<256; i++)
    {
    for(int j=0;j<6;j++)//histo width
    {
    pDC->MoveTo (2 + i+j, lStartY);
    pDC->LineTo (2 + i+j, lStartY - Histo[i] + 1);
    }
    }
    // free dc
    m_HistoFrame.ReleaseDC (pDC);
    }