................
前面已得到BITMAP数据,且变量声明省略
BITMAP curBmp;
int nBytesPerPixel = curBmp.bmWidthBytes/curBmp.bmWidth;
int nSize = curBmp.bmHeight*curBmp.bmWidthBytes;
hImgData = GlobalAlloc(GHND, (DWORD)nSize);if (hImgData == NULL)
{
return FALSE;
}lpImgData = (LPBYTE)GlobalLock(hImgData);pOldBitmap->GetBitmapBits(nSize,lpImgData);int byteRed = GetRValue(refColor);
int byteGreen = GetGValue(refColor);
int byteBlue = GetBValue(refColor);int off = 0;
int maskoff = 0;
BYTE byteMask, nBitCount, nAddByte;
BYTE nBitMask[8] = {0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};if(curBmp.bmWidth % 64 == 0)
{
m_nWidth = curBmp.bmWidth;
nAddByte = 0;
}
else
{
m_nWidth = (curBmp.bmWidth/64+1)*64;
nAddByte = (m_nWidth-curBmp.bmWidth)/8;
}m_nHeight = curBmp.bmHeight;for(int m = 0; m < m_nHeight; m++)
{
nBitCount = 0;
byteMask = 0;
for(int n = 0; n < curBmp.bmWidth; n++, off += nBytesPerPixel)
{
if(curBmp.bmBitsPixel >= 24)
{
if (lpImgData[off] == byteRed
&& lpImgData[off+1] == byteGreen
&& lpImgData[off+2] == byteBlue)
{
byteMask = byteMask | nBitMask[nBitCount];
nBitCount++;
}
else
{
nBitCount++;
}
}
if(nBitCount >= 8)
{
lpImgData[maskoff] = byteMask;
nBitCount = 0;
byteMask = 0;
maskoff++;
}
}
if (nBitCount != 0)
{
lpImgData[maskoff] = byteMask;
nBitCount = 0;
byteMask = 0;
maskoff++;
}
for(int l = 0; l < nAddByte; l++)
{
lpImgData[maskoff] = 0;
maskoff++;
}
} 我觉得是给图形做掩码,但它的循环机制把我搞糊涂了,
比如:if(nBitCount >= 8)
{
lpImgData[maskoff] = byteMask;
nBitCount = 0;
byteMask = 0;
maskoff++;
}
为什么是横向走完8个象素却设置了1个象素掩码呢?
前面已得到BITMAP数据,且变量声明省略
BITMAP curBmp;
int nBytesPerPixel = curBmp.bmWidthBytes/curBmp.bmWidth;
int nSize = curBmp.bmHeight*curBmp.bmWidthBytes;
hImgData = GlobalAlloc(GHND, (DWORD)nSize);if (hImgData == NULL)
{
return FALSE;
}lpImgData = (LPBYTE)GlobalLock(hImgData);pOldBitmap->GetBitmapBits(nSize,lpImgData);int byteRed = GetRValue(refColor);
int byteGreen = GetGValue(refColor);
int byteBlue = GetBValue(refColor);int off = 0;
int maskoff = 0;
BYTE byteMask, nBitCount, nAddByte;
BYTE nBitMask[8] = {0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};if(curBmp.bmWidth % 64 == 0)
{
m_nWidth = curBmp.bmWidth;
nAddByte = 0;
}
else
{
m_nWidth = (curBmp.bmWidth/64+1)*64;
nAddByte = (m_nWidth-curBmp.bmWidth)/8;
}m_nHeight = curBmp.bmHeight;for(int m = 0; m < m_nHeight; m++)
{
nBitCount = 0;
byteMask = 0;
for(int n = 0; n < curBmp.bmWidth; n++, off += nBytesPerPixel)
{
if(curBmp.bmBitsPixel >= 24)
{
if (lpImgData[off] == byteRed
&& lpImgData[off+1] == byteGreen
&& lpImgData[off+2] == byteBlue)
{
byteMask = byteMask | nBitMask[nBitCount];
nBitCount++;
}
else
{
nBitCount++;
}
}
if(nBitCount >= 8)
{
lpImgData[maskoff] = byteMask;
nBitCount = 0;
byteMask = 0;
maskoff++;
}
}
if (nBitCount != 0)
{
lpImgData[maskoff] = byteMask;
nBitCount = 0;
byteMask = 0;
maskoff++;
}
for(int l = 0; l < nAddByte; l++)
{
lpImgData[maskoff] = 0;
maskoff++;
}
} 我觉得是给图形做掩码,但它的循环机制把我搞糊涂了,
比如:if(nBitCount >= 8)
{
lpImgData[maskoff] = byteMask;
nBitCount = 0;
byteMask = 0;
maskoff++;
}
为什么是横向走完8个象素却设置了1个象素掩码呢?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货