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

📄 readbmpview.cpp

📁 把一个图象转 换为灰度图换为灰度图
💻 CPP
字号:
// ReadBmpView.cpp : implementation of the CReadBmpView class
//

#include "stdafx.h"
#include "ReadBmp.h"

#include "ReadBmpDoc.h"
#include "ReadBmpView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CReadBmpView

IMPLEMENT_DYNCREATE(CReadBmpView, CView)

BEGIN_MESSAGE_MAP(CReadBmpView, CView)
	//{{AFX_MSG_MAP(CReadBmpView)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_TXCL_BW, OnTxclBw)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReadBmpView construction/destruction

CReadBmpView::CReadBmpView()
{
	// TODO: add construction code here
//	m_im=0;
}

CReadBmpView::~CReadBmpView()
{
//	if (m_im!=0)
//		delete m_im;
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CReadBmpView drawing
//===============================================================
BOOL CReadBmpView::OnEraseBkgnd(CDC* pDC) 
{
	CBrush backBrush(RGB(0, 128, 128));
	CBrush* pOldBrush = pDC->SelectObject(&backBrush);
	CRect rect;
	pDC->GetClipBox(&rect);
	pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
	pDC->SelectObject(pOldBrush);
	return TRUE;
}
//==================================================================
void CReadBmpView::OnDraw(CDC* pDC)
{
	OnEraseBkgnd(pDC);
    CDib& dib = GetDocument()->m_dib;
	if(dib.m_lpBMIH == NULL) return;
	CMDIFrameWnd *pFrame =(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
	dib.Draw(pDC, 0, 0);
}

/////////////////////////////////////////////////////////////////////////////
// CReadBmpView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CReadBmpView diagnostics

#ifdef _DEBUG
void CReadBmpView::AssertValid() const
{
	CView::AssertValid();
}

void CReadBmpView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CReadBmpView message handlers

void CReadBmpView::OnFileOpen() 
{
	char fn[80];
	CReadBmpDoc* pDoc = GetDocument();

    CFileDialog dlg(TRUE, "bmp", "*.bmp");
    if (dlg.DoModal() != IDOK) return;

	strncpy(fn,dlg.GetPathName(),80);
	pDoc->SetTitle(fn);

	pDoc->m_dib.Read(fn);
	CClientDC dc(this);
	OnDraw(&dc);	
}

void CReadBmpView::OnTxclBw() 
{
	CReadBmpDoc *pDoc=GetDocument();
	
	Image *im;
	im=pDoc->m_dib.DibToImage();

	CClientDC dc(this);
	im->Afficher(&dc, 512,0);

	int i, j;
	for (i=0; i<im->width; i++)
		for (j=0; j<im->height; j++)
			if (im->ng[i][j]>100)
				im->ng[i][j]=255;
			else
				im->ng[i][j]=0;
	
	im->Afficher(&dc, 512,300);
	delete im;
}

⌨️ 快捷键说明

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