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

📄 processimageview.cpp

📁 主要介绍vc++6.0的编程过程
💻 CPP
字号:
// ProcessImageView.cpp : implementation of
// the CProcessImageView class
//

#include "stdafx.h"
#include "ProcessImage.h"

#include "ProcessImageDoc.h"
#include "ProcessImageView.h"
#include "MainFrm.h"
#include "ChildFrm.h"

#include "Brightness.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CProcessImageView

IMPLEMENT_DYNCREATE(CProcessImageView, CScrollView)

BEGIN_MESSAGE_MAP(CProcessImageView, CScrollView)
	//{{AFX_MSG_MAP(CProcessImageView)
	ON_COMMAND(ID_AREAPROCESSES_CHANGECONTRACT, OnAreaprocessesChangecontract)
	ON_COMMAND(ID_AREAPROCESSES_EDGEENHANCE, OnAreaprocessesEdgeenhance)
	ON_COMMAND(ID_AREAPROCESSES_EQUALIZECONTRAST, OnAreaprocessesEqualizecontrast)
	ON_COMMAND(ID_AREAPROCESSES_HIGHPASSFILTER, OnAreaprocessesHighpassfilter)
	ON_COMMAND(ID_AREAPROCESSES_LOWPASSFILTER, OnAreaprocessesLowpassfilter)
	ON_COMMAND(ID_AREAPROCESSES_MEDIANFILTER, OnAreaprocessesMedianfilter)
	ON_COMMAND(ID_POINTPROCESSES_CHANGEBRIGHTNESS, OnPointprocessesChangebrightness)
	ON_COMMAND(ID_POINTPROCESSES_COLORIZE, OnPointprocessesColorize)
	ON_COMMAND(ID_POINTPROCESSES_MAKEGRAY, OnPointprocessesMakegray)
	ON_COMMAND(ID_POINTPROCESSES_REVERSECOLORS, OnPointprocessesReversecolors)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProcessImageView construction/destruction

CProcessImageView::CProcessImageView()
{

	// Set the CImageObject class member
	// to NULL so that we won't try to
	// delete it in the destructor if an
	// image hasn't been loaded.
	m_pImageObject = NULL;

}

CProcessImageView::~CProcessImageView()
{

	// If the CImageObject class member has
	// been allocated, delete it.
	if( m_pImageObject != NULL )
		delete m_pImageObject;

}

BOOL CProcessImageView::PreCreateWindow(CREATESTRUCT& cs)
{
	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CProcessImageView drawing

void CProcessImageView::OnDraw(CDC* pDC)
{
	CProcessImageDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// If the CImageObject class member is NULL,
	// we'll attempt to allocate the CImageObject
	// class and load the image.
	if( m_pImageObject == NULL ){

		// Get the filename.
		CString PathName = pDoc->GetPathName();

		// Change to hourglass.
		BeginWaitCursor();

		// Allocate the CImageObject class
		// and load the image.
		m_pImageObject =
			new CImageObject( PathName.GetBuffer( 3 ),
			pDC );

		// Change from the hourglass.
		EndWaitCursor();

		// If the CImageObject class is NULL, return
		// and don't try anything else.
		if( m_pImageObject == NULL )
			return;
					
		// Set the scroll window size.
		CSize SizeTotal;
		SizeTotal.cx = m_pImageObject->GetWidth();
		SizeTotal.cy = m_pImageObject->GetHeight();
		SetScrollSizes (MM_TEXT, SizeTotal);

		// Get a pointer to the active child window.
		CMainFrame *pFrame =
			(CMainFrame *) AfxGetMainWnd();
		CChildFrame *pChild =
			(CChildFrame *) pFrame->MDIGetActive();

		// Set the child window width and height member
		// variables so that the child window can resize
		// correctly for the image.
		pChild->m_nWidth = m_pImageObject->GetWidth(); 
		pChild->m_nHeight = m_pImageObject->GetHeight(); 

		// Cause the child window to resize.
		pChild->SetWindowPos( NULL, 0, 0, 2500, 2500,
			SWP_NOZORDER | SWP_NOMOVE );

		}

	OnPrepareDC (pDC);

	// Set the palette and draw the image.
	if( GetFocus() == this )
		m_pImageObject->SetPalette( pDC );
	m_pImageObject->Draw( pDC );

}

void CProcessImageView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
	CSize sizeTotal;
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CProcessImageView diagnostics

#ifdef _DEBUG
void CProcessImageView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CProcessImageView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CProcessImageDoc* CProcessImageView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CProcessImageDoc)));
	return (CProcessImageDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CProcessImageView message handlers

void CProcessImageView::OnAreaprocessesChangecontract() 
{

	// The brightness dialog box can also be used
	// to get any other value from 0-200. All we
	// have to do is set the dialog box class members
	// to change the title and label.
	CBrightness Brightness;
	strcpy( Brightness.m_szTitle, "Set Contrast" );
	strcpy( Brightness.m_szLabel, "Contrast" );
	if( Brightness.DoModal() != IDOK ) return;

	// Create a CImageAreaProcess class and attach
	// our CImageObject class member.
	CImageAreaProcesses AreaProcesses(m_pImageObject);
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	AreaProcesses.ChangeContrast( Brightness.m_nBrightness );
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();

}

void CProcessImageView::OnAreaprocessesEdgeenhance() 
{

	// Create a CImageAreaProcess class and attach
	// our CImageObject class member.
	CImageAreaProcesses AreaProcesses( m_pImageObject );
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	AreaProcesses.EdgeEnhance();
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();
}

void CProcessImageView::OnAreaprocessesEqualizecontrast() 
{

	// Create a CImageAreaProcess class and attach
	// our CImageObject class member.
	CImageAreaProcesses AreaProcesses( m_pImageObject );
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	AreaProcesses.EqualizeContrast();
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();
}

void CProcessImageView::OnAreaprocessesHighpassfilter() 
{

	// Create a CImageAreaProcess class and attach
	// our CImageObject class member.
	CImageAreaProcesses AreaProcesses( m_pImageObject );
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	AreaProcesses.HighpassFilter();
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();
}

void CProcessImageView::OnAreaprocessesLowpassfilter() 
{

	// Create a CImageAreaProcess class and attach
	// our CImageObject class member.
	CImageAreaProcesses AreaProcesses( m_pImageObject );
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	AreaProcesses.LowpassFilter();
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();
	
}

void CProcessImageView::OnAreaprocessesMedianfilter() 
{

	// Create a CImageAreaProcess class and attach
	// our CImageObject class member.
	CImageAreaProcesses AreaProcesses( m_pImageObject );
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	AreaProcesses.MedianFilter();
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();
	
}

void
CProcessImageView::OnPointprocessesChangebrightness() 
{
	CBrightness Brightness;
	if( Brightness.DoModal() != IDOK ) return;

	// Create a CImagePointProcess class and attach
	// our CImageObject class member.
	CImagePointProcesses PointProcesses( m_pImageObject );
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	PointProcesses.ChangeBrightness(
		Brightness.m_nBrightness );
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();
	
}

void CProcessImageView::OnPointprocessesColorize() 
{
	CColorDialog ColorDialog;
	if( ColorDialog.DoModal() != IDOK ) return;

	// Create a CImagePointProcess class and attach
	// our CImageObject class member.
	CImagePointProcesses PointProcesses( m_pImageObject );
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	PointProcesses.Colorize( 0, 0,
		m_pImageObject->GetWidth() - 1,
		m_pImageObject->GetHeight() - 1,
		ColorDialog.GetColor() );
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();
}

void CProcessImageView::OnPointprocessesMakegray() 
{

	// Create a CImagePointProcess class and attach
	// our CImageObject class member.
	CImagePointProcesses PointProcesses( m_pImageObject );
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	PointProcesses.MakeGray( TRUE );
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();
	
}

void CProcessImageView::OnPointprocessesReversecolors() 
{

	// Create a CImagePointProcess class and attach
	// our CImageObject class member.
	CImagePointProcesses PointProcesses( m_pImageObject );
	// Change to hourglass.
	BeginWaitCursor();
	// Perform the process.
	PointProcesses.ReverseColors();
	// Change from the hourglass.
	EndWaitCursor();

	// Cause a window redraw.
	InvalidateRect( NULL, FALSE );
	UpdateWindow();
	
}

⌨️ 快捷键说明

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