📄 图像水印view.cpp
字号:
// 图像水印View.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "图像水印.h"
#include "图像水印Doc.h"
#include "图像水印View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_EMBED, OnEmbed)
ON_UPDATE_COMMAND_UI(ID_EMBED, OnUpdateEmbed)
ON_COMMAND(ID_PICK, OnPick)
ON_UPDATE_COMMAND_UI(ID_PICK, OnUpdatePick)
ON_COMMAND(ID_NORMAL, OnNormal)
ON_COMMAND(ID_STRETCH, OnStretch)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction
CMyView::CMyView()
{
// TODO: add construction code here
}
CMyView::~CMyView()
{
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
RECT Rect;
GetClientRect(&Rect);
if(!show_contrast)
m_Dib.Draw(pDC,0,0,Rect.right ,Rect.bottom ,ImageStyle);
else
{
m_Dib.DrawContrast (pDC,Rect.right ,Rect.bottom );
// pDC->SetBkColor ((0,0,0));
// pDC->SetTextColor ((255,255,255));
// pDC->TextOut (0,Rect.bottom -30,"左图为原始图,右图为嵌入了隐藏信息的图片");
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyView printing
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
void CMyView::OnFileOpen()
{
// TODO: Add your command handler code here
show_contrast = false; //非对比显示
// TODO: Add your command handler code here
static char szFilter[] = "BMP Files(*.BMP)|*.BMP||";
CFileDialog FileDlg( TRUE, NULL, NULL,
OFN_HIDEREADONLY, szFilter );
if( FileDlg.DoModal() == IDOK &&
m_Dib.Load( FileDlg.GetPathName() ) )
{
InvalidateRect( NULL, TRUE );
UpdateWindow();
have_open_a_file=true;
if (m_Dib.tag == 0)//该图无隐藏信息
{
embed = true;
pick = false; //菜单亮暗控制
}//
else
{
embed = false;
pick = true; //菜单亮暗控制
}//
}
}
void CMyView::OnEmbed()
{
// TODO: Add your command handler code here
//弹出打开对话框,用户选择嵌入的文件
static char szFilter[] = "All Files(*.*)|*.*||";
CFileDialog FileDlg( TRUE, NULL, NULL,
OFN_HIDEREADONLY, szFilter );
if( FileDlg.DoModal() == IDOK &&
m_Dib.LoadEmbFile( FileDlg.GetPathName() ) )
{
if (m_Dib.bitmap_size / m_Dib.embfile_size < 8)
{
AfxMessageBox("文件太大,无法嵌入!");
}
else
{
show_contrast = true;
m_Dib.BackUpDib(); //图片原始数据备份供对比显示
m_Dib.Embed(); //嵌入
Invalidate(true);//刷屏,显示加入隐藏信息后的图像
static char szFilter[] = "BMP Files(*.BMP)|*.BMP||";
CFileDialog FileDlg( FALSE, "bmp", NULL, //保存
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter );
if( FileDlg.DoModal() == IDOK )
{
m_Dib.Save( FileDlg.GetPathName() );
}
embed = false;
}
}
}
void CMyView::OnUpdateEmbed(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(embed);
}
void CMyView::OnPick()
{
// TODO: Add your command handler code here
//提取完毕,弹出保存对话框,用户进行保存
static char szFilter[] = "BMP Files(*.BMP)|*.BMP|All Files(*.*)|*.*||";
CFileDialog FileDlg( FALSE, " ", NULL, //保存
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter );
if (FileDlg.DoModal() == IDOK)
{
m_Dib.Pick();
m_Dib.SavePicked(FileDlg.GetPathName());
pick = false;
}
}
void CMyView::OnUpdatePick(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(pick);
}
void CMyView::OnNormal()
{
// TODO: Add your command handler code here
ImageStyle = 0;
CMenu *pMnu = AfxGetMainWnd()->GetMenu( );
pMnu->CheckMenuItem(ID_STRETCH,MF_UNCHECKED);
pMnu->CheckMenuItem(ID_NORMAL,MF_CHECKED);
InvalidateRect( NULL, TRUE );
UpdateWindow();
}
void CMyView::OnStretch()
{
// TODO: Add your command handler code here
ImageStyle = 1;
CMenu *pMnu = AfxGetMainWnd()->GetMenu( );
pMnu->CheckMenuItem(ID_STRETCH,MF_CHECKED);
pMnu->CheckMenuItem(ID_NORMAL,MF_UNCHECKED);
InvalidateRect( NULL, TRUE );
UpdateWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -