u014650053
妮儿1
采纳率0%
2015-04-14 13:11 阅读 4.4k

mfc中的picture控件不显示图像

这是我的程序在非mfc中已经能很好的显示图像,但是到了mfc中就显示不出来了,不知道到底是哪里出错了,还望大家帮帮忙!谢谢了。
void CMFCApplication17Dlg::OnClickedButton5()
{
{
// TODO: Add your control notification handler code here
//CFileDialog fDlg(TRUE,"bmp","*.bmp",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
//"原始图像(*.bmp)|*.bmp|所有文件(*.*)|*.*||",NULL);
//if (fDlg.DoModal() == TRUE)
//{
//Open_Filename = fDlg.GetFileName();
IplImage *image=NULL;
if(image)
cvReleaseImage(&image);
image = cvLoadImage("H:\lena.bmp",1);
if (image==0)
MessageBox("Reading Failed");
else
DrawPicToHDC(image, IDC_showimage);
cvReleaseImage(&image);
}
}

//}

void CMFCApplication17Dlg::DrawPicToHDC(IplImage img, UINT ID)
{
CDC *pDC = GetDlgItem(ID)->GetDC();
HDC hDC= pDC->GetSafeHdc();
CRect rect;
CWnd * pWnd;
pWnd=GetDlgItem(ID);
pWnd->SetWindowPos( NULL,0,0,img->width,img->height,SWP_NOZORDER | SWP_NOMOVE );
pWnd->GetClientRect(&rect);
CvvImage cimg;
cimg.CopyOf(img);
cimg.DrawToHDC(hDC,&rect);
ReleaseDC(pDC);
}
void CMFCApplication17Dlg::OnClickedButton1()
{
if( !lvboInitialize())

{

printf("Could not initialize !");

return ;

}
IplImage *image=NULL;
if(image)
cvReleaseImage(&image);
image = cvLoadImage("H:\lena.bmp",0);
IplImage
pTemp = cvCreateImage(cvSize(image->height, image->width), IPL_DEPTH_8U, 1); //n*m创建图像
cvTranspose(image, pTemp);//m*n->n*m,复制image中的数据到ptemp中
CvMat* pMat = cvCreateMat(pTemp->height, pTemp->width, CV_8UC1);//pmat:n*m分配矩阵空间
cvConvert(pTemp, pMat);//pmat:n*m,将图像转化为矩阵,任意类型数据的矩阵
mwArray a(pMat->width,pMat->height,mxUINT8_CLASS);
a.SetData(pMat->data.ptr, pMat->height*pMat->width);
mwArray h(pMat->width,pMat->height ,mxDOUBLE_CLASS);
cvReleaseMat( &pMat );

shiyan4(1,h,a);
IplImage* pTempL0 = cvCreateImage(cvSize(image->height, image->width), IPL_DEPTH_64F, 1); //n*m
CvMat* pMatL0 = cvCreateMat(pTempL0->height, pTempL0->width, CV_64FC1);//n*m
h.GetData(pMatL0->data.db,pMatL0->height*pMatL0->width);
cvConvert(pMatL0,pTempL0);
IplImage* pL0SmoothImg =cvCreateImage(cvSize(pTempL0->height, pTempL0->width),IPL_DEPTH_64F,1);//m*n

        //cvReleaseImage( &pTemp );
    cvTranspose(pTempL0, pL0SmoothImg); //n*m->m*n
    //mat->iplimage 

    IplImage* result =cvCreateImage(CvSize(cvGetSize(pL0SmoothImg)),IPL_DEPTH_8U,1);

cvNormalize(pL0SmoothImg,pL0SmoothImg,1,0,CV_MINMAX);

cvConvertScale(pL0SmoothImg,result,255,0);//62bit->8bit
//DrawPicToHDC(result, IDC_showimage2);
lvboTerminate();
if (result==0)
MessageBox("Reading Failed");
else
DrawPicToHDC(result, IDC_showimage2);
cvReleaseMat( &pMatL0 );
cvReleaseImage( &pTempL0 );
cvReleaseImage( &pL0SmoothImg);
cvReleaseImage( &result);

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • oyljerry oyljerry 2015-04-14 13:54

    把画图,部分是不是要放到OnPaint中,防止刷新冲掉

    点赞 评论 复制链接分享
  • u014650053 妮儿1 2015-04-15 08:07

    不要沉啊,没有人知道吗?谁知道啊说下吧感激不尽。

    点赞 评论 复制链接分享
  • VisualEleven Eleven 2015-04-16 05:41

    image = cvLoadImage("H:\lena.bmp",1);
    另外把你OnClickedButton5函数函数中的代码放到OnPaint函数中去做。

    点赞 评论 复制链接分享

相关推荐