| 发表于: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; } | | |
|