This section shows how to create an X-Function GetN dialog with a matrix image data preview as in the following dialog, including how to initialize an image preview and dialog controls, and how to update the image preview or dialog controls on any control change in the dialog performed by the user.
//put additional include files here #include <image_utils.h> #include <..\Originlab\matdata_utils.h>
//put your own support static functions here static bool _adjust_image_brightness_ex(BITMAPHANDLE* pPreviewBitmap, TreeNode& trGetN, bool& bOKEnable, string& strErrMsg) { int nRet = adjust_image_brightness(pPreviewBitmap, trGetN.level.nVal); if( SUCCESS != nRet) { bOKEnable = false; // disable OK button if adjust image failed strErrMsg = "Fail to adjust image brightness"; // error message string return false; } return true; }
This event function is called when the GetN image preview dialog is open. It can be used to initialize an image preview, initialize dialog controls and enable/disable the OK button. For this example, add the following code into the GetNImageBox_OnInit function to adjust the image brightness according to the value of the Level control.
// Get bitmap handle pointer from image preview control pBITMAPHANDLE pPreviewBitmap = pimgCntrl->GetBitmapHandlePtr(); // call internal function to adjust image _adjust_image_brightness_ex(pPreviewBitmap, trGetN, bOKEnable, strErrMsg);
This event function is called whenever any controls in the grid are modified by the user. It can be used to update the image preview on a dialog control change, update a dialog control on another control change, or update the OK button's enable/disable status. Add the following code into the GetNImageBox_OnChange function.
// call internal function to adjust image, return true to update image preview. bUpdatePreview = _adjust_image_brightness_ex(pPreviewBitmap, trGetN, bOKEnable, strErrMsg);
The main function has the same name as its corresponding X-Function. Add the following code into the main function and click the Compile button.
// Copy bitmap handle pointer from the input image to the output image bool bCopy = true; oimg.SetLBmp(iimg.GetLBmp(), bCopy); // Get bitmap handle pointer from the output image pBITMAPHANDLE phBmp = oimg.GetLBmp(); // adjust adjust_image_brightness(phBmp, level);