1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
void CTest::OnRadioDirection(UINT nID)
{
switch(nID)
{
case IDC_1:
id = 0;
break;
case IDC_2:
id = 1;
break;
case IDC_3:
id = 2;
break;
case IDC_4:
id = 3;
default:
break;
}
m_pGUIDoc->UpdateAllViews(NULL);
}
void CTest::DrawPreview(CDC* pDC)
{
if (m_pImg[id]) //m_pImg is a IplImage,can say is a image
{ //the id is the no of the radio button,
//eg,button 1 = id = 0,button 2 = id =1
BYTE* pImg = (BYTE*)m_pImg[id]->imageData;
CvSize size = cvGetSize(m_pImg[id]);
CRect rcPreview;
if (id == 0)
GetDlgItem(IDC_picture1)->GetWindowRect(&rcPreview);
else if (id == 1)
GetDlgItem(IDC_PICTURE2)->GetWindowRect(&rcPreview);
else if (id == 2)
GetDlgItem(IDC_PICTURE3)->GetWindowRect(&rcPreview);
else if (id == 3)
GetDlgItem(IDC_PICTURE4)->GetWindowRect(&rcPreview);
else
;
ScreenToClient(&rcPreview);
double scaleX = (double)size.width / (double)rcPreview.Width();
double scaleY = (double)size.height / (double)rcPreview.Height();
double scaleToFit = (scaleX > scaleY) ? scaleX : scaleY;
int iWidth = (int) ((double)size.width / scaleToFit);
int iHeight = (int) ((double)size.height / scaleToFit);
int iOffX = rcPreview.left;
int iOffY = rcPreview.top;
HDC hDC = pDC>GetSafeHdc();
SetStretchBltMode(hDC, COLORONCOLOR);
StretchDIBits(hDC, iOffX, iOffY, iWidth, iHeight,
0, 0, size.width, size.height, pImg, GetBitmapTag(), DIB_RGB_COLORS, SRCCOPY);
}
}
|