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

📄 colorimgview.cpp

📁 I used MFC. that code is not perfect and have some problem. But its function is Ok. You just fix
💻 CPP
字号:
// ColorImgView.cpp : implementation of the CColorImgView class
//

#include "stdafx.h"
#include "ColorImg.h"

#include "ColorImgDoc.h"
#include "ColorImgView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CColorImgView

IMPLEMENT_DYNCREATE(CColorImgView, CScrollView)

BEGIN_MESSAGE_MAP(CColorImgView, CScrollView)
	//{{AFX_MSG_MAP(CColorImgView)
	ON_COMMAND(ID_HistoView, OnHistoView)
	ON_COMMAND(ID_Mean, OnMean)
	ON_COMMAND(ID_RGBtoHSI, OnRGBtoHSI)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CColorImgView construction/destruction

CColorImgView::CColorImgView()
{
	// TODO: add construction code here

}

CColorImgView::~CColorImgView()
{
}

BOOL CColorImgView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CColorImgView drawing

void CColorImgView::OnDraw(CDC* pDC)
{
	CColorImgDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

	for (int y = 0; y < 512; y++)
	{
		for (int x = 0; x < 512; x++)	
		{
			pDC->SetPixel(x, y, RGB(pDoc->m_OpenImg[0][y][x],
									pDoc->m_OpenImg[1][y][x],
									pDoc->m_OpenImg[2][y][x]));
		}
	}

	for (y = 0; y < 512; y++)
	{
		for (int x = 0; x < 512; x++)	
		{
			pDC->SetPixel(x+550, y, RGB(pDoc->m_HImg[y][x],
										pDoc->m_SImg[y][x],
										pDoc->m_IImg[y][x]));
		}
	}

	for (y = 0; y < 512; y++)
	{
		for (int x = 0; x < 512; x++)	
		{
			pDC->SetPixel(x, y+550, RGB(pDoc->m_HImg[y][x],
										pDoc->m_HImg[y][x],
										pDoc->m_HImg[y][x]));
		}
	}

	for (y = 0; y < 512; y++)
	{
		for (int x = 0; x < 512; x++)	
		{
			pDC->SetPixel(x+550, y+550, RGB(pDoc->m_SImg[y][x],
											pDoc->m_SImg[y][x],
											pDoc->m_SImg[y][x]));
		}
	}

	for (y = 0; y < 512; y++)
	{
		for (int x = 0; x < 512; x++)	
		{
			pDC->SetPixel(x+1100, y+550, RGB(pDoc->m_IImg[y][x],
											pDoc->m_IImg[y][x],
											pDoc->m_IImg[y][x]));
		}
	}


/*	
	for (int k=0; k<3; k++)
	{
		for (y = 0; y < 512; y++)
		{
			for (int x = 0; x < 512; x++)	
			{
				if (k==0)
				{
					pDC->SetPixel(x , y+550, RGB(pDoc->m_HImg[k][y][x],
												pDoc->m_HImg[k][y][x],
												pDoc->m_HImg[k][y][x]));
				}
				else if (k==1)
				{
					pDC->SetPixel(x+550 , y+550, RGB(pDoc->m_SImg[k][y][x],
													pDoc->m_SImg[k][y][x],
													pDoc->m_SImg[k][y][x]));
				}
				else
				{
					pDC->SetPixel(x+1100 , y+550, RGB(pDoc->m_IImg[k][y][x],
													pDoc->m_IImg[k][y][x],
													pDoc->m_IImg[k][y][x]));
				}

			}
		}
	}
*/
}

void CColorImgView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx =  2048;
	sizeTotal.cy =	2048;
	//sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CColorImgView printing

BOOL CColorImgView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CColorImgView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CColorImgView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CColorImgView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CColorImgView message handlers

void CColorImgView::OnHistoView() 
{
	// TODO: Add your command handler code here
	CColorImgDoc*pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	pDoc->HistoView();

	Invalidate(FALSE);
	
}

void CColorImgView::OnMean() 
{
	// TODO: Add your command handler code here
	CColorImgDoc*pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	pDoc->Mean();

	Invalidate(FALSE);
	
}

void CColorImgView::OnRGBtoHSI() 
{
	// TODO: Add your command handler code here
	CColorImgDoc*pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	pDoc->RGBtoHSI();

	Invalidate(FALSE);	
}

⌨️ 快捷键说明

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