?? palmprintdlg.cpp
字號:
// PalmPrintDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PalmPrint.h"
#include "PalmPrintDlg.h"
#include "dibapi.h"
#include "math.h"
#include <complex>
#define PI 3.14159
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
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()
/////////////////////////////////////////////////////////////////////////////
// CPalmPrintDlg dialog
CPalmPrintDlg::CPalmPrintDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPalmPrintDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPalmPrintDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_hDIB = NULL;
m_palDIB = NULL;
}
void CPalmPrintDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPalmPrintDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPalmPrintDlg, CDialog)
//{{AFX_MSG_MAP(CPalmPrintDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPalmPrintDlg message handlers
BOOL CPalmPrintDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CPalmPrintDlg::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 CPalmPrintDlg::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 CPalmPrintDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPalmPrintDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CFile file;
CFileException fe;
char szFilter[] = "Bitmap Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
CFileDialog fdlg(true, "BMP", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
szFilter);
if(fdlg.DoModal() != IDOK)
return;
CString lpszPathName = fdlg.GetPathName();
// 打開文件
if (!file.Open(lpszPathName, CFile::modeRead | CFile::shareDenyWrite, &fe))
{
return;
}
// 更改光標形狀
BeginWaitCursor();
// 嘗試調用ReadDIBFile()讀取圖像
TRY
{
m_hDIB = ::ReadDIBFile(file);
}
CATCH (CFileException, eLoad)
{
// 讀取失敗
file.Abort();
// 恢復光標形狀
EndWaitCursor();
// 設置DIB為空
m_hDIB = NULL;
return;
}
END_CATCH
// 初始化DIB
::InitDIBData(m_hDIB,m_palDIB);
// 恢復光標形狀
EndWaitCursor();
// 判斷讀取文件是否成功
if (m_hDIB == NULL)
{
// 失敗,可能非BMP格式
CString strMsg;
strMsg = "讀取圖像時出錯!可能是不支持該類型的圖像文件!";
// 提示出錯
MessageBox(strMsg, "系統提示", MB_ICONINFORMATION | MB_OK);
// 返回FALSE
return;
}
// m_hDIBOrigin = (HDIB)CopyHandle((HANDLE)m_hDIB);
DrawBMP(IDC_STATIC,m_hDIB);//繪制原圖像于控件IDC_PIC之上
// DrawBMP(IDC_PIC2,m_hDIBOrigin); //繪制圖像于控件IDC_PIC2之上
// TODO: Add your control notification handler code here
}
void CPalmPrintDlg::DrawBMP(int nID, HDIB ndib)
{
BeginWaitCursor();
// 獲取DIB
HDIB hDIB = ndib;
// 判斷DIB是否為空
if (hDIB != NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
// 獲取DIB寬度
int cxDIB = (int) ::DIBWidth(lpDIB);
// 獲取DIB高度
int cyDIB = (int) ::DIBHeight(lpDIB);
::GlobalUnlock((HGLOBAL) hDIB);
CRect rcDIB;
rcDIB.top = rcDIB.left = 0;
rcDIB.right = cxDIB;
rcDIB.bottom = cyDIB;
CWnd* pWnd=GetDlgItem(nID);
CDC* pDC=pWnd->GetDC();
RECT rect;
pWnd->GetClientRect(&rect);//得到控件矩形區域
CRect rcDest(rect);
// 輸出DIB
::PaintDIB(pDC->m_hDC, &rcDest, hDIB,&rcDIB,m_palDIB);
}
// 恢復正常光標
EndWaitCursor();
}
void CPalmPrintDlg::OnButton3()
{
// TODO: Add your control notification handler code here
// 圖像付立葉變換
// 指向DIB的指針
LPSTR lpDIB;
// 指向DIB象素指針
LPSTR lpDIBBits;
// 鎖定DIB
lpDIB = (LPSTR) ::GlobalLock((HGLOBAL)m_hDIB);
// 找到DIB圖像象素起始位置
lpDIBBits = ::FindDIBBits(lpDIB);
// 判斷是否是8-bpp位圖(這里為了方便,只處理8-bpp位圖的付立葉變換,其它的可以類推)
if (::DIBNumColors(lpDIB) != 256)
{
// 提示用戶
MessageBox("目前只支持256色位圖的付立葉變換!", "系統提示" ,
MB_ICONINFORMATION | MB_OK);
// 解除鎖定
::GlobalUnlock((HGLOBAL)m_hDIB);
// 返回
return;
}
// 更改光標形狀
BeginWaitCursor();
// 調用Fourier()函數進行付立葉變換
if (::Fourier(lpDIBBits, ::DIBWidth(lpDIB), ::DIBHeight(lpDIB)))
{
// 設置臟標記
// pDoc->SetModifiedFlag(TRUE);
// 更新視圖
// pDoc->UpdateAllViews(NULL);
}
else
{
// 提示用戶
MessageBox("分配內存失??!", "系統提示" , MB_ICONINFORMATION | MB_OK);
}
// 解除鎖定
::GlobalUnlock((HGLOBAL)m_hDIB);
// 恢復光標
EndWaitCursor();
DrawBMP(IDC_STATIC,m_hDIB);//繪制原圖像于控件IDC_PIC之上
}
void CPalmPrintDlg::OnButton2()
{
// TODO: Add your control notification handler code here
int h , w ;
int Gmin = 255;
int Gmax = 0;
double t ;
// 圖像每行的字節數
LONG lLineBytes;
// 指向DIB的指針
LPSTR lpDIB;
// 指向DIB象素指針
LPSTR lpDIBBits;
// 鎖定DIB
lpDIB = (LPSTR) ::GlobalLock((HGLOBAL)m_hDIB);
// 找到DIB圖像象素起始位置
lpDIBBits = ::FindDIBBits(lpDIB);
// 計算圖像每行的字節數
lLineBytes = WIDTHBYTES(::DIBWidth(lpDIB) * 8);
for (h=0; h<::DIBHeight(lpDIB); h++)
{
for (w=0; w<::DIBWidth(lpDIB); w++)
{
if(lpDIBBits[h*lLineBytes+w] > Gmax)
Gmax = lpDIBBits[h*lLineBytes+w];
if(lpDIBBits[h*lLineBytes+w] < Gmin)
Gmin = lpDIBBits[h*lLineBytes+w];
}
}
for (h=0; h<::DIBHeight(lpDIB); h++)
{
for (w=0; w<::DIBWidth(lpDIB); w++)
{
t = (double)(lpDIBBits[h*lLineBytes+w]-Gmin)/(double)(Gmax-Gmin);
lpDIBBits[h*lLineBytes+w] = (BYTE)(t*255);
}
}/**/
DrawBMP(IDC_STATIC,m_hDIB);//繪制原圖像于控件IDC_PIC之上
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -