




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、图像处理程序框架说明图像处理使用了统一的程序框架,结构如下图:res 目录是程序使用的一些图标和图片文件,内容如下:MyDip.dsw是工程文件,*.h是相关头文件,*.cpp是c源文件。对于本项目中各种图像处理,都统一使用了这一相同的框架。因此,各图像处理的源程序大部分都相同,不同的主要是MyDIPView.cpp不同图像处理的源程序只要把相应的MyDIPView.cpp文件替换掉就可以。框架中其它相同的文件如下:MainFrm.h:/ MainFrm.h : interface of the CMainFrame class/#if !defined(AFX_MAINFRM_H_985B7
2、281_641A_418D_BAEC_55EB8382DA1A_INCLUDED_)#define AFX_MAINFRM_H_985B7281_641A_418D_BAEC_55EB8382DA1A_INCLUDED_#if _MSC_VER > 1000#pragma once#endif / _MSC_VER > 1000class CMainFrame : public CFrameWndprotected: / create from serialization onlyCMainFrame();DECLARE_DYNCREATE(CMainFrame)/ Attribu
3、tespublic:/ Operationspublic:/ Overrides/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CMainFrame)virtual BOOL PreCreateWindow(CREATESTRUCT& cs);/AFX_VIRTUAL/ Implementationpublic:virtual CMainFrame();#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext&am
4、p; dc) const;#endifprotected: / control bar embedded membersCStatusBar m_wndStatusBar;CToolBar m_wndToolBar;/ Generated message map functionsprotected:/AFX_MSG(CMainFrame)afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);/ NOTE - the ClassWizard will add and remove member functions here./ DO NOT E
5、DIT what you see in these blocks of generated code!/AFX_MSGDECLARE_MESSAGE_MAP();/AFX_INSERT_LOCATION/ Microsoft Visual C+ will insert additional declarations immediately before the previous line.#endif / !defined(AFX_MAINFRM_H_985B7281_641A_418D_BAEC_55EB8382DA1A_INCLUDED_)MainFrm.cpp:/ MainFrm.cpp
6、 : implementation of the CMainFrame class/#include "stdafx.h"#include "MyDIP.h"#include "MainFrm.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CMainFrameIMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)BEGIN_MESSAGE_MAP(CMainFrame,
7、CFrameWnd)/AFX_MSG_MAP(CMainFrame)/ NOTE - the ClassWizard will add and remove mapping macros here./ DO NOT EDIT what you see in these blocks of generated code !ON_WM_CREATE()/AFX_MSG_MAPEND_MESSAGE_MAP()static UINT indicators =ID_SEPARATOR, / status line indicatorID_INDICATOR_CAPS,ID_INDICATOR_NUM,
8、ID_INDICATOR_SCRL,;/ CMainFrame construction/destructionCMainFrame:CMainFrame()/ TODO: add member initialization code hereCMainFrame:CMainFrame()int CMainFrame:OnCreate(LPCREATESTRUCT lpCreateStruct)if (CFrameWnd:OnCreate(lpCreateStruct) = -1)return -1;if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT,
9、WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) |!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)TRACE0("Failed to create toolbarn");return -1; / fail to createif (!m_wndStatusBar.Create(this) |!m_wndStatusBar.SetIndicators(indicators, sizeof(indica
10、tors)/sizeof(UINT)TRACE0("Failed to create status barn");return -1; / fail to create/ TODO: Delete these three lines if you don't want the toolbar to/ be dockablem_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockControlBar(&m_wndToolBar);return 0;BOOL CMa
11、inFrame:PreCreateWindow(CREATESTRUCT& cs)if( !CFrameWnd:PreCreateWindow(cs) )return FALSE;/ TODO: Modify the Window class or styles here by modifying/ the CREATESTRUCT csreturn TRUE;/ CMainFrame diagnostics#ifdef _DEBUGvoid CMainFrame:AssertValid() constCFrameWnd:AssertValid();void CMainFrame:Du
12、mp(CDumpContext& dc) constCFrameWnd:Dump(dc);#endif /_DEBUG/ CMainFrame message handlersdibapi.h:/ dibapi.h/ This is a part of the Microsoft Foundation Classes C+ library./ Copyright (C) 1992-1997 Microsoft Corporation/ All rights reserved./ This source code is only intended as a supplement to t
13、he/ Microsoft Foundation Classes Reference and related/ electronic documentation provided with the library./ See these sources for detailed information regarding the/ Microsoft Foundation Classes product.#ifndef _INC_DIBAPI#define _INC_DIBAPI/* Handle to a DIB */DECLARE_HANDLE(HDIB);/* DIB constants
14、 */#define PALVERSION 0x300/* DIB Macros*/#define IS_WIN30_DIB(lpbi) (*(LPDWORD)(lpbi) = sizeof(BITMAPINFOHEADER)#define RECTWIDTH(lpRect) (lpRect)->right - (lpRect)->left)#define RECTHEIGHT(lpRect) (lpRect)->bottom - (lpRect)->top)/ WIDTHBYTES performs DWORD-aligning of DIB scanlines. T
15、he "bits"/ parameter is the bit count for the scanline (biWidth * biBitCount),/ and this macro returns the number of DWORD-aligned bytes needed/ to hold those bits.#define WIDTHBYTES(bits) (bits) + 31) / 32 * 4)/* Function prototypes */BOOL WINAPI PaintDIB (HDC, LPRECT, HDIB, LPRECT, CPale
16、tte* pPal);BOOL WINAPI CreateDIBPalette(HDIB hDIB, CPalette* cPal);LPSTR WINAPI FindDIBBits (LPSTR lpbi);DWORD WINAPI DIBWidth (LPSTR lpDIB);DWORD WINAPI DIBHeight (LPSTR lpDIB);WORD WINAPI PaletteSize (LPSTR lpbi);WORD WINAPI DIBNumColors (LPSTR lpbi);HGLOBAL WINAPI CopyHandle (HGLOBAL h);BOOL WINA
17、PI SaveDIB (HDIB hDib, CFile& file);HDIB WINAPI ReadDIBFile(CFile& file);HDIB WINAPI NewDIB(long width, long height, unsigned short biBitCount= 0); /addvoidWINAPI ConvertShort(unsigned short *array, long length);voidWINAPI ConvertLong(unsigned long *array, long length);#endif /!_INC_DIBAPIdi
18、bapi.cpp:/ dibapi.cpp/ Source file for Device-Independent Bitmap (DIB) API. Provides/ the following functions:/ PaintDIB() - Painting routine for a DIB/ CreateDIBPalette() - Creates a palette from a DIB/ FindDIBBits() - Returns a pointer to the DIB bits/ DIBWidth() - Gets the width of the DIB/ DIBHe
19、ight() - Gets the height of the DIB/ PaletteSize() - Gets the size required to store the DIB's palette/ DIBNumColors() - Calculates the number of colors/ in the DIB's color table/ CopyHandle() - Makes a copy of the given global memory block/ This is a part of the Microsoft Foundation Classes
20、 C+ library./ Copyright (C) 1992-1997 Microsoft Corporation/ All rights reserved./ This source code is only intended as a supplement to the/ Microsoft Foundation Classes Reference and related/ electronic documentation provided with the library./ See these sources for detailed information regarding t
21、he/ Microsoft Foundation Classes product.#include "stdafx.h"#include "dibapi.h"#include <io.h>#include <errno.h>#include <math.h>#define DIB_HEADER_MARKER (WORD) ('M' << 8) | 'B')#ifdef _MAC#define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x)#
22、define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x), SWAPWORD(LOWORD(x)void ByteSwapHeader(BITMAPFILEHEADER* bmiHeader);void ByteSwapInfo(LPSTR lpHeader, BOOL fWin30Header);#endif/* * * PaintDIB() * * Parameters: * * HDC hDC - DC to do output to * * LPRECT lpDCRect - rectangle on DC to do output to * * H
23、DIB hDIB - handle to global memory with a DIB spec * in it followed by the DIB bits * * LPRECT lpDIBRect - rectangle of DIB to output into lpDCRect * * CPalette* pPal - pointer to CPalette containing DIB's palette * * Return Value: * * BOOL - TRUE if DIB was drawn, FALSE otherwise * * Descriptio
24、n: * Painting routine for a DIB. Calls StretchDIBits() or * SetDIBitsToDevice() to paint the DIB. The DIB is * output to the specified DC, at the coordinates given * in lpDCRect. The area of the DIB to be output is * given by lpDIBRect. * */BOOL WINAPI PaintDIB(HDC hDC,LPRECT lpDCRect,HDIB hDIB,LPRE
25、CT lpDIBRect,CPalette* pPal)LPSTR lpDIBHdr; / Pointer to BITMAPINFOHEADERLPSTR lpDIBBits; / Pointer to DIB bitsBOOL bSuccess=FALSE; / Success/fail flagHPALETTE hPal=NULL; / Our DIB's paletteHPALETTE hOldPal=NULL; / Previous palette/* Check for valid DIB handle */if (hDIB = NULL)return FALSE;/* L
26、ock down the DIB, and get a pointer to the beginning of the bit * buffer */lpDIBHdr = (LPSTR) :GlobalLock(HGLOBAL) hDIB);lpDIBBits = :FindDIBBits(lpDIBHdr);/ Get the DIB's palette, then select it into DCif (pPal != NULL)hPal = (HPALETTE) pPal->m_hObject;/ Select as background since we have/ a
27、lready realized in forground if neededhOldPal = :SelectPalette(hDC, hPal, TRUE);/* Make sure to use the stretching mode best for color pictures */:SetStretchBltMode(hDC, COLORONCOLOR);/* Determine whether to call StretchDIBits() or SetDIBitsToDevice() */if (RECTWIDTH(lpDCRect) = RECTWIDTH(lpDIBRect)
28、 && (RECTHEIGHT(lpDCRect) = RECTHEIGHT(lpDIBRect)bSuccess = :SetDIBitsToDevice(hDC, / hDC lpDCRect->left, / DestX lpDCRect->top, / DestY RECTWIDTH(lpDCRect), / nDestWidth RECTHEIGHT(lpDCRect), / nDestHeight lpDIBRect->left, / SrcX (int)DIBHeight(lpDIBHdr) - lpDIBRect->top - RECTH
29、EIGHT(lpDIBRect), / SrcY 0, / nStartScan (WORD)DIBHeight(lpDIBHdr), / nNumScans lpDIBBits, / lpBits (LPBITMAPINFO)lpDIBHdr, / lpBitsInfo DIB_RGB_COLORS); / wUsage else bSuccess = :StretchDIBits(hDC, / hDC lpDCRect->left, / DestX lpDCRect->top, / DestY RECTWIDTH(lpDCRect), / nDestWidth RECTHEIG
30、HT(lpDCRect), / nDestHeight lpDIBRect->left, / SrcX lpDIBRect->top, / SrcY RECTWIDTH(lpDIBRect), / wSrcWidth RECTHEIGHT(lpDIBRect), / wSrcHeight lpDIBBits, / lpBits (LPBITMAPINFO)lpDIBHdr, / lpBitsInfo DIB_RGB_COLORS, / wUsage SRCCOPY); / dwROP :GlobalUnlock(HGLOBAL) hDIB);/* Reselect old pale
31、tte */if (hOldPal != NULL):SelectPalette(hDC, hOldPal, TRUE); return bSuccess;/* * * CreateDIBPalette() * * Parameter: * * HDIB hDIB - specifies the DIB * * Return Value: * * HPALETTE - specifies the palette * * Description: * * This function creates a palette from a DIB by allocating memory for the
32、 * logical palette, reading and storing the colors from the DIB's color table * into the logical palette, creating a palette from this logical palette, * and then returning the palette's handle. This allows the DIB to be * displayed using the best possible colors (important for DIBs with 256
33、 or * more colors). * */BOOL WINAPI CreateDIBPalette(HDIB hDIB, CPalette* pPal)LPLOGPALETTE lpPal; / pointer to a logical paletteHANDLE hLogPal; / handle to a logical paletteHPALETTE hPal = NULL; / handle to a paletteint i; / loop indexWORD wNumColors; / number of colors in color tableLPSTR lpbi; /
34、pointer to packed-DIBLPBITMAPINFO lpbmi; / pointer to BITMAPINFO structure (Win3.0)LPBITMAPCOREINFO lpbmc; / pointer to BITMAPCOREINFO structure (old)BOOL bWinStyleDIB; / flag which signifies whether this is a Win3.0 DIBBOOL bResult = FALSE;/* if handle to DIB is invalid, return FALSE */if (hDIB = N
35、ULL) return FALSE; lpbi = (LPSTR) :GlobalLock(HGLOBAL) hDIB); /* get pointer to BITMAPINFO (Win 3.0) */ lpbmi = (LPBITMAPINFO)lpbi; /* get pointer to BITMAPCOREINFO (old 1.x) */ lpbmc = (LPBITMAPCOREINFO)lpbi; /* get the number of colors in the DIB */ wNumColors = :DIBNumColors(lpbi); if (wNumColors
36、 != 0) /* allocate memory block for logical palette */hLogPal = :GlobalAlloc(GHND, sizeof(LOGPALETTE)+ sizeof(PALETTEENTRY)* wNumColors);/* if not enough memory, clean up and return NULL */if (hLogPal = 0):GlobalUnlock(HGLOBAL) hDIB);return FALSE;lpPal = (LPLOGPALETTE) :GlobalLock(HGLOBAL) hLogPal);
37、/* set version and number of palette entries */lpPal->palVersion = PALVERSION;lpPal->palNumEntries = (WORD)wNumColors;/* is this a Win 3.0 DIB? */bWinStyleDIB = IS_WIN30_DIB(lpbi);for (i = 0; i < (int)wNumColors; i+)if (bWinStyleDIB)lpPal->palPalEntryi.peRed = lpbmi->bmiColorsi.rgbRed
38、;lpPal->palPalEntryi.peGreen = lpbmi->bmiColorsi.rgbGreen;lpPal->palPalEntryi.peBlue = lpbmi->bmiColorsi.rgbBlue;lpPal->palPalEntryi.peFlags = 0;elselpPal->palPalEntryi.peRed = lpbmc->bmciColorsi.rgbtRed;lpPal->palPalEntryi.peGreen = lpbmc->bmciColorsi.rgbtGreen;lpPal->
39、palPalEntryi.peBlue = lpbmc->bmciColorsi.rgbtBlue;lpPal->palPalEntryi.peFlags = 0;/* create the palette and get handle to it */bResult = pPal->CreatePalette(lpPal);:GlobalUnlock(HGLOBAL) hLogPal);:GlobalFree(HGLOBAL) hLogPal);:GlobalUnlock(HGLOBAL) hDIB);return bResult;/* * * FindDIBBits()
40、* * Parameter: * * LPSTR lpbi - pointer to packed-DIB memory block * * Return Value: * * LPSTR - pointer to the DIB bits * * Description: * * This function calculates the address of the DIB's bits and returns a * pointer to the DIB bits. * */LPSTR WINAPI FindDIBBits(LPSTR lpbi)return (lpbi + *(L
41、PDWORD)lpbi + :PaletteSize(lpbi);/* * * DIBWidth() * * Parameter: * * LPSTR lpbi - pointer to packed-DIB memory block * * Return Value: * * DWORD - width of the DIB * * Description: * * This function gets the width of the DIB from the BITMAPINFOHEADER * width field if it is a Windows 3.0-style DIB o
42、r from the BITMAPCOREHEADER * width field if it is an other-style DIB. * */DWORD WINAPI DIBWidth(LPSTR lpDIB)LPBITMAPINFOHEADER lpbmi; / pointer to a Win 3.0-style DIBLPBITMAPCOREHEADER lpbmc; / pointer to an other-style DIB/* point to the header (whether Win 3.0 and old) */lpbmi = (LPBITMAPINFOHEAD
43、ER)lpDIB;lpbmc = (LPBITMAPCOREHEADER)lpDIB;/* return the DIB width if it is a Win 3.0 DIB */if (IS_WIN30_DIB(lpDIB)return lpbmi->biWidth;else /* it is an other-style DIB, so return its width */return (DWORD)lpbmc->bcWidth;/* * * DIBHeight() * * Parameter: * * LPSTR lpbi - pointer to packed-DIB
44、 memory block * * Return Value: * * DWORD - height of the DIB * * Description: * * This function gets the height of the DIB from the BITMAPINFOHEADER * height field if it is a Windows 3.0-style DIB or from the BITMAPCOREHEADER * height field if it is an other-style DIB. * */DWORD WINAPI DIBHeight(LP
45、STR lpDIB)LPBITMAPINFOHEADER lpbmi; / pointer to a Win 3.0-style DIBLPBITMAPCOREHEADER lpbmc; / pointer to an other-style DIB/* point to the header (whether old or Win 3.0 */lpbmi = (LPBITMAPINFOHEADER)lpDIB;lpbmc = (LPBITMAPCOREHEADER)lpDIB;/* return the DIB height if it is a Win 3.0 DIB */if (IS_W
46、IN30_DIB(lpDIB)return lpbmi->biHeight;else /* it is an other-style DIB, so return its height */return (DWORD)lpbmc->bcHeight;/* * * PaletteSize() * * Parameter: * * LPSTR lpbi - pointer to packed-DIB memory block * * Return Value: * * WORD - size of the color palette of the DIB * * Description: * * This function gets the size required to store the DIB's palette by * multiplying the number of colors by the size of an RGBQUAD (for a * Windows 3.0-style DIB) or by the size
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 邢台医学高等专科学校《国民经济核算》2023-2024学年第二学期期末试卷
- 2025-2030年中国afc自动售票检票系统行业动态分析及应用前景预测研究报告
- 日间手术麻醉指南课件
- 甘肃省兰州市城关区天庆实验中学2023-2024学年中考数学考前最后一卷含解析
- 2024-2025新入职工职前安全培训考试试题带答案(基础题)
- 2025企业安全管理人员安全培训考试试题及参考答案【模拟题】
- 2025年公司及项目部安全培训考试试题(答案)
- 2024-2025企业安全管理人员安全培训考试试题(下载)
- 2025年公司、项目部、各个班组三级安全培训考试试题考点精练
- 2025员工安全培训考试试题答案能力提升
- 红色研学策划方案(2篇)
- 个人形象品牌代言协议
- 中职技能大赛“导游服务”赛项旅游政策与法规及旅游热点问题题库(含答案)
- 2018年西藏中考化学真题及答案
- 妊娠期糖尿病产后护理
- SJ-T 11841.2.2-2022 显示系统视觉舒适度 第2-2部分:平板显示-蓝光测量方法
- 代收代付协议书模板(2篇)
- 政务新闻摄影技巧培训课件
- 2024年放射工作人员放射防护培训考试题及答案
- 《第七天》读书分享交流会
- 老人疫苗接种健康知识讲座
评论
0/150
提交评论