📄 imagetestview.cpp
字号:
// imagetestView.cpp : implementation of the CImagetestView class
//
#include "stdafx.h"
#include "imagetest.h"
#include "imagetestDoc.h"
#include "imagetestView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CImagetestView
IMPLEMENT_DYNCREATE(CImagetestView, CScrollView)
BEGIN_MESSAGE_MAP(CImagetestView, CScrollView)
//{{AFX_MSG_MAP(CImagetestView)
ON_COMMAND(ID_IMG_HARRIS_SHOWCORNER, OnImgHarrisShowcorner)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CImagetestView construction/destruction
CImagetestView::CImagetestView()
{
// TODO: add construction code here
}
CImagetestView::~CImagetestView()
{
}
BOOL CImagetestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CImagetestView drawing
void CImagetestView::OnDraw(CDC* pDC)
{ int i,j;
unsigned char *lpSrc;
CImagetestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(pDoc->m_hDIB == NULL)
return ;
// TODO: add draw code for native data here
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB);
int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x
int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y
LPSTR lpDIBBits=::FindDIBBits (lpDIB);
// 计算图像每行的字节数
long lLineBytes = WIDTHBYTES(cxDIB * 8);
// 每行
for(i = 0; i < cyDIB; i++)
{
// 每列
for(j = 0; j < cxDIB; j++)
{
// 指向DIB第i行,第j个象素的指针
lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j;
// 计算新的灰度值
//*(lpSrc) = BYTE(255-*lpSrc);
}
}
::GlobalUnlock((HGLOBAL) pDoc->m_hDIB);
CRect rect(0,0,cxDIB,cyDIB), rcDIB(0,0,cxDIB,cyDIB);
::PaintDIB(pDC->m_hDC, &rect, pDoc->m_hDIB, &rcDIB, pDoc->m_palDIB);
}
/////////////////////////////////////////////////////////////////////////////
// CImagetestView printing
BOOL CImagetestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CImagetestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CImagetestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CImagetestView diagnostics
#ifdef _DEBUG
void CImagetestView::AssertValid() const
{
CScrollView::AssertValid();
}
void CImagetestView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CImagetestDoc* CImagetestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImagetestDoc)));
return (CImagetestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CImagetestView message handlers
void CImagetestView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
// sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, GetDocument()->m_nDocSize);
}
void CImagetestView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
void CImagetestView::OnImgHarrisShowcorner()
{
CImagetestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(pDoc->m_hDIB == NULL)
return ;
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB);
int cxDIB = (int) ::DIBWidth(lpDIB);
int cyDIB = (int) ::DIBHeight(lpDIB);
int i,j;
#define corner(ROW,COL) corner[cxDIB*(ROW)+(COL)]
CDC *dc=GetDC();
// 创建红色画笔对象
CPen* pPenRed = new CPen;
pPenRed->CreatePen(PS_SOLID,1,RGB(255,0,0));
dc->SelectObject(pPenRed);
for(i = 0; i < cyDIB; i++)
{
for(j = 0; j < cxDIB; j++)
{
if(pDoc->corner(i,j))
{
//在角点处划十字叉以标注
dc->MoveTo (j-5,i);
dc->LineTo (j+6,i);
dc->MoveTo (j,i-5);
dc->LineTo (j,i+6);
dc->MoveTo (j-5,i+1);
dc->LineTo (j+6,i+1);
dc->MoveTo (j+1,i-5);
dc->LineTo (j+1,i+6);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -