Show IplImage on MFC Window

本文介绍了一个用于在当前窗口中显示IplImage图像的方法。该方法可以处理彩色图像和灰度图像,并通过使用CvSize定义图像尺寸,利用CClientDC进行绘制。对于灰度图像,还涉及将其转换为三通道图像的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

*功能:在当前窗口中显示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);
   }
 }
}
本文引用地址: http://blog.sciencenet.cn/blog-297739-253532.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值