본문 바로가기
배워보자!!/Opencv

[Opencv] Iplimage이미지로드, Picture Control에 보여주기

by norinda 2019. 6. 19.
728x90

이번엔

Iplimage로 로드한 이미지를

Picture Control에 뿌려보겠습니다. 캬캬

//-----------------------------------------------------------------------------------------------------

CString curWindowName;
    CString FileName;
    DWORD dwFlags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
    LPCTSTR szFilter = _T("Image (*.BMP, *.PNG, *.JPG) | *.BMP;*.PNG;*.JPG | All Files(*.*)|*.*||");
    LPCTSTR lpszFilter = "Image Files(*.bmp)|*.bmp|";
    CFileDialog dlg(TRUE, NULL, NULL, dwFlags, szFilter);
    if (dlg.DoModal() == IDOK)
    {
        FileName = dlg.GetPathName();
        curWindowName.Format("lena");
    }
    else
    {
        return;
    }
    IplImage *loadIplImage = cvLoadImage(FileName);//insp.bmp = 사각형
    cvNamedWindow(curWindowName, 0); //영상을 표시할 윈도우를 생성(0/1)
    cvShowImage(curWindowName, loadIplImage); //윈도우에 출력
    //PictureControlView(loadIplImage);
    cvWaitKey(0); //프로그램의 동작을 잠시 멈추고 사용자로부터 키 입력을 기다린다.
    cvReleaseImage(&loadIplImage); //할당된 메모리 공간을 해제한다.
    cvDestroyWindow(curWindowName); //윈도우를 닫고, 윈도우를 위해 동적할당된 메모리 공간을 모두 해제한다. 
    //cvDestroyAllWindows(); //한번에 모든 창을 닫는다.

 

//-----------------------------------------------------------------------------------------------------

위와같이 Iplimage로 이미지 로드한걸

아래와같이 보여주면 됩니다.

//-----------------------------------------------------------------------------------------------------

BITMAPINFO bitmapInfo;
    memset(&bitmapInfo, 0, sizeof(bitmapInfo));
    bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bitmapInfo.bmiHeader.biPlanes = 1;
    bitmapInfo.bmiHeader.biCompression = BI_RGB;
    bitmapInfo.bmiHeader.biWidth = LoadImg->width;
    bitmapInfo.bmiHeader.biHeight = -LoadImg->height;
    bitmapInfo.bmiHeader.biBitCount = LoadImg->depth * LoadImg->nChannels;
    //
    CWnd* pWndPic = GetDlgItem(IDC_STATIC_PIC);
    CClientDC dcPic(pWndPic);
    RECT rcPic;
    pWndPic->GetClientRect(&rcPic);
    dcPic.SetStretchBltMode(COLORONCOLOR);

    ::StretchDIBits(dcPic.GetSafeHdc(), rcPic.left, rcPic.top, rcPic.right, rcPic.bottom,
        0, 0, LoadImg->width, LoadImg->height, LoadImg->imageData, &bitmapInfo, DIB_RGB_COLORS, SRCCOPY);

반응형

댓글