?? bmpproc.h
字號(hào):
///////////////////////////////////////////////////////////////////////
/*
目的:BMP位圖處理類。(定義文件)
創(chuàng)建:張偉(SXZ)
日期:2000.01
版本:2.4
SXZ software workgroup. No.200001
*/
///////////////////////////////////////////////////////////////////////
#ifndef __BMPPROC_H__
#define __BMPPROC_H__
/* 版本 */
#define BMPPROC_VERSION 0x240
// DIBSCANLINE_WIDTHBYTES 執(zhí)行DIB掃描行的DWORD對(duì)齊操作。宏參數(shù)“bits”是
// DIB信息結(jié)構(gòu)中成員biWidth和biBitCount的乘積。宏的結(jié)果是經(jīng)過(guò)對(duì)齊后一個(gè)
// 掃描行所占的字節(jié)數(shù)。
#define DIBSCANLINE_WIDTHBYTES(bits) (((bits)+31)/32*4)
// DDBSCANLINE_WIDTHBYTES 執(zhí)行DDB掃描行的WORD對(duì)齊操作。宏參數(shù)“bits”是
// DDB信息結(jié)構(gòu)中成員bmWidth和bmBitCount的乘積。宏的結(jié)果是經(jīng)過(guò)對(duì)齊后一個(gè)
// 掃描行所占的字節(jié)數(shù)。
#define DDBSCANLINE_WIDTHBYTES(bits) (((bits)+15)/16*2)
/* DIB 文件頭標(biāo)志("BM") */
#define DIB_HEADER_MARKER ((WORD)('M'<<8)|'B')
// 常用顏色定義
#define CBPCOLOR_BLACK ((COLORREF)RGB(0,0,0))
#define CBPCOLOR_GRAY ((COLORREF)RGB(128,128,128))
#define CBPCOLOR_HIGHGRAY ((COLORREF)RGB(192,192,192))
#define CBPCOLOR_WHITE ((COLORREF)RGB(255,255,255))
#define CBPCOLOR_RED ((COLORREF)RGB(255,0,0))
#define CBPCOLOR_GREEN ((COLORREF)RGB(0,255,0))
#define CBPCOLOR_BLUE ((COLORREF)RGB(0,0,255))
// 注意:類CBmpProc是從CBitmap類公有繼承而來(lái)的,但最好不要使用類CBitmap
// 中的函數(shù)!如果使用了(尤其是讀入或創(chuàng)建型的函數(shù)),則就不要再使用CBmpProc
// 類中的函數(shù),以免混亂。
class CBmpProc : public CBitmap
{
public:
CBmpProc();
~CBmpProc();
BOOL Create(int width, int height, WORD nBitCount, const void *lpBits=NULL);
BOOL Create(CSize size, WORD nBitCount, const void *lpBits=NULL);
BOOL CreateCompatible(int width, int height, CDC *pDC=NULL, const void *lpBits=NULL);
BOOL CopyFromObject(CBmpProc& souBmp, CRect *pDesRect=NULL, CRect *pSouRect=NULL);
BOOL CopyFromHbmp(HBITMAP souBmp, CRect *pDesRect=NULL, CRect *pSouRect=NULL);
BOOL CopyTran(CBmpProc& souBmp, COLORREF crColour=CBPCOLOR_WHITE,
CRect *pDesRect=NULL, CRect *pSouRect=NULL, int mode=0);
BOOL CopyTran(CBmpProc& souBmp, COLORREF crColour=CBPCOLOR_WHITE,
int x=0, int y=0, CRect *pSouRect=NULL, int mode=0);
BOOL CopyTranCenter(CBmpProc& souBmp, CRect* crArea=NULL,
COLORREF crColour=CBPCOLOR_WHITE, int mode=0);
BOOL CopyTranTile(CBmpProc& souBmp, CRect* crArea=NULL,
COLORREF crColour=CBPCOLOR_WHITE, int mode=0);
BOOL LoadFromFile(LPCTSTR lpszPathName);
BOOL LoadFromResourceID(UINT uID, HINSTANCE hInst);
BOOL LoadFromResourceName(LPCTSTR lpResourceName, HINSTANCE hInst);
BOOL LoadFromObject(CBmpProc& souBmp, CRect *pSouRect=NULL);
BOOL LoadFromHbmp(HBITMAP sou, CRect *pSouRect=NULL);
BOOL LoadFromClipboard();
BOOL Save(LPCTSTR lpszNewFileName=NULL, WORD nBitsPerPixel=0);
BOOL SaveToClipboard();
BOOL Draw(CDC& dc, const CRect* rcDst=NULL, const CRect* rcSrc=NULL);
BOOL DrawTile(CDC& dc, CRect* crArea);
BOOL DrawCenter(CDC& dc, CRect* crArea);
BOOL DrawTransparentInRect(CDC& dc, COLORREF crColour=CBPCOLOR_WHITE,
CRect* crDest=NULL, CRect* crSou=NULL, int mode=0);
BOOL DrawTransparentInPoint(CDC& dc, COLORREF crColour=CBPCOLOR_WHITE,
int x=0, int y=0, CRect* crSou=NULL, int mode=0);
BOOL DrawTranCenter(CDC& dc, CRect* crArea, COLORREF crColour=CBPCOLOR_WHITE, int mode=0);
BOOL DrawTranTile(CDC& dc, CRect* crArea, COLORREF crColour=CBPCOLOR_WHITE, int mode=0);
BOOL Attach(HBITMAP hBmp);
HBITMAP Detach();
void Clear();
HRGN ExportRegion(COLORREF cTranColor=CBPCOLOR_WHITE);
BOOL Fill(COLORREF crColour=CBPCOLOR_WHITE, CRect *crArea=NULL);
BOOL ReSetColor(COLORREF oldcolr, COLORREF newcolr, CRect *crArea=NULL);
// 重載操作符函數(shù)
CBmpProc& operator=(const CBmpProc& ds);
CBmpProc& operator=(const HBITMAP sou);
BOOL operator==(const CBmpProc& ds);
BOOL operator!=(const CBmpProc& ds);
operator HBITMAP() const { return (HBITMAP)m_hObject; };
// 類數(shù)據(jù)訪問函數(shù)
CSize Size() const;
CRect Rect() const;
int Width() const;
int Height() const;
int ScanWidth() const;
int BitsPerPixel() const;
BOOL IsValid() const;
//訪問類內(nèi)部數(shù)據(jù)的介面函數(shù)
int GetImageType() const;
DWORD GetInAddInfo() const;
const CString& GetFileName() const;
BOOL SetFileName(LPSTR pSou);
int GetObject(LPBITMAP lpBitmap) const;
HANDLE GetHDib() const;
WORD GetVersion() const;
#ifdef _DEBUG
static DWORD GetObjectCount() {return m_ObjectCount;};
#endif
protected:
// 助手函數(shù)(與類無(wú)關(guān))
LPSTR FindDIBBits(LPSTR lpbi) const;
DWORD DIBWidth(LPBITMAPINFOHEADER lpbi) const;
DWORD DIBHeight(LPBITMAPINFOHEADER lpbi) const;
WORD PaletteSize(LPBITMAPINFOHEADER lpbi) const;
WORD DIBNumColors(LPBITMAPINFOHEADER lpbi) const;
int GetBitsPerPixel(LPBITMAPINFOHEADER lpbi) const;
LPVOID CreateMemoryBlockFromHandle(HANDLE handle, DWORD dwCount=0);
LPVOID CreateMemoryBlockFromAddress(LPVOID pSou, DWORD dwCount=0);
BOOL IsValidBmpFile(CFile& file);
LPBITMAPINFO GetBmpFileInfo(CFile& file);
LPSTR GetBmpFileBits(CFile& file);
BOOL IsValidDibFormat(WORD nBitsPerPixel);
BOOL IsFileExist(LPCTSTR lpFileName);
DWORD CalculateDIBFileSize(LPBITMAPINFOHEADER lpbi) const;
DWORD CalculateDIBSize(LPBITMAPINFOHEADER lpbi) const;
DWORD CalculateDIBitsOff(LPBITMAPINFOHEADER lpbi) const;
DWORD CalculateDIBInfoSize(LPBITMAPINFOHEADER lpbi) const;
DWORD CalculateDIBitsSize(LPBITMAPINFOHEADER lpbi) const;
BOOL PasteAvailable();
// 內(nèi)部服務(wù)函數(shù)(與類有關(guān))
BOOL SaveBaseSpecifyFileName(LPCTSTR fn);
BOOL SaveBaseSpecifyFormat(WORD nBitsPerPixel);
LPBITMAPINFO GetSpecifyFormatInfo(WORD newBitCount=0);
BOOL ClearAndSetData(int type, DWORD addinfo, LPCTSTR lpFn, LPBITMAPINFO pInfo, HBITMAP hBmp);
public:
void RotatedBitmap(RateDirection radians, COLORREF clrBack);
void RotatedBitmap(RateDirection radians);
enum // 位圖的初始來(lái)源類型:
{
IT_NULL, // 無(wú)位圖類型
IT_DISKFILE, // 文件位圖
IT_RESOURCE, // 資源位圖
IT_MEMORY, // 內(nèi)存位圖
IT_CLIP, // 剪貼板位圖
IT_CREATE // 創(chuàng)建型位圖
};
private:
// 數(shù)據(jù)成員
BOOL m_mark; // 類的有效標(biāo)志。(TRUE-本類中有位圖,
// FALSE-本類中沒有位圖)
int m_type; // 圖像類型,只能使用上面枚舉類型值
DWORD m_addInfo; // 附加信息。
CString m_cFileName;// 文件路徑。
LPBITMAPINFO m_pInfo; // DIB 信息結(jié)構(gòu)
#ifdef _DEBUG
static DWORD m_ObjectCount; // 本類構(gòu)造的實(shí)例目標(biāo)個(gè)數(shù),供調(diào)試使用
#endif
};
#endif /*__BMPPROC_H__*/
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -