⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zoomdlg.cpp

📁 VS2005图像处理程序的源代码
💻 CPP
字号:
// ZoomDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "photoshow.h"
#include "ZoomDlg.h"
#include "MainFrm.h"
#include "photoshowDoc.h"
#include "photoshowView.h"
#include "GeoOperator.h"


// CZoomDlg 对话框

IMPLEMENT_DYNAMIC(CZoomDlg, CDialog)

CZoomDlg::CZoomDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CZoomDlg::IDD, pParent)
	, m_nWidth(0)
	, m_nHeight(0)
	, m_bIsPro(TRUE)
	, m_nType(0)
{
	m_bModify = false;
}

CZoomDlg::~CZoomDlg()
{
}

void CZoomDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_WIDTH, m_nWidth);
	DDX_Text(pDX, IDC_HEIGHT, m_nHeight);
	DDX_Check(pDX, IDC_PRO, m_bIsPro);
	DDX_CBIndex(pDX, IDC_MDOE, m_nType);
}


BEGIN_MESSAGE_MAP(CZoomDlg, CDialog)
	ON_BN_CLICKED(IDC_PREV, &CZoomDlg::OnBnClickedPrev)
	ON_EN_CHANGE(IDC_WIDTH, &CZoomDlg::OnEnChangeWidth)
	ON_EN_CHANGE(IDC_HEIGHT, &CZoomDlg::OnEnChangeHeight)
	ON_BN_CLICKED(IDC_PRO, &CZoomDlg::OnBnClickedPro)
	ON_BN_CLICKED(IDOK, &CZoomDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, &CZoomDlg::OnBnClickedCancel)
END_MESSAGE_MAP()


// CZoomDlg 消息处理程序

BOOL CZoomDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	CMainFrame* pMain = (CMainFrame*)AfxGetMainWnd();
	CphotoshowView* pView = (CphotoshowView*)pMain->GetActiveView();

	m_nWidth = m_nSrcWidth = pView->m_nPicWidth;
	m_nHeight = m_nSrcHeight = pView->m_nPicHeight;

	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

void CZoomDlg::OnBnClickedPrev()
{
	Refresh();

	CPreviewDlg dlg;
	dlg.m_nType = 1;
	dlg.DoModal();
}

void CZoomDlg::OnEnChangeWidth()
{
	UpdateData(TRUE);

	if (m_nWidth > 4000)
		m_nWidth = 4000;
	if (m_nWidth <= 0)
		m_nWidth = 1;

	UpdateData(FALSE);
	RefreshSize(true);
}

void CZoomDlg::OnEnChangeHeight()
{
	UpdateData(TRUE);

	if (m_nHeight > 4000)
		m_nHeight = 4000;
	if (m_nHeight <= 0)
		m_nHeight = 1;

	UpdateData(FALSE);
	RefreshSize(false);
}

void CZoomDlg::OnBnClickedPro()
{
	RefreshSize(true);
}

void CZoomDlg::OnBnClickedOk()
{
	CMainFrame* pMain = (CMainFrame*)AfxGetMainWnd();
	CphotoshowView* pView = (CphotoshowView*)pMain->GetActiveView();

	Refresh();
	pView->OnFileSave();
	m_bModify = false;
	OnOK();
}

void CZoomDlg::OnBnClickedCancel()
{
	if (m_bModify)
	{
		if (IDYES == MessageBox(L"图像已经更改,是否保存?", L"photoshow", MB_YESNO))
			OnBnClickedOk();
	}
	OnCancel();
}

void CZoomDlg::Refresh(void)
{
	UpdateData(TRUE);

	// 更新预览对话框
	CMainFrame* pMain = (CMainFrame*)AfxGetMainWnd();
	CphotoshowView* pView = (CphotoshowView*)pMain->GetActiveView();
	double fx = (double)m_nWidth / pView->m_nPicWidth;
	double fy = (double)m_nHeight / pView->m_nPicHeight;

	SAFE_DELETE_ARRAY (pView->m_pImageTempBuffer);

	if (m_nType == 0)
		ZoomNormal(pView->m_pImageBuffer, pView->m_pImageTempBuffer, 
				   pView->m_nPicWidth, pView->m_nPicHeight, pView->m_nTempWidth, 
				   pView->m_nTempHeight, fx, fy);
	else
		ZoomInterpolation(pView->m_pImageBuffer, pView->m_pImageTempBuffer, 
						  pView->m_nPicWidth, pView->m_nPicHeight, 
						  pView->m_nTempWidth, pView->m_nTempHeight, 
						  fx, fy);
	m_bModify = true;
}

void CZoomDlg::RefreshSize(bool width)
{
	UpdateData(TRUE);

	if (!m_bIsPro)
		return;

	if (width)	// 以宽度缩放比例修改高度
	{
		double fx = (double)m_nWidth / m_nSrcWidth;
		m_nHeight = (int)(m_nSrcHeight * fx);
	}
	else		// 以高度缩放比例修改宽度
	{
		double fy = (double)m_nHeight / m_nSrcHeight;
		m_nWidth = (int)(m_nSrcWidth * fy);
	}

	UpdateData(FALSE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -