⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geotrans.cpp

📁 VC++数字图像处理 配套光盘
💻 CPP
字号:
// GeoTrans.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "GeoTrans.h"
#include "DIBAPI.h"
#include "TransDIB.h"
#include "math.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//
//	Note!
//
//		If this DLL is dynamically linked against the MFC
//		DLLs, any functions exported from this DLL which
//		call into MFC must have the AFX_MANAGE_STATE macro
//		added at the very beginning of the function.
//
//		For example:
//
//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
//		{
//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
//			// normal function body here
//		}
//
//		It is very important that this macro appear in each
//		function, prior to any calls into MFC.  This means that
//		it must appear as the first statement within the 
//		function, even before any object variable declarations
//		as their constructors may generate calls into the MFC
//		DLL.
//
//		Please see MFC Technical Notes 33 and 58 for additional
//		details.
//

/////////////////////////////////////////////////////////////////////////////
// CGeoTransApp

BEGIN_MESSAGE_MAP(CGeoTransApp, CWinApp)
	//{{AFX_MSG_MAP(CGeoTransApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGeoTransApp construction

CGeoTransApp::CGeoTransApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CGeoTransApp object

CGeoTransApp theApp;

// 图像镜像导出函数
int _stdcall MirrorBmp(HDC hdcSrc,HBITMAP hbmpSrc,HDC hdcDest,BOOL bDirection)
{	
	//得到图象大小信息
	int cx,cy;

	//读取DIB信息
	LPBYTE lpDIB=DIBfromBitmap(hdcSrc,hbmpSrc);
	if(lpDIB==NULL)
		return -1;	
    LPBYTE lpDIBits =(LPBYTE)lpDIB+sizeof(BITMAPINFOHEADER) + ::PaletteSize((LPSTR)lpDIB);

	BITMAPINFOHEADER * lpBmpih=(BITMAPINFOHEADER *)lpDIB; 
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;

	//对DIB进行转换
	if(!MirrorDIB((LPSTR)lpDIBits, cx, cy, bDirection))
		return -2;
/**/

	//将变化后的信息放到目的句柄

	if(SetDIBitsToDevice(hdcDest,0,0,cx,cy,0,0,0,cy,lpDIBits,(BITMAPINFO*)lpDIB,DIB_RGB_COLORS)==0)
		return -3;
	

	return 1;

}

//图像转置导出函数
int _stdcall TransposeBmp(HDC hdcSrc,HBITMAP hbmpSrc,HDC hdcDest)
{
	//得到图象大小信息
	int cx,cy;

	//读取DIB信息

	LPBYTE lpDIB=DIBfromBitmap(hdcSrc,hbmpSrc);
	if(lpDIB==NULL)
		return 0;	
	LPBYTE lpDIBits =(LPBYTE)lpDIB+sizeof(BITMAPINFOHEADER) + ::PaletteSize((LPSTR)lpDIB);
	
	BITMAPINFOHEADER * lpBmpih=(BITMAPINFOHEADER *)lpDIB; 
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;
	

	//对DIB进行转换
	TransposeDIB((LPSTR)lpDIB);

	//将变化后的信息放到目的句柄
	lpBmpih=(BITMAPINFOHEADER *)lpDIB;
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;
	if(SetDIBitsToDevice(hdcDest,0,0,cx,cy,0,0,0,cy,lpDIBits,(BITMAPINFO*)lpDIB,DIB_RGB_COLORS)==0)
		return -1;
	return 1;

}

//图像缩放导出函数  
int _stdcall RotateBmp(HDC hdcSrc,HBITMAP hbmpSrc,HDC hdcDest, int iRotateAngle)
{
	//得到图象大小信息
	int cx,cy;

	//读取DIB信息

	LPBYTE lpDIB=DIBfromBitmap(hdcSrc,hbmpSrc);
	if(lpDIB==NULL)
		return 0;	
	
	BITMAPINFOHEADER * lpBmpih=(BITMAPINFOHEADER *)lpDIB; 
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;
	

	//对DIB进行转换
	LPBYTE lpNewDIB=RotateDIB((LPSTR)lpDIB,iRotateAngle);

	LPBYTE lpDIBits =(LPBYTE)::FindDIBBits((LPSTR)lpNewDIB);

	//将变化后的信息放到目的句柄
	lpBmpih=(BITMAPINFOHEADER *)lpNewDIB;
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;

	GlobalFree(lpDIB);
	if(SetDIBitsToDevice(hdcDest,0,0,cx,cy,0,0,0,cy,lpDIBits,(BITMAPINFO*)lpNewDIB,DIB_RGB_COLORS)==0)
		return -1;
	return 1;

}

//图像旋转导出函数
int _stdcall ZoomBmp(HDC hdcSrc,HBITMAP hbmpSrc,HDC hdcDest, double fXZoomRatio, double fYZoomRatio)
{
	//得到图象大小信息
	int cx,cy;

	//读取DIB信息

	LPBYTE lpDIB=DIBfromBitmap(hdcSrc,hbmpSrc);
	if(lpDIB==NULL)
		return 0;	
	
	BITMAPINFOHEADER * lpBmpih=(BITMAPINFOHEADER *)lpDIB; 
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;
	

	//对DIB进行转换
	LPBYTE lpNewDIB=ZoomDIB((LPSTR)lpDIB,(float)fXZoomRatio,(float)fYZoomRatio);

	LPBYTE lpDIBits =(LPBYTE)::FindDIBBits((LPSTR)lpNewDIB);

	//将变化后的信息放到目的句柄
	lpBmpih=(BITMAPINFOHEADER *)lpNewDIB;
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;

	GlobalFree(lpDIB);
	if(SetDIBitsToDevice(hdcDest,0,0,cx,cy,0,0,0,cy,lpDIBits,(BITMAPINFO*)lpNewDIB,DIB_RGB_COLORS)==0)
		return 0;
	return 1;

}

//图像反色导出函数
int _stdcall LinerTransBmp(HDC hdcSrc,HBITMAP hbmpSrc,HDC hdcDest)
{	
	//得到图象大小信息
	int cx,cy;

	//读取DIB信息

	LPBYTE lpDIB=DIBfromBitmap(hdcSrc,hbmpSrc);
	if(lpDIB==NULL)
		return -1;	
	LPBYTE lpDIBits =(LPBYTE)lpDIB+sizeof(BITMAPINFOHEADER) + ::PaletteSize((LPSTR)lpDIB);
	
	BITMAPINFOHEADER * lpBmpih=(BITMAPINFOHEADER *)lpDIB; 
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;

	//对DIB进行转换
	if(!LinerTrans((LPSTR)lpDIBits,cx,cy,-1.0,255.0))
		return -2;


	//将变化后的信息放到目的句柄

	if(SetDIBitsToDevice(hdcDest,0,0,cx,cy,0,0,0,cy,lpDIBits,(BITMAPINFO*)lpDIB,DIB_RGB_COLORS)==0)
		return -3;
	
//	GlobalFree(lpDIB);
	return 1;

}

//中值滤波导出函数
int _stdcall MedianFilterBmp(HDC hdcSrc,HBITMAP hbmpSrc,HDC hdcDest, int iFilterH, int iFilterW, int iFilterMX, int iFilterMY)
{	
	//得到图象大小信息
	int cx,cy;

	//读取DIB信息

	LPBYTE lpDIB=DIBfromBitmap(hdcSrc,hbmpSrc);
	if(lpDIB==NULL)
		return -1;	
	LPBYTE lpDIBits =(LPBYTE)lpDIB+sizeof(BITMAPINFOHEADER) + ::PaletteSize((LPSTR)lpDIB);
	
	BITMAPINFOHEADER * lpBmpih=(BITMAPINFOHEADER *)lpDIB; 
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;

	//对DIB进行转换
	if(!MedianFilter((LPSTR)lpDIBits,cx,cy, iFilterH, iFilterW,iFilterMX,iFilterMY))
		return -2;


	//将变化后的信息放到目的句柄

	if(SetDIBitsToDevice(hdcDest,0,0,cx,cy,0,0,0,cy,lpDIBits,(BITMAPINFO*)lpDIB,DIB_RGB_COLORS)==0)
		return -3;
	
//	GlobalFree(lpDIB);
	return 1;

}

//梯度锐化导出函数
int _stdcall GradSharpBmp(HDC hdcSrc,HBITMAP hbmpSrc,HDC hdcDest,BYTE bThre)
{	
	//得到图象大小信息
	int cx,cy;

	//读取DIB信息

	LPBYTE lpDIB=DIBfromBitmap(hdcSrc,hbmpSrc);
	if(lpDIB==NULL)
		return -1;	
	LPBYTE lpDIBits =(LPBYTE)lpDIB+sizeof(BITMAPINFOHEADER) + ::PaletteSize((LPSTR)lpDIB);
	
	BITMAPINFOHEADER * lpBmpih=(BITMAPINFOHEADER *)lpDIB; 
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;

	//对DIB进行转换
	if(!GradSharp((LPSTR)lpDIBits,cx,cy,bThre))
		return -2;


	//将变化后的信息放到目的句柄

	if(SetDIBitsToDevice(hdcDest,0,0,cx,cy,0,0,0,cy,lpDIBits,(BITMAPINFO*)lpDIB,DIB_RGB_COLORS)==0)
		return -3;
	
//	GlobalFree(lpDIB);
	return 1;

}

//图像中加入随机噪声导出函数
int _stdcall RandomNoiseBmp(HDC hdcSrc,HBITMAP hbmpSrc,HDC hdcDest)
{	
	//得到图象大小信息
	int cx,cy;

	//读取DIB信息

	LPBYTE lpDIB=DIBfromBitmap(hdcSrc,hbmpSrc);
	if(lpDIB==NULL)
		return -1;	
	LPBYTE lpDIBits =(LPBYTE)lpDIB+sizeof(BITMAPINFOHEADER) + ::PaletteSize((LPSTR)lpDIB);
	
	BITMAPINFOHEADER * lpBmpih=(BITMAPINFOHEADER *)lpDIB; 
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;

	//对DIB进行转换
	if(!RandomNoiseDIB((LPSTR)lpDIBits,cx,cy))
		return -2;


	//将变化后的信息放到目的句柄

	if(SetDIBitsToDevice(hdcDest,0,0,cx,cy,0,0,0,cy,lpDIBits,(BITMAPINFO*)lpDIB,DIB_RGB_COLORS)==0)
		return -3;
	
//	GlobalFree(lpDIB);
	return 1;

}


//图像中加入椒盐噪声导出函数
int _stdcall SaltNoiseBmp(HDC hdcSrc,HBITMAP hbmpSrc,HDC hdcDest)
{	
	//得到图象大小信息
	int cx,cy;

	//读取DIB信息

	LPBYTE lpDIB=DIBfromBitmap(hdcSrc,hbmpSrc);
	if(lpDIB==NULL)
		return -1;	
	LPBYTE lpDIBits =(LPBYTE)lpDIB+sizeof(BITMAPINFOHEADER) + ::PaletteSize((LPSTR)lpDIB);
	
	BITMAPINFOHEADER * lpBmpih=(BITMAPINFOHEADER *)lpDIB; 
	cx=lpBmpih->biWidth;
	cy=lpBmpih->biHeight;

	//对DIB进行转换
	if(!SaltNoiseDIB((LPSTR)lpDIBits,cx,cy))
		return -2;


	//将变化后的信息放到目的句柄

	if(SetDIBitsToDevice(hdcDest,0,0,cx,cy,0,0,0,cy,lpDIBits,(BITMAPINFO*)lpDIB,DIB_RGB_COLORS)==0)
		return -3;
	
	return 1;

}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -