?? geotrans.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;
// 圖像鏡像導出函數(shù)
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進行轉(zhuǎn)換
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;
}
//圖像轉(zhuǎn)置導出函數(shù)
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進行轉(zhuǎn)換
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;
}
//圖像縮放導出函數(shù)
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進行轉(zhuǎn)換
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;
}
//圖像旋轉(zhuǎn)導出函數(shù)
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進行轉(zhuǎn)換
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;
}
//圖像反色導出函數(shù)
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進行轉(zhuǎn)換
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;
}
//中值濾波導出函數(shù)
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進行轉(zhuǎn)換
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;
}
//梯度銳化導出函數(shù)
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進行轉(zhuǎn)換
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;
}
//圖像中加入隨機噪聲導出函數(shù)
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進行轉(zhuǎn)換
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;
}
//圖像中加入椒鹽噪聲導出函數(shù)
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進行轉(zhuǎn)換
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;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -