opencv--打开图像

来源:互联网 发布:淘宝的类目都有哪些 编辑:程序博客网 时间:2024/05/22 01:58

从网上找的例程,但是用了之后发现打开一幅图像,完了再打开第二副的时候只覆盖掉第一副,而第一副没被覆盖掉的地方还是显示着的!

 IplImage* pImg;
   CString strPathName;
   CFileDialog dlg(TRUE);
   CDC* pDC = this->GetDC();
   CRect rect;
   this->GetClientRect(&rect);
   if(dlg.DoModal()==IDOK)
   {
      strPathName = dlg.GetPathName();

      pImg = cvLoadImage(strPathName);
      BITMAPINFO bmi;
      FillBitmapInfo(&bmi,pImg->width,pImg->height,(pImg->depth)*(pImg->nChannels));   
      
      ::StretchDIBits(pDC->GetSafeHdc(),rect.left,rect.top,pImg->width,pImg->height,0,0,pImg->width,pImg->height,pImg->imageData,&bmi,DIB_RGB_COLORS,SRCCOPY);
   }

 

void COpenCV_SVDDlg::FillBitmapInfo(BITMAPINFO *bmi, int width, int height, int bpp)
{
   ASSERT( bmi && width > 0 && height > 0 &&
      (bpp == 8 || bpp == 24 || bpp == 32) );
   
    BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
   
    memset( bmih, 0, sizeof(*bmih));
    bmih->biSize   = sizeof(BITMAPINFOHEADER);
    bmih->biWidth  = width;
    bmih->biHeight = -abs(height);
    bmih->biPlanes = 1;
    bmih->biBitCount = bpp;
    bmih->biCompression = BI_RGB;
   
    if( bpp == 8 )
    {
        RGBQUAD* palette = bmi->bmiColors;
        int i;
        for( i = 0; i < 256; i++ )
        {
            palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;
            palette[i].rgbReserved = 0;
        }
    }

}
 

原创粉丝点击