【问题标题】:How to draw a CImage on Picture Control? MFC如何在优化校准上绘制 CImage? MFC
【发布时间】:2020-11-05 03:38:47
【问题描述】:

我正在构建一个直方图工具,它将显示实时摄像机输入的直方图。 帧率真的很慢,只有4fps。 我是 MFC 的新手,但从相机制造商那里得到了一个使用 MFC 在图片控件上显示相机输出的示例。在他们那一刻,我一直试图在图片控件上简单地显示一个 CImage。

我得到一个完全黑色的输出。 我做错了什么?

void Capp3Dlg::OnBnClickedbtncalc()
{
int histoWidth = 255;
int histoHeight = 100;
CImage histo;
histo.Create(histoWidth, histoHeight, 8, NULL);

CRect rect; // define a rectangular class
CWnd* pWnd = GetDlgItem(IDC_Histo); //Get the handle of the control
pWnd->GetClientRect(&rect); //Get the handle to the size of the control area
CDC* pDc = pWnd->GetDC(); //Get the DC of the picture

//const int pixSum = histoWidth * histoHeight;
BYTE rValues[25500];
BYTE gValues[25500];
BYTE bValues[25500];
for (int i = 0; i < sizeof(rValues); i++) {
    rValues[i] = 255;
    gValues[i] = 0;
    bValues[i] = 0;
}

for (int h = 0;h < histoHeight;h++)
{
    for (int w = 0;w < histoWidth;w++)
    {
        int index = h * histoWidth + w;
        unsigned char* pucColor = reinterpret_cast<unsigned char*> (histo.GetPixelAddress(w, h));
        pucColor[0] = bValues[index];
        pucColor[1] = gValues[index];
        pucColor[2] = rValues[index];
    }
}

int nWindowW = rect.Width(); 
int nWindowH = rect.Height();   
int nImageW = histo.GetWidth();   
int nImageH = histo.GetHeight(); 
float ratioW = (float)nWindowW / nImageW;
float ratioH = (float)nWindowH / nImageH;
if (ratioW < ratioH)
    histo.Draw(pDc->m_hDC, 0, (int)(nWindowH - nImageH * ratioW) / 2, nWindowW, (int)(nImageH * ratioW), 0, 0, nImageW, nImageH);
else
    histo.Draw(pDc->m_hDC, (int)(nWindowW - nImageW * ratioH) / 2, 0, (int)(nImageW * ratioH), nWindowH, 0, 0, nImageW, nImageH);

ReleaseDC(pDc);
}

【问题讨论】:

    标签: visual-studio visual-c++ computer-vision mfc


    【解决方案1】:

    发现错误。

    CImage.Create 上的 nBpp 必须是 3*8 才能正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 2011-12-08
      • 2019-02-08
      相关资源
      最近更新 更多