生物特征 高性能服务 智能交互分享 http://blog.sciencenet.cn/u/bluewind23 带着鲜刺的玫瑰刺得血如雨下一如既往前行!

博文

Show IplImage on MFC Window

已有 8143 次阅读 2009-9-5 08:26 |个人分类:学习研究|系统分类:科研笔记| OpenCV, IplImage, MFC, Bitmap

/***********************************************

*功能:在当前窗口中显示IplImage的图像
*输入参数:src  指向图片的指针
*输出参数:无
*返回值:无
*作者:张建成

***********************************************/
void ShowImage(IplImage *src)

 if(src->nChannels==3)// color
 { 
   TheImage=cvCloneImage(src);
    IplImage *TheImage = src;
    CvSize ImgSize;
    ImgSize.width = TheImage->width;
    ImgSize.height = TheImage->height;
    CClientDC dc(this);
   CDC * pDC = &dc;
    int res = StretchDIBits(pDC->GetSafeHdc(),0,0,int(TheImage->width),int(TheImage->height),
                      0,0,TheImage->width,TheImage->height,TheImage->imageData,
       (BITMAPINFO*)bmi,DIB_RGB_COLORS,SRCCOPY);

   }

else
 {
   if(src->nChannels==1)// gray
   {  
    IplImage *grayImg=cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,3);
    IplImage * planes[3] ={0,0,0};
    for(int i=0;i<3;i++)
       {
         planes[i] = cvCreateImage(cvSize(src->width,src->height),8,1);
        (planes[i]->imageData)= (src->imageData);
    }
     cvCvtPlaneToPix(planes[0],planes[1],planes[2],0,grayImg);
    IplImage * TheImage=cvCloneImage(grayImg);
     CvSize ImgSize;
    ImgSize.width = TheImage->width;
    ImgSize.height = TheImage->height;
    CClientDC dc(this);
    CDC * pDC = &dc;
 
    int res = StretchDIBits(pDC->GetSafeHdc(),0,0,int(TheImage->width),int(TheImage->height),
                      0,0,TheImage->width,TheImage->height,TheImage->imageData,
       (BITMAPINFO*)bmi,DIB_RGB_COLORS,SRCCOPY);

   }
}
}



https://blog.sciencenet.cn/blog-297739-253532.html

上一篇:OpenCV 深入学习:IplImage 结构
下一篇:MFC中的多线程
收藏 IP: .*| 热度|

0

发表评论 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-11-23 09:38

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部