简体   繁体   中英

Cannot load image in picture control MFC with resizeable form

I have interesting question about load image in picture control of MFC. I have a form that can resize. I do it using the method of Mark Ransom . I write that method in CResizableDialog.cpp . To used it, in my class I used

class CFace_Recognition_MFCDlg : public CResizableDialog

And my form have a picture control form with IDC_IMG is

CStatic pic1;
void CFace_Recognition_MFCDlg::DoDataExchange(CDataExchange* pDX)
{
    CResizableDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_IMG, pic1);
}

Finally, I using opencv to read image and convert it to bmp. Then display it into picture control by code

IplImage *img;
IplImage *resize;

img=cvLoadImage("phongcanh.jpg",CV_INTER_LINEAR);
if(img==0){
    exit(0);
}
resize = cvCreateImage(cvSize(400,300),img->depth, img->nChannels); 
cvResize(img, resize, 1);           
pic1.SetBitmap(IplImage2DIB(resize));  
cvReleaseImage(&img);  

The function IplImage2DIB works well. But I cannot show the image into the picture control. I check and I find that the problem in the function

CResizableDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_IMG, pic1);

But I don't know how to edit it. Because I am working with a resizeable form . Could you help me to fix it? Thanks

CResizableDialog is a limited framework for resizable Layout. My guess: it simply doesn't cover resizing of an image in a CStatic after dialog creation. Just have a look at the ResizableLib source code.

If this is the case, make the CStatic invisible (while still maintaining the resizable anchor) and use its position in OnDraw() or OnEraseBkgnd() to draw the image yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM