您的位置:程序门 -> c/c++ -> c++ 语言



关于transparentimage函数怎么用?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


关于transparentimage函数怎么用?
发表于:2007-08-11 19:49:42 楼主
请问已经把一张图通过
下面的代码片段总结了如何绘制位图:

//   create   a   dc   that   matches   the   device.
hdcmem   =   createcompatibledc   (hdc);
      hbitmap=load(   .......                         )
holdsel   =   selectobject   (hdcmem,   hbitmap);
     

getobject   (hbitmap,   sizeof   (bitmap),   &bmp);
     
//   copy   the   bitmap   image   from   the   memory   dc   to   the   screen   dc.
bitblt   (hdc,   rect.left,   rect.top,   bmp.bmwidth,   bmp.bmheight,  
                hdcmem,   0,   0,   srccopy);
     
//   restore   original   bitmap   selection   and   destroy   the   memory   dc.
selectobject   (hdcmem,   holdsel);
deletedc   (hdcmem);
加入到pocket   pc上,要把另一张图片加到它的上边,过滤掉一种颜色
不知道怎么用transparentimage这个函数?还有其他函数实现这个吗?
发表于:2007-08-13 20:54:441楼 得分:0
实现图像指定颜色的透明这是我写nfml遇到的一个小问题,对于vc++不是特别熟的人来说算是个问题!自认为还凑合吧,不过感觉效率一般。
                此类技术一般用于有背景的贴图,我们不能针对每种背景对图片进行处理,那么就需要对图片轮廓进行高对比度颜色处理,就是用某种跟图片的像素不相近的单色填充图片背景,然后用程序将这个单色去掉来实现透明。具体实现如下:

lresult   cnfmlguidraw::nfmldrawtransparentimage(hwnd   hwnd,   hbitmap   hbitmap,   int   xpos,   int   ypos,colorref   transcolor)
{
  hdc   hdc   =   getdc(hwnd);
  bitmap   bmp;
  int   xcnt;
  hdc   hdcmem   =   createcompatibledc(hdc);
  hgdiobj   holdsel   =   selectobject(hdcmem,   hbitmap);
  getobject(hbitmap,   sizeof(bitmap),   &bmp);
  for(xcnt=xpos;   xcnt <bmp.bmwidth;   xcnt+=bmp.bmwidth)
  {
    transparentimage(hdc,
              xcnt,
              ypos,
              bmp.bmwidth   +   xcnt,
              bmp.bmheight   +   ypos,
              hdcmem,
              xpos,
              ypos,
              bmp.bmwidth   +   xpos,
              bmp.bmheight   +   ypos,
              transcolor             );
  }
  selectobject(hdcmem,   holdsel);
  deletedc(hdcmem);
  return   0;
}



快速检索

最新资讯
热门点击