CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  图形处理/算法

求透明背景图片绘制例子

楼主alibaba2006()2006-03-09 21:30:49 在 VC/MFC / 图形处理/算法 提问

RT:alibaba2006@163.com 问题点数:100、回复次数:3Top

1 楼unionize(同盟会)回复于 2006-03-09 22:38:37 得分 50

E-Mail   sent   successfullyTop

2 楼striking(庸人自扰)回复于 2006-03-09 23:01:31 得分 50

void     DrawTransparentBitmap(HDC     hdc,     HBITMAP     hBitmap,     short     xStart,      
                                                                                                            short     yStart,     COLORREF     cTransparentColor)      
            {      
            BITMAP                     bm;      
            COLORREF             cColor;      
            HBITMAP                 bmAndBack,     bmAndObject,     bmAndMem,     bmSave;      
            HBITMAP                 bmBackOld,     bmObjectOld,     bmMemOld,     bmSaveOld;      
            HDC                                 hdcMem,     hdcBack,     hdcObject,     hdcTemp,     hdcSave;      
            POINT                         ptSize;      
     
            hdcTemp     =     CreateCompatibleDC(hdc);      
            SelectObject(hdcTemp,     hBitmap);             //     Select     the     bitmap      
     
            GetObject(hBitmap,     sizeof(BITMAP),     (LPSTR)&bm);      
            ptSize.x     =     bm.bmWidth;                                                 //     Get     width     of     bitmap      
            ptSize.y     =     bm.bmHeight;                                             //     Get     height     of     bitmap      
            DPtoLP(hdcTemp,     &ptSize,     1);                         //     Convert     from     device      
     
                                                                                                                                                    //     to     logical     points      
     
            //     Create     some     DCs     to     hold     temporary     data.      
            hdcBack             =     CreateCompatibleDC(hdc);      
            hdcObject     =     CreateCompatibleDC(hdc);      
            hdcMem                 =     CreateCompatibleDC(hdc);      
            hdcSave             =     CreateCompatibleDC(hdc);      
     
            //     Create     a     bitmap     for     each     DC.     DCs     are     required     for     a     number     of      
            //     GDI     functions.      
     
            //     Monochrome     DC      
            bmAndBack             =     CreateBitmap(ptSize.x,     ptSize.y,     1,     1,     NULL);      
     
            //     Monochrome     DC      
            bmAndObject     =     CreateBitmap(ptSize.x,     ptSize.y,     1,     1,     NULL);      
     
            bmAndMem                 =     CreateCompatibleBitmap(hdc,     ptSize.x,     ptSize.y);      
            bmSave                         =     CreateCompatibleBitmap(hdc,     ptSize.x,     ptSize.y);      
     
            //     Each     DC     must     select     a     bitmap     object     to     store     pixel     data.      
            bmBackOld             =     SelectObject(hdcBack,     bmAndBack);      
            bmObjectOld     =     SelectObject(hdcObject,     bmAndObject);      
            bmMemOld                 =     SelectObject(hdcMem,     bmAndMem);      
            bmSaveOld             =     SelectObject(hdcSave,     bmSave);      
     
            //     Set     proper     mapping     mode.      
            SetMapMode(hdcTemp,     GetMapMode(hdc));      
     
            //     Save     the     bitmap     sent     here,     because     it     will     be     overwritten.      
            BitBlt(hdcSave,     0,     0,     ptSize.x,     ptSize.y,     hdcTemp,     0,     0,     SRCCOPY);      
     
            //     Set     the     background     color     of     the     source     DC     to     the     color.      
            //     contained     in     the     parts     of     the     bitmap     that     should     be     transparent      
            cColor     =     SetBkColor(hdcTemp,     cTransparentColor);      
     
            //     Create     the     object     mask     for     the     bitmap     by     performing     a     BitBlt      
            //     from     the     source     bitmap     to     a     monochrome     bitmap.      
            BitBlt(hdcObject,     0,     0,     ptSize.x,     ptSize.y,     hdcTemp,     0,     0,      
                                        SRCCOPY);      
     
            //     Set     the     background     color     of     the     source     DC     back     to     the     original      
            //     color.      
            SetBkColor(hdcTemp,     cColor);      
     
            //     Create     the     inverse     of     the     object     mask.      
            BitBlt(hdcBack,     0,     0,     ptSize.x,     ptSize.y,     hdcObject,     0,     0,      
                                        NOTSRCCOPY);      
     
            //     Copy     the     background     of     the     main     DC     to     the     destination.      
            BitBlt(hdcMem,     0,     0,     ptSize.x,     ptSize.y,     hdc,     xStart,     yStart,      
                                        SRCCOPY);      
     
            //     Mask     out     the     places     where     the     bitmap     will     be     placed.      
            BitBlt(hdcMem,     0,     0,     ptSize.x,     ptSize.y,     hdcObject,     0,     0,     SRCAND);      
     
            //     Mask     out     the     transparent     colored     pixels     on     the     bitmap.      
            BitBlt(hdcTemp,     0,     0,     ptSize.x,     ptSize.y,     hdcBack,     0,     0,     SRCAND);      
     
            //     XOR     the     bitmap     with     the     background     on     the     destination     DC.      
            BitBlt(hdcMem,     0,     0,     ptSize.x,     ptSize.y,     hdcTemp,     0,     0,     SRCPAINT);      
     
            //     Copy     the     destination     to     the     screen.      
            BitBlt(hdc,     xStart,     yStart,     ptSize.x,     ptSize.y,     hdcMem,     0,     0,      
                                        SRCCOPY);      
     
            //     Place     the     original     bitmap     back     into     the     bitmap     sent     here.      
            BitBlt(hdcTemp,     0,     0,     ptSize.x,     ptSize.y,     hdcSave,     0,     0,     SRCCOPY);      
     
            //     Delete     the     memory     bitmaps.      
            DeleteObject(SelectObject(hdcBack,     bmBackOld));      
            DeleteObject(SelectObject(hdcObject,     bmObjectOld));      
            DeleteObject(SelectObject(hdcMem,     bmMemOld));      
            DeleteObject(SelectObject(hdcSave,     bmSaveOld));      
     
            //     Delete     the     memory     DCs.      
            DeleteDC(hdcMem);      
            DeleteDC(hdcBack);      
            DeleteDC(hdcObject);      
            DeleteDC(hdcSave);      
            DeleteDC(hdcTemp);      
            }          
     
  The     following     is     an     example     of     how     the     DrawTransparentBitmap     function     might     be     called:          
     
            DrawTransparentBitmap(hdc,                                     //     The     destination     DC.      
     
                                                                                                    hBitmap,                     //     The     bitmap     to     be     drawn.      
                                                                                                    xPos,                                 //     X     coordinate.      
                                                                                                    yPos,                                 //     Y     coordinate.      
                                                                                                    0x00FFFFFF);     //     The     color     for     transparent      
                                                                                                                                                        //     pixels     (white,     in     this      
                                                                                                                                                        //     example).          
   
  Top

3 楼alibaba2006()回复于 2006-03-10 17:32:46 得分 0

受到邮件了,还是谢谢楼上两位Top

相关问题

  • 求透明图像绘制例子
  • 如何在CDC上绘制背景透明的图片
  • 怎样在 Canvas 上绘制透明位图?(即去除背景)谢谢!
  • 绘制透明控件问题
  • c++ builder 的背景透明...
  • 控件背景透明
  • 背景透明的问题
  • bitmap透明背景问题
  • 如何使背景透明?
  • 透明背景的控件

关键词

  • dc
  • ptsize
  • hdctemp
  • hdcobject
  • hdcback
  • hdcsave
  • hdcmem
  • bitmap
  • bitblt
  • hdc

得分解答快速导航

  • 帖主:alibaba2006
  • unionize
  • striking

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo