查看单个帖子
旧 2009-08-19, 08:03 PM   #1
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 Alpha Blend code (MFC)

void CMyDlg::AlphaBlend(CDC *pDC, double blend)
{
BITMAP bmpX,bmpY;

CBitmap bmp1,bmp2;
bmp2.LoadBitmap(IDB_BITMAP2);
bmp1.LoadBitmap(IDB_BITMAP1);

bmp1.GetBitmap(&bmpX);
UINT* bmpBuffer=(UINT*) GlobalAlloc(GPTR,
bmpX.bmWidthBytes * bmpX.bmHeight);
bmp1.GetBitmapBits(bmpX.bmWidthBytes * bmpX.bmHeight, bmpBuffer);

bmp2.GetBitmap(&bmpY);
UINT* bmpBuffer2=(UINT*) GlobalAlloc(GPTR,
bmpY.bmWidthBytes * bmpY.bmHeight);
bmp2.GetBitmapBits(bmpY.bmWidthBytes * bmpY.bmHeight, bmpBuffer2);

int nSize = bmpY.bmWidth * bmpY.bmHeight;

for (int i = 0; i < nSize; i++)
{
int abR = (int) (GetR(bmpBuffer[i]) * blend +
(1-blend) * GetR(bmpBuffer2[i]));
int abG = (int) (GetG(bmpBuffer[i]) * blend +
(1-blend) * GetG(bmpBuffer2[i]));
int abB = (int) (GetB(bmpBuffer[i]) * blend +
(1-blend) * GetB(bmpBuffer2[i]));

bmpBuffer2[i] = RGB(abB, abG, abR);
}

bmp2.SetBitmapBits(bmpX.bmWidthBytes * bmpX.bmHeight, bmpBuffer2);

CDC memdc;
memdc.CreateCompatibleDC(pDC);
memdc.SelectObject(bmp2);
pDC->BitBlt(10,10,bmpX.bmWidthBytes,
bmpX.bmHeight, &memdc, 0, 0, SRCCOPY);

GlobalFree((HGLOBAL)bmpBuffer);
GlobalFree((HGLOBAL)bmpBuffer2);
memdc.DeleteDC();
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/DonJikn/archiv...02/3858454.aspx
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
huangyhg离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)