📄 imageprocessingdoc.cpp
字号:
// ImageProcessingDoc.cpp : implementation of the CImageProcessingDoc class
//
#include "stdafx.h"
#include "ImageProcessing.h"
#include "ImageProcessingDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "ImageSize.h"
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingDoc
IMPLEMENT_DYNCREATE(CImageProcessingDoc, CDocument)
BEGIN_MESSAGE_MAP(CImageProcessingDoc, CDocument)
//{{AFX_MSG_MAP(CImageProcessingDoc)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_EDGE, OnEdge)
ON_COMMAND(ID_FILTERING, OnFiltering)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingDoc construction/destruction
CImageProcessingDoc::CImageProcessingDoc()
{
// TODO: add one-time construction code here
nHeight = 0;
nWidth = 0;
fp = NULL;
data = NULL;
bFileIsLoad = false;
}
CImageProcessingDoc::~CImageProcessingDoc()
{
}
BOOL CImageProcessingDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingDoc serialization
void CImageProcessingDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingDoc diagnostics
#ifdef _DEBUG
void CImageProcessingDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CImageProcessingDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingDoc commands
void CImageProcessingDoc::OnFileOpen()
{
// TODO: Add your command handler code here
#define NAMEBUF 1024*1024
CFileDialog FileSDlg(TRUE, NULL,NULL, OFN_ALLOWMULTISELECT,_T("All Files (*.*)|*.*||"));// AfxGetMainWnd());
CString pathName;
FileSDlg.m_ofn.lpstrFile=new TCHAR[NAMEBUF]; // 重新定义 lpstrFile 缓冲大小
memset(FileSDlg.m_ofn.lpstrFile,0,NAMEBUF); // 初始化定义的缓冲
FileSDlg.m_ofn.nMaxFile = NAMEBUF; // 重定义 nMaxFile
FileSDlg.DoModal();
pathName = FileSDlg.GetPathName();
CImageSize mDlg;
if(mDlg.DoModal() == IDCANCEL)
return;
nHeight = mDlg.m_height;
nWidth = mDlg.m_width;
if( (fp=fopen(pathName,"rb")) == NULL)
return;
data = (unsigned char *)malloc(nHeight*nWidth);
if(data == NULL) return;
fread(data,1,nHeight*nWidth,fp);
bFileIsLoad = true;
UpdateAllViews(NULL);
}
void CImageProcessingDoc::OnEdge()
{
// TODO: Add your command handler code here
int x,y;
unsigned char *data1;
data1 = (unsigned char *)malloc(nHeight*nWidth);
if(data1 == NULL) return;
for(y = 0;y<nHeight;y++)
for(x =0; x< nWidth;x++)
data1[y*nWidth+x]=0;
for(y=1;y<nHeight-1;y++)
for(x =1 ;x<nWidth-1;x++)
{
/*
data1[y*nWidth+x] = -data[(y-1)*nWidth+x-1]+2*data[(y-1)*nWidth+x] - data[(y-1)*nWidth+x+1]
-data[(y)*nWidth+x-1]+2*data[(y)*nWidth+x] - data[(y)*nWidth+x+1]
-data[(y+1)*nWidth+x-1]+2*data[(y+1)*nWidth+x] - data[(y+1)*nWidth+x+1];
data1[y*nWidth+x] = data1[y*nWidth+x]>255?255:data1[y*nWidth+x];
*/
data1[y*nWidth+x] = data[(y-1)*nWidth+x-1] + data[(y-1)*nWidth+x] + data[(y-1)*nWidth+x+1]
+ data[(y)*nWidth+x-1] + data[(y)*nWidth+x] + data[(y)*nWidth+x+1]
+ data[(y+1)*nWidth+x-1] + data[(y+1)*nWidth+x] + data[(y+1)*nWidth+x+1];
data1[y*nWidth+x] /=9;
data1[y*nWidth+x] = data1[y*nWidth+x]>255 ? 255 :data1[y*nWidth+x];
}
memcpy(data,data1,nHeight*nWidth);
UpdateAllViews(NULL);
}
void CImageProcessingDoc::OnFiltering()
{
// TODO: Add your command handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -