예전에 리소스 등록하여 BMP 출력하는거 썼었네..
이번에는 IplImage 등의 구조체로 읽어들인 영상을 Picture Control에 출력하는 방법을 다룬다.
당장은 쓸 일 없지만 나중에 쓸라그럼 내머리가 기억을 못할테니..
적어놔야지..
//-----------------------------------------------------
// 사용할 영상
IplImage* tmp = cvLoadImage("경로\\SIMG_3380.jpg");
CDC* pDC;
CRect rect;
// m_stDisplay 는 picture control의 멤버변수명.
pDC = m_stDisplay.GetDC();
m_stDisplay.GetClientRect(&rect);
BITMAPINFO bitmapInfo;
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biXPelsPerMeter = 100;
bitmapInfo.bmiHeader.biYPelsPerMeter = 100;
bitmapInfo.bmiHeader.biClrUsed = 0;
bitmapInfo.bmiHeader.biClrImportant = 0;
bitmapInfo.bmiHeader.biSizeImage = 0;
bitmapInfo.bmiHeader.biWidth = tmp->width;
bitmapInfo.bmiHeader.biHeight = -tmp->height;
IplImage* tempImage;
if (tmp->nChannels == 3)
{
tempImage = (IplImage*)cvClone(tmp);
bitmapInfo.bmiHeader.biBitCount = tempImage->depth * tempImage->nChannels;
}
else if (tmp->nChannels == 1)
{
tempImage = cvCreateImage(cvGetSize(tmp), IPL_DEPTH_8U, 3);
cvCvtColor(tmp, tempImage, CV_GRAY2BGR);
bitmapInfo.bmiHeader.biBitCount = tempImage->depth * tempImage->nChannels;
}
pDC->SetStretchBltMode(COLORONCOLOR);
::StretchDIBits(pDC->GetSafeHdc(), rect.left, rect.top, rect.right, rect.bottom,
0, 0, tempImage->width, tempImage->height, tempImage->imageData, &bitmapInfo,
DIB_RGB_COLORS, SRCCOPY);
cvReleaseImage(&tempImage);
// release 잘해주기.
ReleaseDC(pDC);
cvReleaseImage(&tmp);
//-----------------------------------------------------
결과 :
아래처럼 Picture Control을 생성 해두고
출력 하면 딱 사이즈 맞게 출력된다.
아래는 덤으로.. 테스트에 사용된 사진.
작년 제주도에서 찍은 사진. 나름 맘에들어. ㅋㅋ
'Programming > Windows' 카테고리의 다른 글
taskkill 명령어를 이용하여 프로세스를 강제종료하자 (0) | 2017.02.16 |
---|---|
CWnd <- -> HWND (0) | 2015.05.27 |