📄 dibdc.h
字号:
//////////////////////////////////////////////////////////////////////
#if !defined THERE_IS_A_DIBDC_H_FILE
#define THERE_IS_A_DIBDC_H_FILE
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
class CDIBDC : public CDC
{
DECLARE_DYNAMIC(CDIBDC)
public:
CDIBDC();
virtual ~CDIBDC();
protected:
//DIB attribute
HBITMAP m_hDIBitmap;
BITMAPINFO m_BitmapInfo; //Bitmap information(about DIB)
BYTE** m_Index; //Bitmap data index
BYTE* m_pData; //Bitmap data
#ifdef THERE_IS_A_ENCRYPTION_H_FILE
CEncryption m_Encryption;
#endif
protected:
//Reset DIB use parameter have been ready
BOOL ResetDIB();
//Set data index
BYTE** LockIndex();
//Delete data index
void UnlockIndex();
private:
VOID ResetParams();
public:
BOOL IsValid();
BOOL Load();
BOOL Load(LPCTSTR lpszPathName);
BOOL Load(BYTE *pData, int FileLength);
VOID DestroyDIB();
DWORD DIBHeaderSize();
VOID SaveToDIBHeader(PVOID pDIB);
HBITMAP GetBitmapHandle();
/////////////////////////////////////////////////////
//Initialize or resize DIB//
//用于创建DIBDC.
//Create a DIB with new size, new bits(at the same time, delete old DIB)
BOOL CreateDIB(LONG width, LONG height, WORD bits);
//Create a DIB with a new size, colortable is retained, data is deleted
BOOL ResizeDIB(LONG width,LONG height);
//Set the DIB with the same color
VOID SetFillColor(COLORREF color);
//////////////////////////////////////////////////////
//CDIBDC <--> array//
//用于图像数据的直接存取.
//Get data
BYTE* GetData();
//Set data
VOID SetData(CONST VOID *pData);
//Get data index
BYTE** GetIndex();
//Get a pixel at (x,y), example: GetAt(x,y,(WORD*)pColor);
VOID GetAt(INT x, INT y, ...);
//Set a pixel at (x,y), example: SetAt(x,y,(WORD)Color);
VOID SetAt(INT x, INT y, ...);
///////////////////////////////////////////
//CDIBDC <--> CDIBDC//
//用于DIBDC间的赋值, 复制, 有的函数功能一致, 只有描述的不同.
//Overload the construct function, Create a copy of DIBDC
CDIBDC(CDIBDC& DIBDC);
//Overload the operator '=', left DC is a copy of right DC
CDIBDC& operator=(CDIBDC& DIBDC);
//Create a new DIB which is the same as DIB of DIBDC,
//same data, and same colortable
BOOL CreateDIB(CDIBDC& DIBDC);
//Create a new DIB, use the content in rect(x,y,width,height) in DIB in DIBDC
BOOL CreateDIB(CDIBDC& DIBDC, INT x, INT y, INT width, INT height);
//Add DIB in DIBDC to this CDIBDC, origin points at (x,y),
//IsSuitable is a flag to change or nochange the size of this CDIBDC
BOOL AddDIB(CDIBDC& DIBDC, INT x=0, INT y=0, BOOL IsSuitable=TRUE);
//////////////////////////////////////////
//CDIBDC <--> Clipboard//
//用于剪贴板操作
//Test the data in clipboard if it is CF_DIB
BOOL ClipboardAvailable();
//Paste DIB from clipboard
BOOL ClipboardPaste();
//Copy DIB to clipboard
BOOL ClipboardCopy();
////////////////////////////////////////////
//CDIBDC <--> Memory //
//用于剪贴板操作中的内存转移或自定义的进程间共享数据.
//pDIB指向的内存数据格式符合CF_DIB(剪贴板中和设备无关的位图)格式.
BOOL LoadFromMem(PVOID pDIB);
VOID SaveToMem(PVOID pDIB);
//得到符合CF_DIB格式的内存区大小.
DWORD DIBSize();
////////////////////////////////////////////
//CDIBDC <--> file//
//用于DIBDC和文件交换数据.
//Open image from indicated file.
BOOL OpenImage(LPCTSTR lpszPathName);
//Save image from indicated file.
BOOL SaveImage(LPCTSTR lpszPathName);
//Set cryptic version of the image file.
//Save Bitmap to a file
VOID SaveBitmap(CFile* pFile); //*.bmp
VOID SaveCrypticBmp(CFile* pFile); //*.bmc
//Get Bitmap from a file
BOOL GetBitmap(CFile* pFile);
BOOL GetCrypticBmp(CFile* pFile);
//Get free image from a file.
//NOTE: format of free image
// word width
// word height
// byte ppData[height][width]
BOOL GetFreeImage(CFile* pFile); //*.fri
BOOL GetCrypticFri(CFile* pFile); //*.fic
//Save free image to a file
VOID SaveFreeImage(CFile* pFile, BOOL IsGray=TRUE);
VOID SaveCrypticFri(CFile* pFile, BOOL IsGray=TRUE);
//Save to file, support all type in list.
VOID SaveToFile(CFile *pFile);
//Open from file
BOOL GetFromFile(CFile* pFile);
////////////////////////////////////////////////
//CDIBDC <--> other CDC//
//Create compatible device context with pDC
virtual BOOL CreateCompatibleDC(CDC* pDC);
//Paste to pDC, like StrechDIBits(...)
VOID Paste(CDC* pDC,
INT XDest, INT YDest,
INT nDestWidth, INT nDestHeight,
INT XSrc, INT YSrc,
INT nSrcWidth, INT nSrcHeight,
DWORD dwRop=SRCCOPY);
VOID Paste(CDC* pDC,
INT XDest, INT YDest,
INT nWidth, INT nHeight,
INT XSrc, INT YSrc,
DWORD dwRop=SRCCOPY);
VOID Paste(CDC* pDC,
INT XDest, INT YDest,
INT nDestWidth, INT nDestHeight,
DWORD dwRop=SRCCOPY);
VOID Paste(CDC* pDC,
INT XDest, INT YDest,
DWORD dwRop=SRCCOPY);
////////////////////////////////////////////////
//SetColorTable//
VOID SetDefaultColors(BOOL IsGray=TRUE);
VOID SetColors(INT index, BYTE r, BYTE g, BYTE b);
VOID SetColorTable(RGBQUAD* pColors);
BOOL GetColorTable(RGBQUAD* pColors);
//////////////////////////////////////////////////////
//Attributes//
LONG RowBytes();
DWORD ColorTableSize();
DWORD ImageSize();
WORD& Bits();
LONG& Height();
LONG& Width();
};
#endif // !defined(THERE_IS_A_DIBDC_H_FILE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -