如何解决如何在优化校准上绘制CImage? MFC
我正在构建一个直方图工具,它将显示实时摄像机输入的直方图。 帧速率真的很慢,只有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,(int)(nWindowH - nImageH * ratioW) / 2,nWindowW,(int)(nImageH * ratioW),nImageW,nImageH);
else
histo.Draw(pDc->m_hDC,(int)(nWindowW - nImageW * ratioH) / 2,(int)(nImageW * ratioH),nWindowH,nImageH);
ReleaseDC(pDc);
}
解决方法
发现了错误。
nBpp
上的CImage.Create
必须为3*8
才能正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。