请问,如何将一个在窗体中显示的BMP图(ico图标)显示为透明背景?

batboy99 2003-08-25 03:53:35
请问,如何将一个在窗体中显示的BMP图(ico图标)显示为透明背景?以不挡住后面的内容。
谢谢回答,新手提问。
...全文
277 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kongyunzhongque 2003-10-08
  • 打赏
  • 举报
回复
up
wangzi163 2003-10-08
  • 打赏
  • 举报
回复
up
wguaner 2003-10-08
  • 打赏
  • 举报
回复
学习ING,帮顶。
kangfx 2003-09-01
  • 打赏
  • 举报
回复
gz
lbird 2003-08-26
  • 打赏
  • 举报
回复
BOOL TransparentBlt(
int xDest,
int yDest,
int nDestWidth,
int nDestHeight,
CDC* pSrcDC,
int xSrc,
int ySrc,
int nSrcWidth,
int nSrcHeight,
UINT clrTransparent //透明的颜色
);
gzshd 2003-08-26
  • 打赏
  • 举报
回复
1 取出源位图各个象素点,将各像素点的RGB值乘以预设的透明度,放入一个暂存数组中。
2 取出背景图与源位图重叠部分的像素点,将各像素点的RGB值乘以100%-0%之间的预设的透明度,放入到另一个暂存数组中
3 将前两个步骤所产生的数组相加,就产生了所有半透明图的色彩值了。

BITMAP bm;
int x,y,s,t,m,i=0;
GetClientRect(&rect);
mdc = new CDC;
bitmap = new CBitmap;
bgbmp = new CBitmap;
mdc->CreateCompatibleDC(dc);
bgbmp->m_hObject = (HBITMAP)::LoadImage(NULL,"bground.bmp",IMAGE_BITMAP,rect.right,rect.bottom,LR_LOADFROMFILE);
bitmap->m_hObject = (HBITMAP)::LoadImage(NULL,"girl.bmp",IMAGE_BITMAP,298,329,LR_LOADFROMFILE);
bitmap->GetObject(sizeof(BITMAP),&bm);
unsigned char *px = new unsigned char[bm.bmHeight*bm.bmWidthBytes];
bitmap->GetBitmapBits(bm.bmHeight*bm.bmWidthBytes,px);
s = bm.bmHeight;
t = bm.bmWidth;
m = bm.bmWidthBytes;
for(y=0;y<bm.bmHeight;y++)
for(x=0;x<bm.bmWidth;x++)
{
px[x*3+y*bm.bmWidthBytes] *= 0.5;
px[x*3+1+y*bm.bmWidthBytes] *= 0.5;
px[x*3+2+y*bm.bmWidthBytes] *= 0.5;

}
bitmap->SetBitmapBits(bm.bmHeight*bm.bmWidthBytes,px);
bgbmp->GetObject(sizeof(BITMAP),&bm);
unsigned char *py = new unsigned char[bm.bmHeight*bm.bmWidthBytes];
bgbmp->GetBitmapBits(bm.bmHeight*bm.bmWidthBytes,py);
for(y=100;y<100+s;y++)
{
i = (y-100)*m;
for(x=100;x<100+t;x++)
{
py[x*3+y*bm.bmWidthBytes] = py[x*3+y*bm.bmWidthBytes]*0.5 + px[i];
py[x*3+1+y*bm.bmWidthBytes] = py[x*3+1+y*bm.bmWidthBytes]*0.5 + px[i+1];
py[x*3+2+y*bm.bmWidthBytes] = py[x*3+2+y*bm.bmWidthBytes]*0.5 + px[i+2];
i=i+3;
}
}
bgbmp->SetBitmapBits(bm.bmHeight*bm.bmWidthBytes,py);
mdc->SelectObject(bgbmp);
delete px;
delete py;
mct1025 2003-08-25
  • 打赏
  • 举报
回复
透明位图的显示
http://www.vckbase.com/document/viewdoc.asp?id=532

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧