16,548
社区成员




// watermarkDlg.cpp : implementation file
//
#include "stdafx.h"
#include "watermark.h"
#include "watermarkDlg.h"
#include "math.h"
#include "Dib.h"
#include "IntextDlg.h"
#include "DiTextDlg.h"
#include "AtTextDlg.h"
#include "JPEG.h"
#include "PSNR.h"
#include <string>
using namespace std;
//#include <afxwin.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CString Intext;
CString Douttext;
//CString strMessage1;
/*-----------------5.18-----------------------------------------*/
//int InSeq;
/*-----------------5.18-----------------------------------------*/
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWatermarkDlg dialog
CWatermarkDlg::CWatermarkDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWatermarkDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWatermarkDlg)
m_alphazhi = 0.0f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nClickCount = 0;
m_alphazhi = 0.1f;
}
void CWatermarkDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWatermarkDlg)
// DDX_Radio(pDX, IDC_IMA_FORM, m_formxz);
// DDX_Radio(pDX, IDC_DCT_ARI, m_arithmaticxz);
// DDX_Radio(pDX, IDC_RAD_NOISE, m_gongjixz);
DDX_Text(pDX, IDC_ALPHA, m_alphazhi);
DDV_MinMaxFloat(pDX, m_alphazhi, 0.f, 1.f);
// DDX_Text(pDX, IDC_REMIND, m_remindmsg);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWatermarkDlg, CDialog)
//{{AFX_MSG_MAP(CWatermarkDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_IMAGE_OPEN, OnImageOpen)
ON_BN_CLICKED(IDC_WATERMARKED_OPEN, OnWatermarkedOpen)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWatermarkDlg message handlers
BOOL CWatermarkDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// this->m_remindmsg = "步骤:\r\n\r\n1、请选择水印格式;\r\n2、请输入水印;\r\n3、请输入原始图像;\r\n4、请选择算法;\r\n5、请点击嵌入按钮。\r\n";
// this->UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CWatermarkDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWatermarkDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
ValidateRect(rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CWatermarkDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/*void CWatermarkDlg::OnMarkOpen() //打开原始水印
{
// TODO: Add your control notification handler code here
CFileDialog fd(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"BMP files (*.bmp)|*.bmp|all files (*.*)|*.*|" );
if(fd.DoModal()!=IDOK)
{
return;
}
CString filename;
filename=fd.GetPathName();
markname=filename;
CFile cf;//文件变量,用来对文件操作
CFileException e;//出错处理
if (!cf.Open(filename,CFile::modeRead, &e))//找到文件后,打开文件
{
MessageBox("Can not open the file!");
return;
}
//显示等待光标
BeginWaitCursor();
// 获取DIB
m_mark.Read(&cf);
CDC *dc=GetDC();
m_Width1 =m_mark.GetWidth();
m_Height1 =m_mark.GetHeight();
//m_mark.Display(dc,30,30);//原始图像
m_Dib.mark=m_mark.m_hDib;
}*/
void CWatermarkDlg::OnImageOpen() //打开原始图像
{
// TODO: Add your control notification handler code here
CFileDialog fd(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"BMP files (*.bmp)|*.bmp|all files (*.*)|*.*|" );
if(fd.DoModal()!=IDOK)
{
return;
}
// CString filename;
m_strImageFile = fd.GetPathName();
CFile cf;//文件变量,用来对文件操作
CFileException e;//出错处理
if (!cf.Open(m_strImageFile,CFile::modeRead, &e))//找到文件后,打开文件
{
MessageBox("Can not open the file!");
return;
}
//显示等待光标
BeginWaitCursor();
m_Dib.Read(&cf);
CDC *dc=GetDC();
m_Height=m_Dib.GetHeight();
m_Width=m_Dib.GetWidth();
m_nRows = m_Height;
m_nCols = m_Width;
HDIB hDIB = CopyHandle(m_Dib.m_hDib);
m_image.m_hDib = hDIB;
m_image.BuildPalette();
m_image.BuildBitmap();
//m_image.Display(dc,270,30);//,300,300,0,0,m_Width,m_Height
}
void CWatermarkDlg::OnWatermarkedOpen() //打开带水印图像
{
// TODO: Add your control notification handler code here
CFileDialog fd(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"BMP files (*.bmp)|*.bmp|all files (*.*)|*.*|" );
if(fd.DoModal()!=IDOK)
{
return;
}
CString filename;
filename=fd.GetPathName();
CFile cf;//文件变量,用来对文件操作
CFileException e;//出错处理
if (!cf.Open(filename,CFile::modeRead, &e))//找到文件后,打开文件
{
MessageBox("Can not open the file!");
return;
}
//显示等待光标
BeginWaitCursor();
m_Dib.Read(&cf);
CDC *dc=GetDC();
m_Height=m_Dib.GetHeight();
m_Width=m_Dib.GetWidth();
HDIB hDIB = CopyHandle(m_Dib.m_hDib);
m_marked.m_hDib = hDIB;
m_marked.BuildPalette();
m_marked.BuildBitmap();
m_marked.Display(dc,600,30);//嵌入后显示位置
}
// ** include the required class definition
#include "DiTextDlg.h"
// ** Declare global pointer to the modeless dialog
CDiTextDlg* g_pDlgDiText = NULL;
CIntextDlg *g_pDlgIntext = NULL;
void CWatermarkDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData();
CFileDialog *lpOpenFile;
CString szFilter=_T("Data File(*.txt)|*.txt||");
CString none2=_T("");
CString m_GetFilePath;
lpOpenFile=new CFileDialog(1,none2,none2,OFN_FILEMUSTEXIST,szFilter);
int iLen, len;
if(lpOpenFile->DoModal()==IDOK)
{
Invalidate(true);
UpdateWindow();
m_GetFilePath=lpOpenFile->GetPathName();
CFile file(m_GetFilePath,CFile::modeRead);
char *pBuf;
char buf[500]={0};
iLen=file.GetLength();
pBuf=new char[iLen];
file.Read(pBuf,iLen);
file.Close();
for(int i=0;i<500;i++)
buf[i]=pBuf[i*5];
// mylen=strlen(Myshu);
mylen=mylen+500;
//Myshu = new char[mylen];
strcat(Myshu,buf);
MessageBox(Myshu);
count = count +1;
this->m_remindmsg = "%d",count;
UpdateData();
len = mylen;
m_Dib.LSBEmbed(Myshu, len);
}
delete lpOpenFile;
HDIB hDIB = CopyHandle(m_Dib.m_hDib);
m_marked.m_hDib = hDIB;
m_marked.BuildPalette();
m_marked.BuildBitmap();
CDC *dc=GetDC();
m_marked.Display(dc,600,30);//嵌入后显示位置
m_marked.Save("marked.bmp");
m_strMarkedFile = "marked.bmp";
DiOutTxt = m_Dib.LSBPick(len);
if (m_nClickCount==0)
{
CDiTextDlg *dlgOuttext;
dlgOuttext = new CDiTextDlg;
dlgOuttext->m_ditext_out=new char [len];
dlgOuttext->m_ditext_out=DiOutTxt;
dlgOuttext->DoModal();
}
else
{
CAtTextDlg *dlgAOuttext;
dlgAOuttext = new CAtTextDlg;
dlgAOuttext->m_attext=DiOutTxt;
dlgAOuttext->DoModal();
}
}
void CWatermarkDlg::OnButton2()
{
// TODO: Add your control notification handler code here
}
void CWatermarkDlg::OnButton5()
{
// TODO: Add your control notification handler code here
}