HebingDlg.cpp
上传用户:aqingfeng
上传日期:2014-03-25
资源大小:1839k
文件大小:11k
- // HebingDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "小波变换.h"
- #include "HebingDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CHebingDlg dialog
- CHebingDlg::CHebingDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CHebingDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CHebingDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CHebingDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CHebingDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CHebingDlg, CDialog)
- //{{AFX_MSG_MAP(CHebingDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
- ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
- ON_BN_CLICKED(IDC_BUTTON5, OnButton5) // NOTE: the ClassWizard will add message map macros here
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CHebingDlg message handlers
- BOOL CHebingDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- // TODO: Add extra initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
- // 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 CHebingDlg::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);
- 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 CHebingDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CHebingDlg::OnButton1()
- {
- // TODO: Add your control notification handler code here
- static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
- CFileDialog fd(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
- if(fd.DoModal()==IDOK)
- filename1=fd.GetPathName();
-
- }
- void CHebingDlg::OnButton2()
- {
- // TODO: Add your control notification handler code here
- static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
- CFileDialog fd(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
- if(fd.DoModal()==IDOK)
- filename2=fd.GetPathName();
- }
- void CHebingDlg::OnButton3()
- {
- // TODO: Add your control notification handler code here
- static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
- CFileDialog fd(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
- if(fd.DoModal()==IDOK)
- filename3=fd.GetPathName();
- }
- void CHebingDlg::OnButton4()
- {
- // TODO: Add your control notification handler code here
- static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
- CFileDialog fd(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
- if(fd.DoModal()==IDOK)
- filename4=fd.GetPathName();
-
- }
- void CHebingDlg::OnButton5()
- {
- // TODO: Add your control notification handler code here
- if(filename1.IsEmpty())
- {
- MessageBox("未选择图片!");
- return;
- }
- if(filename2.IsEmpty())
- {
- MessageBox("未选择图片");
- return;
- }
- if(filename3.IsEmpty())
- {
- MessageBox("未选择图片!");
- return;
- }
- if(filename4.IsEmpty())
- {
- MessageBox("未选择图片!");
- return;
- }
- CFile file1,file3,file2,file5,file4;
- //打开文件1和2
- static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
- CFileDialog fd(false,"*.bmp","*.bmp", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
- CString filename;
- if(fd.DoModal()==IDOK)
- { filename=fd.GetPathName();
-
- file1.Open(filename1,CFile::modeRead|CFile::shareDenyWrite,NULL);
- file2.Open(filename2,CFile::modeRead|CFile::shareDenyWrite,NULL);
- file3.Open(filename3,CFile::modeRead|CFile::shareDenyWrite,NULL);
- file4.Open(filename4,CFile::modeRead|CFile::shareDenyWrite,NULL);
- LPBITMAPFILEHEADER bmpfilehead1,bmpfilehead2,bmpfilehead3,bmpfilehead4,bmpfilehead5;
- LPBITMAPINFOHEADER bmpfileinfo1,bmpfileinfo2,bmpfileinfo3,bmpfileinfo4,bmpfileinfo5;
- //分配三个文件头的内存
-
- bmpfilehead1=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
- bmpfilehead2=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
- bmpfilehead3=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
- bmpfilehead4=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
- bmpfilehead5=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
- //分配三个信息头的内存
- bmpfileinfo1=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
- bmpfileinfo2=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
- bmpfileinfo3=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
- bmpfileinfo4=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
- bmpfileinfo5=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
-
- //读file1和file2的文件头和信息头
- file1.Read(bmpfilehead1,sizeof(BITMAPFILEHEADER));
- file1.Read(bmpfileinfo1,sizeof(BITMAPINFOHEADER));
- file2.Read(bmpfilehead2,sizeof(BITMAPFILEHEADER));
- file2.Read(bmpfileinfo2,sizeof(BITMAPINFOHEADER));
- file3.Read(bmpfilehead3,sizeof(BITMAPFILEHEADER));
- file3.Read(bmpfileinfo3,sizeof(BITMAPINFOHEADER));
- file4.Read(bmpfilehead4,sizeof(BITMAPFILEHEADER));
- file4.Read(bmpfileinfo4,sizeof(BITMAPINFOHEADER));
- if(bmpfileinfo1->biHeight!=bmpfileinfo2->biHeight)
- {
- MessageBox("两文件高不一致,不能合并");
- exit(0);
- }
- //复制一个文件头和信息头到file3中
- ::CopyMemory(bmpfileinfo5,bmpfileinfo1,sizeof(BITMAPINFOHEADER));
- ::CopyMemory (bmpfilehead5,bmpfilehead1,sizeof(BITMAPFILEHEADER));
- //分配file1的数据区内存
- DWORD bmp1size;
- bmp1size=bmpfilehead1->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024;
- char *bmpdata1;
- bmpdata1=(char*)::VirtualAlloc(NULL,bmp1size,MEM_COMMIT,PAGE_READWRITE);
- //HGLOBAL tempbmpdata1=::GlobalAlloc(GHND,bmp1size);
- //bmpdata1=(char*)::GlobalLock (tempbmpdata1);
- //分配file2的数据区内存
- DWORD bmp2size;
- bmp2size=bmpfilehead2->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024;
- char *bmpdata2;
- bmpdata2=(char*)::VirtualAlloc(NULL,bmp2size,MEM_COMMIT,PAGE_READWRITE);
- //HGLOBAL tempbmpdata2=::GlobalAlloc(GHND, bmp2size);
- //bmpdata2=(char*)::GlobalLock (tempbmpdata2);
- DWORD bmp3size;
- bmp3size=bmpfilehead3->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024;
- char *bmpdata3;
- bmpdata3=(char*)::VirtualAlloc(NULL,bmp2size,MEM_COMMIT,PAGE_READWRITE);
- //HGLOBAL tempbmpdata2=::GlobalAlloc(GHND, bmp2size);
- //bmpdata2=(char*)::GlobalLock (tempbmpdata2);
- DWORD bmp4size;
- bmp4size=bmpfilehead4->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024;
- char *bmpdata4;
- bmpdata4=(char*)::VirtualAlloc(NULL,bmp2size,MEM_COMMIT,PAGE_READWRITE);
- //HGLOBAL tempbmpdata2=::GlobalAlloc(GHND, bmp2size);
- //bmpdata2=(char*)::GlobalLock (tempbmpdata2);
- //读file1和file2的数据区
- file1.Seek(1024+54,CFile::begin);
- file1.ReadHuge(bmpdata1,(bmpfilehead1->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024));
- file2.Seek(1024+54,CFile::begin);
- file2.ReadHuge(bmpdata2,(bmpfilehead2->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024));
- file3.Seek(1024+54,CFile::begin);
- file3.ReadHuge(bmpdata3,(bmpfilehead2->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024));
- file4.Seek(1024+54,CFile::begin);
- file4.ReadHuge(bmpdata4,(bmpfilehead2->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024));
- //把file1和file2的数据区合并到file3的数据区中
- DWORD endbmpsize;
- endbmpsize=bmpfilehead1->bfSize-3*sizeof(BITMAPFILEHEADER)-
- 3*sizeof(BITMAPINFOHEADER)-2048*2+bmpfilehead2->bfSize+bmpfilehead3->bfSize+bmpfilehead4->bfSize;
- char *endbmp;
- endbmp=(char*)::VirtualAlloc(NULL,endbmpsize,MEM_COMMIT,PAGE_READWRITE);
- //HGLOBAL endbmpdata=::GlobalAlloc(GHND,endbmpsize);
- //endbmp=(char*)::GlobalLock (endbmpdata);
-
- char *temp1=NULL;
- char *temp2=NULL;
- char *temp3=NULL;
- char *temp4=NULL;
- char *temp5=NULL;
- temp1=bmpdata1;
- temp2=bmpdata2;
- temp3=bmpdata3;
- temp4=bmpdata4;
- temp5=endbmp;
- for(int j=0;j<bmpfileinfo1->biHeight;j++)//
- {
- ::CopyMemory(temp5,temp1,bmpfileinfo1->biWidth);
- //if((temp1-bmpdata1)<=bmp1size)
- temp1+=bmpfileinfo1->biWidth ;
- //if((temp3-endbmp)<= endbmpsize)
- temp5+=bmpfileinfo1->biWidth ;
- ::CopyMemory(temp5,temp2,bmpfileinfo2->biWidth);
- //if((temp2-bmpdata2)<= bmp2size)
- temp2+=bmpfileinfo2->biWidth;
- //if((temp3-endbmp)<= endbmpsize)
- temp5+=bmpfileinfo2->biWidth;
- ::CopyMemory(temp5,temp3,bmpfileinfo3->biWidth);
- //if((temp2-bmpdata2)<= bmp2size)
- temp3+=bmpfileinfo3->biWidth;
- //if((temp3-endbmp)<= endbmpsize)
- temp5+=bmpfileinfo3->biWidth;
- ::CopyMemory(temp5,temp4,bmpfileinfo4->biWidth);
- //if((temp2-bmpdata2)<= bmp2size)
- temp4+=bmpfileinfo4->biWidth;
- //if((temp3-endbmp)<= endbmpsize)
- temp5+=bmpfileinfo4->biWidth;
-
- }
-
- file5.Open(filename,CFile::modeNoTruncate|CFile::modeCreate|CFile::modeReadWrite,NULL);
- //设置file3的调色板
- char temp[1024];
- for(int i=0;i<256;i++)
- {
- temp[i*4]=i;
- temp[i*4+1]=i;
- temp[i*4+2]=i;
- temp[i*4+3]=0;
- }
- bmpfilehead5->bfSize=bmpfilehead2->bfSize -3*sizeof(BITMAPFILEHEADER)-
- 3*sizeof(BITMAPINFOHEADER)-3*1024+bmpfilehead1->bfSize+bmpfilehead3->bfSize+bmpfilehead4->bfSize;
- bmpfileinfo5->biWidth=bmpfileinfo1->biWidth+bmpfileinfo2->biWidth+bmpfileinfo3->biWidth+bmpfileinfo4->biWidth;
- file5.Write(bmpfilehead5,sizeof(BITMAPFILEHEADER));//写file3的文件头
- file5.Write(bmpfileinfo5,sizeof(BITMAPINFOHEADER));//写file3的信息头
- file5.Write(temp,1024);//写file3的调色板
- file5.Write(endbmp,endbmpsize);
- free(bmpfilehead1);
- free(bmpfilehead2);
- free(bmpfilehead3);
- free(bmpfilehead4);
- free(bmpfilehead5);
- free(bmpfileinfo1);
- free(bmpfileinfo2);
- free(bmpfileinfo3);
- free(bmpfileinfo4);
- free(bmpfileinfo5);
- //::GlobalFree(tempbmpdata1);
- //::GlobalFree(tempbmpdata2);
- //::GlobalFree(endbmpdata);
- ::VirtualFree(bmpdata1,bmp1size,MEM_COMMIT);
- ::VirtualFree(bmpdata2,bmp2size,MEM_COMMIT);
- ::VirtualFree(bmpdata3,bmp2size,MEM_COMMIT);
- ::VirtualFree(bmpdata4,bmp2size,MEM_COMMIT);
- ::VirtualFree(endbmp,endbmpsize,MEM_COMMIT);
- file1.Close();
- file2.Close();
- file3.Close();
- file4.Close();
- file5.Close();
- MessageBox("合并完成");
- }
-
- }