0

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

Community
  • 1
  • 1
John
  • 2,838
  • 7
  • 36
  • 65
  • please use cv::Mat, not IplImages. opencv's legacy c-api is a dead end. – berak Mar 26 '15 at 16:41
  • pic1 must be a member variable of the dialog class. If you are getting an error message or an assertion please tell us what it is. – ScottMcP-MVP Mar 26 '15 at 16:44
  • If I used CFace_Recognition_MFCDlg::DoDataExchange(pDX); DDX_Control(pDX, IDC_IMG, pic1); and run it crashes with Unhandled exception at 0x01059A29 in Face_Recognition_MFC.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x010D2FEC). – John Mar 26 '15 at 16:47

1 Answers1

0

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.

thomiel
  • 2,467
  • 22
  • 37