📄 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
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingDoc
IMPLEMENT_DYNCREATE(CImageProcessingDoc, CDocument)
BEGIN_MESSAGE_MAP(CImageProcessingDoc, CDocument)
//{{AFX_MSG_MAP(CImageProcessingDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
ON_COMMAND(ID_FILE_SEND_MAIL, OnFileSendMail)
ON_UPDATE_COMMAND_UI(ID_FILE_SEND_MAIL, OnUpdateFileSendMail)
ON_COMMAND(ID_FILE_REOPEN,OnFileReopen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CImageProcessingDoc construction/destruction
CImageProcessingDoc::CImageProcessingDoc()
{
// TODO: add one-time construction code here
//m_refColorBKG=0x00808080;
m_hDFT=NULL;
m_hDIB=NULL;
m_palDIB=NULL;
m_sizeDoc=CSize(1,1);
}
CImageProcessingDoc::~CImageProcessingDoc()
{
if(m_hDIB!=NULL)
{
::GlobalFree((HGLOBAL)m_hDIB);
}
if(m_palDIB!=NULL)
{
delete m_palDIB;
}
}
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
BOOL CImageProcessingDoc::CanCloseFrame(CFrameWnd *pFrame)
{
return CDocument::CanCloseFrame(pFrame);
}
void CImageProcessingDoc::DeleteContents()
{
CDocument::DeleteContents();
}
BOOL CImageProcessingDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
CFile file;
CFileException fe;
if(!file.Open(lpszPathName,CFile::modeRead|CFile::shareDenyWrite,&fe))
{
ReportSaveLoadException(lpszPathName,&fe,
FALSE,AFX_IDP_FAILED_TO_OPEN_DOC);
return false;
}
DeleteContents();
BeginWaitCursor();
TRY
{
m_hDIB=::ReadDIBFile(file);
}
CATCH(CFileException,eLoad)
{
file.Abort();
EndWaitCursor();
ReportSaveLoadException(lpszPathName,eLoad,
false,AFX_IDP_FAILED_TO_OPEN_DOC);
m_hDIB=NULL;
return false;
}
END_CATCH
InitDIBData();
EndWaitCursor();
if(m_hDIB==NULL)
{
CString strMsg;
strMsg ="读取图像时出错!不支持此类型图像文件!";
MessageBox(NULL,strMsg,"Visual C++图像增强处理",MB_ICONINFORMATION|MB_OK);
return false;
}
SetPathName(lpszPathName);
SetModifiedFlag(false);
return true;
}
void CImageProcessingDoc::OnFileReopen()
{
if(IsModified())
{
if(MessageBox(NULL,"重新打开图像将丢失所有改动!是否继续?","Visual C++图像增强处理",
MB_ICONQUESTION|MB_YESNO)==IDNO)
{
return;
}
}
CFile file;
CFileException fe;
CString strPathName;
strPathName=GetPathName();
if(!file.Open(strPathName,CFile::modeRead|CFile::shareDenyWrite,&fe))
{
ReportSaveLoadException(strPathName,&fe,
false,AFX_IDP_FAILED_TO_OPEN_DOC);
return;
}
BeginWaitCursor();
TRY
{
m_hDIB=::ReadDIBFile(file);
}
CATCH(CFileException,eLoad)
{
file.Abort();
EndWaitCursor();
ReportSaveLoadException(strPathName,eLoad,
false,AFX_IDP_FAILED_TO_OPEN_DOC);
m_hDIB=NULL;
return;
}
END_CATCH
InitDIBData();
if(m_hDIB==NULL)
{
CString strMsg;
strMsg="读取图像时出错!不支持此类型图像文件!";
MessageBox(NULL,strMsg,NULL,MB_ICONINFORMATION|MB_OK);
EndWaitCursor();
return;
}
SetModifiedFlag(false);
UpdateAllViews(NULL);
EndWaitCursor();
return;
}
BOOL CImageProcessingDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
CFile file;
CFileException fe;
if(!file.Open(lpszPathName,CFile::modeCreate|
CFile::modeReadWrite|CFile::shareExclusive,&fe))
{
ReportSaveLoadException(lpszPathName,&fe,
true,AFX_IDP_INVALID_FILENAME);
return false;
}
BOOL bSuccess=false;
TRY
{
BeginWaitCursor();
bSuccess=::SaveDIB(m_hDIB,file);
file.Close();
}
CATCH(CException,eSave)
{
file.Abort();
EndWaitCursor();
ReportSaveLoadException(lpszPathName,eSave,
true,AFX_IDP_FAILED_TO_SAVE_DOC);
return false;
}
END_CATCH
EndWaitCursor();
SetModifiedFlag(false);
if(!bSuccess)
{
CString strMsg;
strMsg="无法保存BMP图像!";
MessageBox(NULL,strMsg,NULL,MB_ICONINFORMATION|MB_OK);
}
return bSuccess;
}
void CImageProcessingDoc::ReplaceHDIB(HDIB hDIB)
{
if(m_hDIB!=NULL)
{
::GlobalFree((HGLOBAL)m_hDIB);
}
m_hDIB=hDIB;
}
void CImageProcessingDoc::InitDIBData()
{
if(m_palDIB!=NULL)
{
delete m_palDIB;
m_palDIB=NULL;
}
if(m_hDIB==NULL)
{
return;
}
LPSTR lpDIB=(LPSTR)::GlobalLock((HGLOBAL)m_hDIB);
if(::DIBWidth(lpDIB)>INT_MAX||::DIBHeight(lpDIB)>INT_MAX)
{
::GlobalUnlock((HGLOBAL)m_hDIB);
::GlobalFree((HGLOBAL)m_hDIB);
m_hDIB=NULL;
CString strMsg;
strMsg="BMP图像太大!";
MessageBox(NULL,strMsg,NULL,MB_ICONINFORMATION|MB_OK);
return;
}
m_sizeDoc=CSize((int)::DIBWidth(lpDIB),(int)::DIBHeight(lpDIB));
//ImageInfo.Format("当前图像宽:%d,当前图像高:%d",m_sizeDoc.cx,m_sizeDoc.cy);
::GlobalUnlock((HGLOBAL)m_hDIB);
m_palDIB=new CPalette;
if(m_palDIB==NULL)
{
::GlobalFree((HGLOBAL)m_hDIB);
m_hDIB=NULL;
return;
}
if(::CreateDIBPalette(m_hDIB,m_palDIB)==NULL)
{
delete m_palDIB;
m_palDIB=NULL;
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -