本文整理汇总了C++中CDC::AlphaBlend方法的典型用法代码示例。如果您正苦于以下问题:C++ CDC::AlphaBlend方法的具体用法?C++ CDC::AlphaBlend怎么用?C++ CDC::AlphaBlend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDC
的用法示例。
在下文中一共展示了CDC::AlphaBlend方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawHorizontalTransition
// 画水平过渡
int DrawHorizontalTransition(CDC &dcDes, CDC &dcSrc, const CRect &rcDes, const CRect &rcSrc, int nBeginTransparent/* = 0*/, int nEndTransparent/* = 100*/)
{
ASSERT(rcDes.Width() == rcSrc.Width() && rcDes.Height() == rcSrc.Height());
BOOL bIsDownTransition = TRUE;
if (nEndTransparent <= nBeginTransparent)
{
bIsDownTransition = FALSE;
int nTemp = nBeginTransparent;
nBeginTransparent = nEndTransparent;
nEndTransparent = nTemp;
}
BLENDFUNCTION blend;
memset( &blend, 0, sizeof( blend) );
blend.BlendOp = AC_SRC_OVER;
blend.SourceConstantAlpha = 255;
int nWidth = rcDes.Width();
int nHeight = rcDes.Height();
int nMinTransition = (int)(255 - 255.0 * nBeginTransparent / 100.0);
int nMaxTransition = (int)(255.0 * (100 - nEndTransparent) / 100.0);
double dTransition = (nMinTransition - nMaxTransition) / (double)nWidth;
for (int i = 0; i < nWidth; i++)
{
blend.SourceConstantAlpha = (BYTE)(bIsDownTransition ? nMinTransition - (dTransition * i) : nMaxTransition + (dTransition * i));
dcDes.AlphaBlend(rcDes.left + i, rcDes.top , 1, nHeight, &dcSrc, rcSrc.left + i, rcSrc.top, 1, nHeight, blend);
}
return blend.SourceConstantAlpha;
}
示例2: DrawRightBottomTransition
// 画右下角过渡
void DrawRightBottomTransition(CDC &dc, CDC &dcTemp, CRect rc, const int nOverRegio, const COLORREF clrBackground)
{
BLENDFUNCTION blend;
memset( &blend, 0, sizeof( blend) );
blend.BlendOp= AC_SRC_OVER;
blend.SourceConstantAlpha = 255;
int nStartX = rc.Width() - nOverRegio;
int nStartY = rc.Height() - nOverRegio;
double dRadius = (double)sqrt((double)(nOverRegio * nOverRegio + nOverRegio * nOverRegio));
double dRadiusTemp = 0.0;
for (int i = 0; i < nOverRegio; i++)
{
for (int j = 0; j < nOverRegio; j++)
{
dRadiusTemp = (double)sqrt((double)(i * i + j * j));
if (dRadiusTemp > nOverRegio)
{
dRadiusTemp = nOverRegio;
}
blend.SourceConstantAlpha = (BYTE)(255 - (255.0 / nOverRegio * (dRadiusTemp)));
dc.AlphaBlend(nStartX + i, nStartY + j, 1, 1, &dcTemp, nStartX + i, nStartY + j, 1, 1, blend);
}
}
}
示例3: DrawVerticalTransition
int CControlBase::DrawVerticalTransition(CDC &dcDes, CDC &dcSrc, const CRect &rc, int nBeginTransparent/* = 0*/, int nEndTransparent/* = 100*/)
{
BOOL bIsDownTransition = TRUE;
if (nEndTransparent <= nBeginTransparent)
{
bIsDownTransition = FALSE;
int nTemp = nBeginTransparent;
nBeginTransparent = nEndTransparent;
nEndTransparent = nTemp;
}
BLENDFUNCTION blend;
memset( &blend, 0, sizeof( blend) );
blend.BlendOp= AC_SRC_OVER;
blend.SourceConstantAlpha = 255;
int nStartPosition = rc.top;
int nWidth = rc.right - rc.left;
int nHeight = rc.bottom - rc.top;
int nMinTransition = 255 - 255.0 * nBeginTransparent / 100.0;
int nMaxTransition = 255.0 * (100 - nEndTransparent) / 100.0;
double dTransition = (nMinTransition - nMaxTransition) / (double)nHeight;
if (bIsDownTransition)
{
for (int i = 0; i < nHeight; i++)
{
blend.SourceConstantAlpha = nMinTransition/* - nMaxTransition*/ - (dTransition * i);
dcDes.AlphaBlend(rc.left, nStartPosition + i,nWidth , 1,
&dcSrc, rc.left, nStartPosition + i, nWidth, 1, blend);
//TRACE("%d\n", blend.SourceConstantAlpha);
}
}
else
{
for (int i = 0; i < nHeight; i++)
{
blend.SourceConstantAlpha = nMaxTransition + (dTransition * i);
dcDes.AlphaBlend(rc.left, nStartPosition + i,nWidth , 1,
&dcSrc, rc.left, nStartPosition + i, nWidth, 1, blend);
//TRACE("\t\t\t\t%d\n", blend.SourceConstantAlpha);
}
}
//TRACE("\n");
return blend.SourceConstantAlpha;
}
示例4: Draw
void RectAlphaDrawer::Draw(CDC& dc, CRect& rc, BYTE Alpha)
{
if (m_pDC == NULL)
CreateInternalDC(&dc);
BLENDFUNCTION blFunc = {AC_SRC_OVER, 0, Alpha, 0};
dc.AlphaBlend(rc.left, rc.top, rc.Width(), rc.Height(), GetInternalDC(), 0, 0, s_InternalRect.Width(), s_InternalRect.Height(), blFunc);
if (m_drawOptions & DO_DrawNotAlphaPerigram)
dc.Draw3dRect(&rc, m_bkColor, m_bkColor);
}
示例5: Draw
void ToppyFramework::Draw(CDC* pDC)
{
CDC* pMemDC = GetDC();
if (NeedsRepaint())
{
m_TheState.Draw(pMemDC);
CDC osdDC;
osdDC.CreateCompatibleDC(pDC);
osdDC.SetBkColor(TRANSPARENT_COLOUR);
CBitmap bmOsd;
bmOsd.CreateCompatibleBitmap(pDC, 720, 576);
osdDC.SelectObject(&bmOsd);
osdDC.FillSolidRect(0,0,720,576,TRANSPARENT_COLOUR);
if (m_OSDregions.Draw(&osdDC))
{
CDC monoDC;
monoDC.CreateCompatibleDC(pDC);
CBitmap maskBm;
maskBm.CreateBitmap(720, 576, 1, 1, NULL);
monoDC.SelectObject(maskBm);
osdDC.SetBkColor(TRANSPARENT_COLOUR);
monoDC.BitBlt(0, 0, 720, 576, &osdDC, 0, 0, SRCCOPY);
CDC tempDC;
tempDC.CreateCompatibleDC(pDC);
CBitmap tempBM;
tempBM.CreateCompatibleBitmap(pDC, 720, 576);
tempDC.SelectObject(&tempBM);
tempDC.BitBlt(0,0, 720, 576, pMemDC, 0, 0, SRCCOPY);
BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255-(BYTE)(GetConfig()->GetOsdTransparency() * 255/100), 0};
pMemDC->AlphaBlend(0, 0, 720, 576, &osdDC, 0, 0, 720, 576, bf );
//
//// now contains correct over OSD area, wrong in background
//
pMemDC->MaskBlt(0,0, 720, 576, &tempDC, 0, 0, maskBm, 0, 0, MAKEROP4(SRCCOPY, DSTCOPY));
//memDC.BitBlt(0, 0, 720, 576, &osdDC, 0, 0, SRCCOPY);
}
}
pDC->BitBlt(0,0, 720, 576, pMemDC, 0, 0, SRCCOPY);
ReleaseDC();
}
示例6: DrawRectangle
// 画过渡圆角矩加
void DrawRectangle(CDC &dc, const CRect &rc, BOOL bUp/* = TRUE*/, int nBeginTransparent/* = 50*/, int nEndTransparent/* = 90*/)
{
int nWidth = rc.Width();
int nHeight = rc.Height();
int nDesStartX = rc.left;
int nDesStartY = rc.top;
CDC TempDC;
TempDC.CreateCompatibleDC(&dc);
CBitmap memBmp;
memBmp.CreateCompatibleBitmap(&dc, nWidth, nHeight);
CBitmap *pOldmap = TempDC.SelectObject(&memBmp);
TempDC.FillSolidRect(0, 0, nWidth, nHeight, RGB(0, 0, 0));
TempDC.FillSolidRect(1, 1, nWidth - 2, nHeight - 2, RGB(255, 255, 255));
// 中间
CRect rcSrc;
CRect rcDes;
if(bUp)
{
rcSrc.SetRect(1, 1, nWidth - 1, nHeight / 2);
rcDes.SetRect(nDesStartX + 1, nDesStartY + 1, nDesStartX + nWidth - 1, nDesStartY + nHeight / 2);
}
else
{
rcSrc.SetRect(1, nHeight / 2, nWidth - 1, nHeight - 1);
rcDes.SetRect(nDesStartX + 1, nDesStartY + nHeight / 2, nDesStartX + nWidth - 1, nDesStartY + nHeight - 1);
}
DrawVerticalTransition(dc, TempDC, rcDes, rcSrc, nBeginTransparent, nEndTransparent);
// 边框
BLENDFUNCTION blend;
memset( &blend, 0, sizeof( blend) );
blend.BlendOp= AC_SRC_OVER;
blend.SourceConstantAlpha = 100;
// 左
dc.AlphaBlend(nDesStartX, nDesStartY + 1, 2, nHeight - 2, &TempDC, 0, 1, 2, nHeight - 2, blend);
// 上
dc.AlphaBlend(nDesStartX + 1, nDesStartY, nWidth - 2, 2, &TempDC, 1, 0, nWidth - 2, 2, blend);
// 右
dc.AlphaBlend(nDesStartX + nWidth - 2, nDesStartY + 1, 2, nHeight - 2, &TempDC, nWidth - 2, 1, 2, nHeight - 2, blend);
// 下
dc.AlphaBlend(nDesStartX + 1, rc.bottom - 2, nWidth - 2, 2, &TempDC, 1, nHeight - 2, nWidth - 2, 2, blend);
blend.SourceConstantAlpha = 12;
// 左上
dc.AlphaBlend(nDesStartX, nDesStartY, 2, 2, &TempDC, 0, 0, 1, 1, blend);
// 右上
dc.AlphaBlend(nDesStartX + nWidth, nDesStartY, 2, 2, &TempDC, 0, 0, 1, 1, blend);
// 右下
dc.AlphaBlend(nDesStartX + nWidth, nDesStartY + nHeight, 2, 2, &TempDC, 0, 0, 1, 1, blend);
// 左下
dc.AlphaBlend(nDesStartX , nDesStartY + nHeight, 2, 2, &TempDC, 0, 0, 1, 1, blend);
TempDC.SelectObject(pOldmap);
memBmp.DeleteObject();
TempDC.DeleteDC();
}
示例7: DrawWindow
void CWndPopup::DrawWindow()
{
CRect rcClient;
GetClientRect(&rcClient);
CDC *pDC = GetDC();
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
CBitmap memBit;
memBit.CreateCompatibleBitmap(pDC, rcClient.Width(), rcClient.Height());
CBitmap *pOldBit = MemDC.SelectObject(&memBit);
MemDC.SetBkMode(TRANSPARENT);
if(m_pImage)
{
Graphics graphics(MemDC);
DrawImageFrame(graphics, m_pImage, rcClient,0, 0, m_sizeBKImage.cx, m_sizeBKImage.cy, 32);
}
else
{
MemDC.FillSolidRect(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), RGB(0, 147, 209));
MemDC.FillSolidRect(rcClient.left + 1, rcClient.top + 1, rcClient.Width() - 2, rcClient.Height() - 2, RGB(255, 255, 255));
}
CDC TempMemDC;
TempMemDC.CreateCompatibleDC(&MemDC);
TempMemDC.SetBkMode(TRANSPARENT);
CBitmap TempMemBit;
TempMemBit.CreateCompatibleBitmap(&MemDC, rcClient.Width(), rcClient.Height());
CBitmap *pTempOldBit = TempMemDC.SelectObject(&TempMemBit);
TempMemDC.FillSolidRect(0, 0, rcClient.Width(), rcClient.Height(), RGB(255, 0, 255));
DrawWindow(TempMemDC, rcClient);
DWORD dwSize = TempMemBit.GetBitmapBits(0,NULL);
unsigned char *lpBuffer = new unsigned char[dwSize];
TempMemBit.GetBitmapBits(dwSize,lpBuffer);
for( int i = 0 ; i+3 < dwSize ; i+=4 )
{
if(lpBuffer[i] == 255 && lpBuffer[i + 1] == 0 && lpBuffer[i + 2] == 255)
{
lpBuffer[i] = 0;
lpBuffer[i + 1] = 0;
lpBuffer[i + 2] = 0;
}
else
{
if(lpBuffer[i] == 0 && lpBuffer[i + 1] == 0 && lpBuffer[i + 2] == 0) lpBuffer[i] = 1;
lpBuffer[i+3] = 255;
}
}
TempMemBit.SetBitmapBits(dwSize, lpBuffer);
delete[] lpBuffer;
BLENDFUNCTION blendTemp = {AC_SRC_OVER,0,255,AC_SRC_ALPHA};
MemDC.AlphaBlend(0, 0, rcClient.Width(), rcClient.Height(), &TempMemDC, 0, 0, rcClient.Width(), rcClient.Height(), blendTemp);
TempMemDC.SelectObject(pTempOldBit);
TempMemBit.DeleteObject();
TempMemDC.DeleteDC();
DrawWindowEx(MemDC, rcClient);
DWORD dwSizeMen = memBit.GetBitmapBits(0,NULL);
unsigned char *lpBufferMen = new unsigned char[dwSize];
memBit.GetBitmapBits(dwSizeMen,lpBufferMen);
for( int i = 0 ; i+3 < dwSizeMen ; i+=4 )
{
if(lpBufferMen[i] == 0 && lpBufferMen[i + 1] == 0 && lpBufferMen[i + 2] == 0) lpBufferMen[i] = 1;
}
memBit.SetBitmapBits(dwSizeMen, lpBufferMen);
delete[] lpBufferMen;
ClientToScreen(&rcClient);
POINT pointDes;
pointDes.x = rcClient.left;
pointDes.y = rcClient.top;
POINT pointSrc;
pointSrc.x = 0;
pointSrc.y = 0;
SIZE sizeDes;
sizeDes.cx = rcClient.Width();
sizeDes.cy = rcClient.Height();
BLENDFUNCTION blend;
memset( &blend, 0, sizeof( blend) );
blend.AlphaFormat = AC_SRC_ALPHA ;
blend.SourceConstantAlpha = 255;
HWND hWnd = GetSafeHwnd();
SetWindowLong(hWnd,GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
UpdateLayeredWindow(pDC, &pointDes, &sizeDes, &MemDC, &pointSrc, 0, &blend,m_pImage ? ULW_ALPHA : ULW_COLORKEY);
MemDC.SelectObject(pOldBit);
memBit.DeleteObject();
//.........这里部分代码省略.........
示例8: DrawTransitionSpace
int CControlBase::DrawTransitionSpace(CDC &dcDes, const CRect &rc, int nBeginTransparent/* = 0*/, int nEndTransparent/* = 100*/)
{
CRect rcClientTemp = rc;
CDC TempDC;
TempDC.CreateCompatibleDC(&dcDes);
CBitmap memBmp;
memBmp.CreateCompatibleBitmap(&dcDes, rc.right, rc.bottom);
CBitmap* pOldBitmap = TempDC.SelectObject(&memBmp);
TempDC.FillSolidRect(&rcClientTemp, RGB(0, 0, 0));
rcClientTemp.left++;
rcClientTemp.top++;
rcClientTemp.right--;
rcClientTemp.bottom--;
TempDC.FillSolidRect(&rcClientTemp, RGB(255, 255, 255));
if (nBeginTransparent <= nEndTransparent)
{
rcClientTemp.bottom = rcClientTemp.top + rc.Height() / 2;
DrawVerticalTransition(dcDes, TempDC, rcClientTemp, nBeginTransparent ,nEndTransparent);
rcClientTemp.top = rcClientTemp.bottom;
rcClientTemp.bottom = rc.bottom - 1;
DrawVerticalTransition(dcDes, TempDC, rcClientTemp, 90 ,90);
}
else
{
rcClientTemp.bottom = rcClientTemp.top + rc.Height() / 2;
DrawVerticalTransition(dcDes, TempDC, rcClientTemp, 90 ,90);
rcClientTemp.top = rcClientTemp.bottom;
rcClientTemp.bottom = rc.bottom - 1;
DrawVerticalTransition(dcDes, TempDC, rcClientTemp, nBeginTransparent ,nEndTransparent);
}
BLENDFUNCTION blend;
memset( &blend, 0, sizeof( blend) );
blend.BlendOp= AC_SRC_OVER;
blend.SourceConstantAlpha = 96; // 透明度
//左
dcDes.AlphaBlend(rc.left, rc.top + 2, 2, rc.Height() - 4, &TempDC, rc.left, rc.top + 2, 2, rc.Height() - 4, blend);
//上中
dcDes.AlphaBlend(rc.left + 2, rc.top, rc.Width() - 4, 2, &TempDC, rc.left + 2, rc.top, rc.Width() - 4, 2, blend);
//右
dcDes.AlphaBlend(rc.right - 2, rc.top + 2, 2, rc.Height() - 4, &TempDC, rc.right - 2, rc.top + 2, 2, rc.Height() - 4, blend);
//下
dcDes.AlphaBlend(rc.left + 2, rc.bottom - 2, rc.Width() - 4, 2, &TempDC, rc.left + 2, rc.bottom - 2, rc.Width() - 4, 2, blend);
blend.SourceConstantAlpha = 32;
//左上
dcDes.AlphaBlend(rc.left, rc.top, 1, 1, &TempDC, rc.left, rc.top, 1, 1, blend);
//右上
dcDes.AlphaBlend(rc.right - 1, rc.top, 1, 1, &TempDC, rc.right - 1, rc.top, 1, 1, blend);
//左下
dcDes.AlphaBlend(rc.left, rc.bottom - 1, 1, 1, &TempDC, rc.left, rc.bottom - 1, 1, 1, blend);
//右下
dcDes.AlphaBlend(rc.right - 1, rc.bottom - 1, 1, 1, &TempDC, rc.right - 1, rc.bottom - 1, 1, 1, blend);
blend.SourceConstantAlpha = 64;
//左上
dcDes.AlphaBlend(rc.left, rc.top + 1, 1, 1, &TempDC, rc.left, rc.top + 1, 1, 1, blend);
dcDes.AlphaBlend(rc.left + 1, rc.top, 1, 1, &TempDC, rc.left + 1, rc.top, 1, 1, blend);
//右上
dcDes.AlphaBlend(rc.right - 1, rc.top + 1, 1, 1, &TempDC, rc.right - 1, rc.top + 1, 1, 1, blend);
dcDes.AlphaBlend(rc.right - 2, rc.top, 1, 1, &TempDC, rc.right - 2, rc.top, 1, 1, blend);
//左下
dcDes.AlphaBlend(rc.left, rc.bottom - 2, 1, 1, &TempDC, rc.left, rc.bottom - 2, 1, 1, blend);
dcDes.AlphaBlend(rc.left + 1, rc.bottom - 1, 1, 1, &TempDC, rc.left + 1, rc.bottom - 1, 1, 1, blend);
//右下
dcDes.AlphaBlend(rc.right - 2, rc.bottom - 1, 1, 1, &TempDC, rc.right - 2, rc.bottom - 1, 1, 1, blend);
dcDes.AlphaBlend(rc.right - 1, rc.bottom - 2, 1, 1, &TempDC, rc.right - 1, rc.bottom - 2, 1, 1, blend);
return 0;
}