资源位图上无法显示透明颜色 [英] Transparent color can't be shown on resource bitmap

查看:57
本文介绍了资源位图上无法显示透明颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在位图上绘制透明的颜色.但是,当我按如下方式编写代码并运行它时,位图会被覆盖成彩色.我的代码有什么问题?另外,我的程序中是否有不必要的代码?
过程如下:
我将位图资源导入MFC CDialog程序.将图片控件添加到CDialog,并将以前导入的位图添加到图片控件.将图片控件属性设置为透明.
然后,将以下代码添加到onpaint.

Hi,

I would like to draw transparent color on bitmap. But, when I write the code as follow and run it, the bitmap is covered on color. What is wrong on my code? Also, is there any unnecessary code in my program ?
The process is as follow:
I import bitmap resource to MFC CDialog program. Add picture control to CDialog and add the previous imported bitmap to picture control. Set picture control property as transparent.
Then, I add the follow code to onpaint.

CDC dc;
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP_TESTBITMAP);
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
CDC* pDC = this->GetDC();
dc.CreateCompatibleDC(pDC);
CBitmap* pOldBmp = dc.SelectObject(&bmp);
for (int i = 0; i < bmpInfo.bmHeight; i++) {
    for(int j = 0; j < bmpInfo.bmWidth; j++) {
        dc.SetPixel(j, i, RGB(rand()%100, rand()%50, rand()%100));
    }
}
pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &dc, 0, 0, SRCAND);
dc.SelectObject(pOldBmp);
bmp.DeleteObject();
dc.DeleteDC();
this->ReleaseDC(pDC);
CDialogEx::OnPaint();


感谢您的帮助和时间.


Thanks for your help and time.

推荐答案

看看:
使用MFC中的动态蒙版轻松绘制透明位图 [ ^ ]
使用CImage绘制透明位图 [
Have a look at:
Drawing Transparent Bitmap with ease with on the fly masks in MFC[^]
Drawing transparent bitmaps using CImage[^]

Best regards
Espen Harlinn


这篇关于资源位图上无法显示透明颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆