The number of bytes used in setting the bitmap bits; 0 if the function fails.
dwCount Specifies the number of bytes pointed to by lpBits.
lpBits Points to the BYTE array that contains the bit values to be copied to the CBitmap object.
//设置DDB所使用的像素数据----局部
//x, y, nWidth, nHeight
//lpBits----数据源, 扫描宽度字节数必须是2的倍数
DWORD CDdb::SetBitmapBits(int x, int y, int nWidth, int nHeight, int nBitCount, LPBYTE lpbyBits)
{
ASSERT(lpbyBits);
//类型不匹配, 则返回0, 表示没有设置任何数据
if(nBitCount != m_nBitCount)return 0;
//进行参数合法性检测
if((x > m_nWidth - 1) || (y > nHeight - 1))
{
AfxMessageBox("Cross the border!");
return 0;
}
//有效宽度和高度:w , h.
LONG w = (LONG)min(nWidth, m_nWidth - x);
LONG h = (LONG)min(nHeight, m_nHeight - y);
//绘制设备相关的位图.当然由于该类是以CBitmap对象进行加工的, 因而事先必须有一个该对象, 所以该方法的作用显得不是很突出.因为完全不用该方法也能绘制DDB位图.
BOOL CDdb::Draw(CDC* pDstDC, int x, int y, int nWidth, int nHeight, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop)
{
CDC memoryDC;
memoryDC.CreateCompatibleDC(pDstDC);
CBitmap* pOldBitmap = memoryDC.SelectObject(m_pDdb);
class CDdb : public CObject
{
DECLARE_DYNAMIC(CDdb)
public:
CDdb();
CDdb(CBitmap* pBitmap);
virtual ~CDdb();
BOOL Draw(CDC* pDstDC, int x, int y, int nWidth, int nHeight, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop);
DWORD SetBitmapBits( DWORD dwCount, const void* lpbyBits );
DWORD SetBitmapBits(int x, int y, int nWidth, int nHeight, int nBitCount, LPBYTE lpbyBits);
void GetDdbDataTo32(int x, int y, int nWidth, int nHeight, LPBYTE lpbyBits32);
void GetDdbDataTo24(int x, int y, int nWidth, int nHeight, LPBYTE lpbyBits24);
void SaveAs256(const char *pszDibFileName, int x, int y, int nWidth, int nHeight);
void QuantizeColor(LPBYTE pDdbBits24, int nScanWidth, int nScanHeight, LPBYTE pDdbBits8, CPalette* pPalette);
void Save(const char* pszDibFileName, int x, int y, int nWidth, int nHeight);
LONG CalcDdbWidthBytes(LONG nWidth, BYTE byBitCount);
LONG GetDdbWidthBytes() const;
LONG GetHeight() const;
LONG GetWidth() const;
BYTE GetBitCount() const ;
BYTE* GetDdbData() const;
void SetDdb(CBitmap* pBitmap);