c++ 画图像直方图

 

CClientDC dc(this);   
    CRect rect; 
    GetDlgItem(IDC_PIC)->GetWindowRect(&rect);

    ScreenToClient(rect);
    CPen* pPenBlue = new CPen;               
    pPenBlue->CreatePen(PS_SOLID, 2, RGB(255,255,255)); //蓝色画笔  
    CPen* pPenBlack = new CPen;            
    pPenBlack->CreatePen(PS_SOLID, 1, RGB(0,0,0)); //黑色画笔

    CGdiObject* pOldPen = dc.SelectObject(pPenBlack); //选中黑色画笔,并保存当前画笔

 

 //   //绘制x坐标轴 
    int OriX = rect.left, OriY= rect.bottom;//坐标系原点OriX,OriY  
    CPoint OPos(OriX,OriY),NowPos;  //OPos是原点坐标

 

 //   //绘制x坐标轴 
    int OriX = rect.left, OriY= rect.bottom;//坐标系原点OriX,OriY  
    CPoint OPos(OriX,OriY),NowPos;  //OPos是原点坐标

    //寻找数据数组最大的数据  
    int max = 0; 
    for (int i = 0;i < 328;i++) 
    { 
        if (max < count[i]) 
        { 
            max = count[i]; 
        } 
    } 

    //y轴坐标系数的数据步长  
    int Tstep = max / 10;   //10个数据  
    //y轴坐标系数的刻度步长  
    int Ystep = (OriY-rect.top - 15) / 21; 

 int RealStep = OPos.y-rect.top-(OriY-rect.top-Ystep*21);

 //绘制灰度图像的直方图
    dc.SelectObject(pPenBlue); //选择蓝色画笔  
    for (int i = 0;i < 328;i++) 
    {  
        NowPos.x = OPos.x + i*picStep; 
        NowPos.y = OPos.y; 
        dc.MoveTo(NowPos); 
  NowPos.y = OPos.y - (float)(((float)(RealStep*20))/(21*max))*count[i]; 
        dc.LineTo(NowPos); 
    } 
    //恢复以前的画笔  
    dc.SelectObject(pOldPen); 
    delete pPenBlue; 
    delete pPenBlack; 

 

你可能感兴趣的:(c++ 画图像直方图)