📄 picviewerdoc.cpp
字号:
void CPicViewerDoc::OnUpdateColumn(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 16)) ;
}
void CPicViewerDoc::OnUpdateStripe(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 8)) ;
}
void CPicViewerDoc::OnUpdateSmoothAvg(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnConvolSharp1()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_SHARP_1) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnConvolSharp2()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_SHARP_2) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnConvolSharp3()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_SHARP_3) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnConvolSmooth1()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_SMOOTH_1) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnConvolSmooth2()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_SMOOTH_2) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnConvolSmooth3()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_SMOOTH_3) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateConvolSharp1(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnUpdateConvolSharp2(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnUpdateConvolSharp3(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnUpdateConvolSmooth1(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnUpdateConvolSmooth2(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnUpdateConvolSmooth3(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnConvolEnhanceH()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_ENHANCE_HORZ) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateConvolEnhanceH(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnConvolEnhanceV()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_ENHANCE_VERT) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateConvolEnhanceV(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnConvolEnhanceLap1()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_ENHANCE_LAPLACE1) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateConvolEnhanceLap1(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnConvolEnhanceLap2()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_ENHANCE_LAPLACE2) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateConvolEnhanceLap2(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnConvolEnhanceLap3()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_ENHANCE_LAPLACE3) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateConvolEnhanceLap3(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnConvolEnhanceLap4()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_ENHANCE_LAPLACE4) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateConvolEnhanceLap4(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnConvolEnhanceVh()
{
// TODO: Add your command handler code here
m_fPic.Algorithm (EFFECT_ENHANCE_VERTHORZ) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateConvolEnhanceVh(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnConvolUser()
{
// TODO: Add your command handler code here
}
void CPicViewerDoc::OnUpdateConvolUser(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnUpdateMosaic(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 24)) ;
}
void CPicViewerDoc::OnEffectUndo()
{
// TODO: Add your command handler code here
m_fPic.Undo () ;
this->AttachPic () ;
this->UpdateAllViews (NULL) ;
}
void CPicViewerDoc::OnEffectRedo()
{
// TODO: Add your command handler code here
m_fPic.Redo () ;
this->AttachPic () ;
this->UpdateAllViews (NULL) ;
}
void CPicViewerDoc::OnUpdateEffectUndo(CCmdUI* pCmdUI)
{ pCmdUI->Enable (m_fPic.IsUndoEnable ()) ; }
void CPicViewerDoc::OnUpdateEffectRedo(CCmdUI* pCmdUI)
{ pCmdUI->Enable (m_fPic.IsRedoEnable ()) ; }
void CPicViewerDoc::DeleteContents()
{
m_DDB.Detach () ;
m_fPic.Unload () ;
m_bFirstShow = TRUE ;
CDocument::DeleteContents();
}
void CPicViewerDoc::OnUpdateCountcolor(CCmdUI* pCmdUI)
{ pCmdUI->Enable (m_fPic.GetHandle() != NULL) ; }
void CPicViewerDoc::OnFileOpen()
{
// store in IDS_PICFORMAT
/* Picture Files (*.bmp, *.jpg, *.gif, *.tif, *.pcx, *.tga, *.png)|*.bmp; *.jpg; *.jpeg; *.gif; *.tif; *.tiff; *.pcx; *.tga; *.png|
Bitmap Files (*.bmp)|*.bmp|
JPEG Files (*.jpg;*.jpeg)|*.jpg; *.jpeg|
Gif Files (*.gif)|*.gif|
Png Files (*.png)|*.png|
Tiff Files (*.tif)|*.tif; *.tiff|
Pcx Files (*.pcx)|*.pcx|
Tga Files (*.tga)|*.tga|
All Files (*.*)|*.*|| */
CString Filter ;
Filter.LoadString (IDS_PICFORMAT) ;
CSelectFileDlg dlgFile (TRUE, NULL, NULL, OFN_HIDEREADONLY, Filter, NULL) ;
if (dlgFile.DoModal() == IDCANCEL)
return ;
DeleteContents () ;
CWaitCursor waitCursor ;
if (m_fPic.Load (dlgFile.GetPathName()) == IMAGE_UNKNOW)
{
::MessageBox (NULL, _T("读取文件失败,此格式无效或不支持"), _T("错误"), MB_OK | MB_ICONINFORMATION) ;
return ;
}
this->SetPathName (dlgFile.GetPathName()) ; // pass the parameter to OnSaveDocument
m_DDB.Attach (m_fPic.GetHandle ()) ; // Get DDB
m_fPic.SetUndoEnable (true) ; // set undo-flag
m_bFirstShow = TRUE ;
this->UpdateAllViews (NULL) ;
}
void CPicViewerDoc::OnFileSaveAs()
{
CString Filter ;
Filter.LoadString (IDS_PICFORMAT) ;
CSelectFileDlg dlgFile (FALSE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, Filter, NULL) ;
if (dlgFile.DoModal() == IDCANCEL)
return ;
CWaitCursor waitCursor ;
if (!m_fPic.Save (dlgFile.GetPathName()))
{
::MessageBox (NULL, _T("保存文件失败! 请检查是否指定扩展名"), _T("错误"), MB_OK | MB_ICONINFORMATION) ;
return ;
}
SetModifiedFlag (FALSE) ;
}
void CPicViewerDoc::OnSphere()
{
m_fPic.Sphere () ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateSphere(CCmdUI* pCmdUI)
{ pCmdUI->Enable (FALSE) ; }
void CPicViewerDoc::OnUpdatePickkeycolor(CCmdUI* pCmdUI)
{ pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() >= 16)) ; }
void CPicViewerDoc::OnPickkeycolor()
{
RGBQUAD rgb ;
CString str ;
if (m_fPic.TakeKeyColor (&rgb))
str.Format (_T("R : %i\tG : %i\tB : %i"), rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue) ;
else
str.Format (_T("不能获取透明色!")) ;
::MessageBox (::AfxGetMainWnd()->m_hWnd, str, _T("获取透明色"), MB_OK) ;
}
void CPicViewerDoc::OnConvertGray()
{ m_fPic.ConvertToGray () ; this->AttachPic () ; }
void CPicViewerDoc::OnUpdateConvertGray(CCmdUI* pCmdUI)
{ pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && !m_fPic.IsGrayPalette ()) ; }
void CPicViewerDoc::OnConvertTo32()
{ m_fPic.ConvertTo32Bit () ; this->AttachPic () ; }
void CPicViewerDoc::OnUpdateConvertTo32(CCmdUI* pCmdUI)
{ pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() != 32)) ; }
void CPicViewerDoc::OnConvertTo24()
{ m_fPic.ConvertTo24Bit () ; this->AttachPic () ; }
void CPicViewerDoc::OnUpdateConvertTo24(CCmdUI* pCmdUI)
{ pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() != 24)) ; }
void CPicViewerDoc::OnConvertTo16()
{
if (m_fPic.ColorsUsed () > 0x10000)
if (IDYES == ::MessageBox (NULL, TEXT("图像使用颜色数大于65536种,转换会丢失颜色,是否继续转换?"), TEXT("warning"), MB_YESNO))
{
m_fPic.ConvertTo16Bit () ; this->AttachPic () ;
}
else
return ;
else
{
m_fPic.ConvertTo16Bit () ; this->AttachPic () ;
}
}
void CPicViewerDoc::OnUpdateConvertTo16(CCmdUI* pCmdUI)
{ pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (m_fPic.ColorBits() != 16)) ; }
void CPicViewerDoc::OnSpliteChannel()
{
FCDib red ;
FCDib green ;
FCDib blue ;
FCDib alpha ;
CWaitCursor * wait = new CWaitCursor ;
m_fPic.GetRGBChannel (&red, &green, &blue, &alpha) ;
delete wait ;
POSITION posTemplate = ::AfxGetApp ()->GetFirstDocTemplatePosition () ;
CDocTemplate * pDocTemplate = ::AfxGetApp ()->GetNextDocTemplate (posTemplate) ;
CPicViewerDoc * pDocument = (CPicViewerDoc*) pDocTemplate->OpenDocumentFile (NULL) ;
pDocument->m_fPic = red ;
pDocument->AttachPic () ;
pDocument->m_bFirstShow = FALSE ;
pDocument->SetModifiedFlag (TRUE) ;
pDocument->UpdateAllViews (NULL) ;
pDocument->SetTitle (GetTitle () + _T(" [Red Channel]")) ;
pDocument = (CPicViewerDoc*) pDocTemplate->OpenDocumentFile (NULL) ;
pDocument->m_fPic = green ;
pDocument->AttachPic () ;
pDocument->m_bFirstShow = FALSE ;
pDocument->SetModifiedFlag (TRUE) ;
pDocument->UpdateAllViews (NULL) ;
pDocument->SetTitle (GetTitle () + _T(" [Green Channel]")) ;
pDocument = (CPicViewerDoc*) pDocTemplate->OpenDocumentFile (NULL) ;
pDocument->m_fPic = blue ;
pDocument->AttachPic () ;
pDocument->m_bFirstShow = FALSE ;
pDocument->SetModifiedFlag (TRUE) ;
pDocument->UpdateAllViews (NULL) ;
pDocument->SetTitle (GetTitle () + _T(" [Blue Channel]")) ;
if (m_fPic.ColorBits () == 32)
{
pDocument = (CPicViewerDoc*) pDocTemplate->OpenDocumentFile (NULL) ;
pDocument->m_fPic = alpha ;
pDocument->AttachPic () ;
pDocument->m_bFirstShow = FALSE ;
pDocument->SetModifiedFlag (TRUE) ;
pDocument->UpdateAllViews (NULL) ;
pDocument->SetTitle (GetTitle () + _T(" [Alpha Channel]")) ;
}
}
void CPicViewerDoc::OnUpdateSpliteChannel(CCmdUI* pCmdUI)
{ pCmdUI->Enable (m_fPic.ColorBits() >= 24) ; }
BOOL CPicViewerDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
CWaitCursor waitcur ;
BOOL bRet = m_fPic.Save (lpszPathName) ;
if (!bRet)
ReportSaveLoadException (lpszPathName, NULL, FALSE, AFX_IDP_FAILED_TO_SAVE_DOC) ;
SetModifiedFlag (FALSE) ;
return bRet ;
}
BOOL CPicViewerDoc::OnNewDocument()
{
return CDocument::OnNewDocument();
}
void CPicViewerDoc::OnViewRealsize()
{
m_DDB.SetZoomScale (1) ;
this->UpdateAllViews (NULL) ;
}
void CPicViewerDoc::OnUpdateViewRealsize(CCmdUI* pCmdUI)
{ pCmdUI->Enable ((m_fPic.GetHandle() != NULL) && (abs (m_DDB.GetZoomScale ()) != 1)) ; }
// Paste From Clipboard
void CPicViewerDoc::OnEditPaste()
{
if (m_fPic.HasSelection ())
{
RECT box ;
m_fPic.GetBoundBox (&box) ;
m_fPic.PasteFromClipboard (&box) ;
}
else
m_fPic.PasteFromClipboard (NULL) ;
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateEditPaste(CCmdUI* pCmdUI)
{ pCmdUI->Enable (m_fPic.IsPasteAvailable ()) ; }
// select whole picture, i.e. clear selection
void CPicViewerDoc::OnSelectAll()
{
m_fPic.ClearSelection () ;
this->UpdateAllViews (NULL) ;
}
void CPicViewerDoc::OnUpdateSelectAll(CCmdUI* pCmdUI)
{ pCmdUI->Enable (m_fPic.GetHandle() != NULL) ; }
// cut a block
void CPicViewerDoc::OnEditCut()
{
RGBQUAD white = {255, 255, 255, 0} ;
if (m_fPic.HasSelection ())
{
RECT box ;
m_fPic.GetBoundBox (&box) ;
m_fPic.CopyToClipboard (&box) ;
m_fPic.RegionFill (white, &box) ;
}
else
{
m_fPic.CopyToClipboard (NULL) ;
m_fPic.RegionFill (white, NULL) ;
}
this->AttachPic () ;
}
void CPicViewerDoc::OnUpdateEditCut(CCmdUI* pCmdUI)
{ pCmdUI->Enable ((m_fPic.GetHandle () != NULL) && (m_fPic.ColorBits() > 8)) ; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -