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();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值