📄 win32bitmap.cpp
字号:
oDestRect.Width(), oDestRect.Height(),
hSrcDC, oSrcRect.x1, oSrcRect.y1, SRCCOPY);
DeleteDC(hSrcDC);
DeleteDC(hDestDC);
return kError_NoErr;
}
Error Win32Bitmap::MaskBlitRect(Bitmap *pOther, Rect &oSrcRect,
Rect &oDestRect)
{
HDC hRootDC, hSrcDC, hDestDC, hMaskDC;
Win32Bitmap *pSrcBitmap = (Win32Bitmap *)pOther;
if (!pSrcBitmap->m_hMaskBitmap)
return BlitRect(pOther, oSrcRect, oDestRect);
if (pSrcBitmap->m_hBitmap == NULL)
return kError_UnknownErr;
hRootDC = GetDC(NULL);
hSrcDC = CreateCompatibleDC(hRootDC);
hDestDC = CreateCompatibleDC(hRootDC);
hMaskDC = CreateCompatibleDC(hRootDC);
ReleaseDC(NULL, hRootDC);
SelectObject(hSrcDC, pSrcBitmap->m_hBitmap);
SelectObject(hMaskDC, pSrcBitmap->m_hMaskBitmap);
SelectObject(hDestDC, m_hBitmap);
SetBkColor(hSrcDC, RGB(m_oTransColor.red,m_oTransColor.green,m_oTransColor.blue));
BitBlt(hDestDC, oDestRect.x1, oDestRect.y1,
oDestRect.Width(), oDestRect.Height(),
hSrcDC, oSrcRect.x1, oSrcRect.y1, SRCINVERT);
BitBlt(hDestDC, oDestRect.x1, oDestRect.y1,
oDestRect.Width(), oDestRect.Height(),
hMaskDC, oSrcRect.x1, oSrcRect.y1, SRCAND);
BitBlt(hDestDC, oDestRect.x1, oDestRect.y1,
oDestRect.Width(), oDestRect.Height(),
hSrcDC, oSrcRect.x1, oSrcRect.y1, SRCINVERT);
DeleteDC(hSrcDC);
DeleteDC(hDestDC);
DeleteDC(hMaskDC);
return kError_NoErr;
}
Error Win32Bitmap::BlitRectMaskBitmap(Bitmap *pOther, Rect &oSrcRect,
Rect &oDestRect)
{
HDC hRootDC, hSrcDC, hDestDC;
Win32Bitmap *pSrcBitmap = (Win32Bitmap *)pOther;
if (pSrcBitmap->m_hMaskBitmap == NULL)
return kError_UnknownErr;
hRootDC = GetDC(NULL);
hSrcDC = CreateCompatibleDC(hRootDC);
hDestDC = CreateCompatibleDC(hRootDC);
ReleaseDC(NULL, hRootDC);
DeleteObject(SelectObject(hSrcDC, pSrcBitmap->m_hMaskBitmap));
DeleteObject(SelectObject(hDestDC, m_hMaskBitmap));
BitBlt(hDestDC, oDestRect.x1, oDestRect.y1,
oDestRect.Width(), oDestRect.Height(),
hSrcDC, oSrcRect.x1, oSrcRect.y1, SRCCOPY);
DeleteDC(hSrcDC);
DeleteDC(hDestDC);
return kError_NoErr;
}
void Win32Bitmap::UpdateHistogram(WORD *pHist)
{
BITMAP sInfo;
BITMAPINFO *pInfo;
HDC hRootDC, hMemDC;
int iRet, iLine, iCol;
char *pData;
Color sTrans, *pColorPtr;
hRootDC = GetDC(NULL);
hMemDC = CreateCompatibleDC(hRootDC);
ReleaseDC(NULL, hRootDC);
GetObject(m_hBitmap, sizeof(BITMAP), (LPSTR)&sInfo);
pInfo = (BITMAPINFO *)new char[sizeof(BITMAPINFOHEADER)];
pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pInfo->bmiHeader.biWidth = sInfo.bmWidth;
pInfo->bmiHeader.biHeight = sInfo.bmHeight;
pInfo->bmiHeader.biPlanes = 1;
pInfo->bmiHeader.biBitCount = 24;
pInfo->bmiHeader.biCompression = BI_RGB;
pInfo->bmiHeader.biSizeImage = 0;
pInfo->bmiHeader.biXPelsPerMeter = 0;
pInfo->bmiHeader.biYPelsPerMeter = 0;
pInfo->bmiHeader.biClrUsed = 0;
pInfo->bmiHeader.biClrImportant = 0;
pData = new char[sInfo.bmWidth * 4];
for(iLine = 0; iLine < sInfo.bmHeight; iLine++)
{
iRet = GetDIBits(hMemDC, m_hBitmap,
(sInfo.bmHeight - 1) - iLine, 1,
pData, pInfo, DIB_RGB_COLORS);
if (!iRet)
{
break;
}
for(iCol = 0, pColorPtr = (Color *)pData;
iCol < sInfo.bmWidth; iCol++, pColorPtr++)
{
if (pColorPtr->red != m_oTransColor.blue ||
pColorPtr->green != m_oTransColor.green ||
pColorPtr->blue != m_oTransColor.red)
pHist[mcRGB(pColorPtr->blue, pColorPtr->green, pColorPtr->red)]++;
}
}
delete pData;
delete pInfo;
DeleteDC(hMemDC);
}
void Win32Bitmap::ConvertTo256Color(WORD *pHist,
RGBQUAD *pColorTable)
{
BITMAP sInfo;
BITMAPINFO *pInfo;
HDC hRootDC, hMemDC;
int iRet, iLine, iCol, iPack;
unsigned char *pData, *p8BitData, *pDest;
Color sTrans, *pColorPtr;
HBITMAP h8BitBitmap;
hRootDC = GetDC(NULL);
hMemDC = CreateCompatibleDC(hRootDC);
ReleaseDC(NULL, hRootDC);
GetObject(m_hBitmap, sizeof(BITMAP), (LPSTR)&sInfo);
pInfo = (BITMAPINFO *)new char[sizeof(BITMAPINFOHEADER)];
pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pInfo->bmiHeader.biWidth = sInfo.bmWidth;
pInfo->bmiHeader.biHeight = sInfo.bmHeight;
pInfo->bmiHeader.biPlanes = 1;
pInfo->bmiHeader.biBitCount = 24;
pInfo->bmiHeader.biCompression = BI_RGB;
pInfo->bmiHeader.biSizeImage = 0;
pInfo->bmiHeader.biXPelsPerMeter = 0;
pInfo->bmiHeader.biYPelsPerMeter = 0;
pInfo->bmiHeader.biClrUsed = 0;
pInfo->bmiHeader.biClrImportant = 0;
iPack = sInfo.bmWidth % 2;
pData = new unsigned char[sInfo.bmWidth * 4];
p8BitData = new unsigned char[(sInfo.bmWidth + iPack) * sInfo.bmHeight];
for(iLine = 0, pDest = p8BitData; iLine < sInfo.bmHeight; iLine++)
{
iRet = GetDIBits(hMemDC, m_hBitmap,
(sInfo.bmHeight - 1) - iLine, 1,
pData, pInfo, DIB_RGB_COLORS);
if (!iRet)
{
break;
}
for(iCol = 0, pColorPtr = (Color *)pData;
iCol < sInfo.bmWidth; iCol++, pColorPtr++, pDest++)
{
*pDest = pHist[mcRGB(pColorPtr->blue, pColorPtr->green, pColorPtr->red)] + 10;
}
pDest += iPack;
}
h8BitBitmap = CreateBitmap(sInfo.bmWidth, sInfo.bmHeight, 1, 8, p8BitData);
delete pData;
delete p8BitData;
delete pInfo;
DeleteDC(hMemDC);
if (m_hBitmap)
{
DeleteObject(m_hBitmap);
m_pBitmapData = NULL;
}
m_hBitmap = h8BitBitmap;
m_pBitmapData = NULL;
}
void Win32Bitmap::SetPalette(HPALETTE hPal)
{
if (m_hPal)
DeleteObject(m_hPal);
m_hPal = hPal;
}
Bitmap *Win32Bitmap::Clone(void)
{
Win32Bitmap *pTemp;
Rect oRect;
pTemp = new Win32Bitmap(m_iWidth, m_iHeight, m_oBitmapName);
pTemp->m_oTransColor = m_oTransColor;
pTemp->m_bHasTransColor = m_bHasTransColor;
oRect.x1 = oRect.y1 = 0;
oRect.x2 = m_iWidth;
oRect.y2 = m_iHeight;
pTemp->BlitRect(this, oRect, oRect);
pTemp->BlitRectMaskBitmap(this, oRect, oRect);
return pTemp;
}
Error Win32Bitmap::MakeTransparent(Rect &oRect)
{
HDC hRootDC, hDC;
RECT sRect;
if (m_hMaskBitmap == NULL)
return kError_UnknownErr;
hRootDC = GetDC(NULL);
hDC = CreateCompatibleDC(hRootDC);
ReleaseDC(NULL, hRootDC);
sRect.left = oRect.x1;
sRect.right = oRect.x2;
sRect.top = oRect.y1;
sRect.bottom = oRect.y2;
SelectObject(hDC, m_hMaskBitmap);
FillRect(hDC, &sRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
DeleteDC(hDC);
return kError_NoErr;
}
void Win32Bitmap::BlitIt(int x, int y)
{
HDC hSrcDC, hDestDC;
if (m_hBitmap == NULL)
{
return;
}
hDestDC = GetDC(NULL);
hSrcDC = CreateCompatibleDC(hDestDC);
SelectObject(hSrcDC, m_hBitmap);
BitBlt(hDestDC, x, y,
m_iWidth, m_iHeight,
hSrcDC, 0, 0,
SRCCOPY);
ReleaseDC(NULL, hDestDC);
DeleteDC(hSrcDC);
}
void Win32Bitmap::GetColor(Pos oPos, Color &oColor)
{
}
void Win32Bitmap::GetSize(Pos &oPos)
{
oPos.x = m_iWidth;
oPos.y = m_iHeight;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -