3.12.2 Image Control Dialog

Version Info

Minimum Origin Version Required: Origin 8 SR0

Need to do before Running Examples

  1. New a matrix window and import \Samples\Image Processing and Analysis\Flower.jpg.
  2. New a c file named ImageControlExample.c in Code Builder and save to \OriginC\Originlab folder.
  3. Run
    run.LoadOC(Originlab\ImageControlExample.c, 16);
    OpenImagePreviewDlg;
    in Command window. Click UP button to adjust brightness.

Example

#include <..\Originlab\DialogEx.h>

#include <image_utils.h>
#include <..\Originlab\ImageControl.h>
#include <..\Originlab\matdata_utils.h>

void OpenImagePreviewDlg()
{
	MatrixLayer ml = Project.ActiveLayer();
	if( ml )
	{
		MatrixObject mo = ml.MatrixObjects(0);
		
		ImagePreviewDlg dlgEx(mo);
		dlgEx.DoModalEx( GetWindow() );
	}
}

class ImagePreviewDlg : public ResizeDialog
{
public:
	ImagePreviewDlg(MatrixObject& mo, int ID = IDD_GETNBOX_PREVIEW);
	~ImagePreviewDlg();
	
	int DoModalEx(HWND hWndParent);
	
protected:
EVENTS_BEGIN
	ON_INIT(OnInitDialog)
	ON_BN_CLICKED(IDC_PARAMS_MORE, OnBtnClick)
EVENTS_END	

	BOOL OnInitDialog();
	BOOL OnBtnClick(Control ctrl);

private:
	MatrixObject		m_moSource;
	PictureControl		m_pictControl;
	MOImageControl*		m_pimgView;
};

ImagePreviewDlg::ImagePreviewDlg(MatrixObject& mo, int ID)
:ResizeDialog(ID, "ODlg")
{
	m_moSource = mo;
}

ImagePreviewDlg::~ImagePreviewDlg()
{
	delete m_pimgView;
}

BOOL ImagePreviewDlg::OnInitDialog()
{	
	ResizeDialog::OnInitDialog();
	
	// to hidden ususeful controls
	vector<int> vnHiddenIDs = {IDC_ERR_MESSAGE_BOX, IDC_PARAMS_DESCRIPTION, IDC_GETN_RESULT_PREVIEW};
	for(int nn = 0; nn < vnHiddenIDs.GetSize(); nn++)
	{
		Control ctrl = GetItem(vnHiddenIDs[nn]);
		if(ctrl)
			ctrl.Visible = false;	
	}
	
	// click to update brightness
	Control btn = GetItem(IDC_PARAMS_MORE);
	if( btn )
		btn.Text = "UP";
	
	Control cntrl = GetItem(IDC_PARAMS_PREVIEW);
	if(cntrl)
		m_pictControl.CreateControl(cntrl.GetSafeHwnd());
	//m_pictControl.DrawMode = PCDM_NO_STRETCH;	
	
	m_pimgView = new MOImageControl(m_pictControl);	
	Image imgi(m_moSource);
	m_pimgView->SetImage(imgi);
	
	return true;
}

BOOL ImagePreviewDlg::OnBtnClick(Control ctrl)
{	
	pBITMAPHANDLE pLBmp = m_pimgView->GetBitmapHandlePtr();	// get bitmap handle from matrix
	if( SUCCESS == adjust_image_brightness(pLBmp, 20) )
	{
		m_pimgView->Update();
	}
	return true;
}

int ImagePreviewDlg::DoModalEx(HWND hWndParent)
{
	InitMsgMap();
	
	DWORD dwDlgOptions = 0;
	int nRet = DoModal(hWndParent, dwDlgOptions);
	return nRet;
}