51testing 2007-12-13 10:26
图片镂空算法集合[图]
在开发界面及棋牌游戏过程中,需要很多镂空的图片,而且图片形式一般比较固定.
所以封装了几种常见的镂空方法.
[b][color=#0000ff]1. 用于没有掩码图,只有指定透明色,不进行伸缩[/color][/b]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][color=#0000ff]void[/color][color=#000000] DrawTransBitmap( HDC hdcDest, [/color][color=#008000]//[/color][color=#008000] 目标DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标X偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标Y偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nWidthDest, [/color][color=#008000]//[/color][color=#008000] 目标宽度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nHeightDest, [/color][color=#008000]//[/color][color=#008000] 目标高度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] HDC hdcSrc, [/color][color=#008000]//[/color][color=#008000] 源DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源X起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源Y起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] COLORREF crTransparent [/color][color=#008000]//[/color][color=#008000] 透明色,COLORREF类型[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] );
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
适用图片:[img]http://p.blog.csdn.net/images/p_blog_csdn_net/xuweiqun/contact_folder_light.bmp[/img]
[b][color=#0000ff]2. 用于没有掩码图,只有指定透明色,可以进行伸缩[/color][/b]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[color=#0000ff]void[/color][color=#000000] DrawTransBitmap( HDC hdcDest, [/color][color=#008000]//[/color][color=#008000] 目标DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标X偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标Y偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nWidthDest, [/color][color=#008000]//[/color][color=#008000] 目标宽度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nHeightDest, [/color][color=#008000]//[/color][color=#008000] 目标高度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] HDC hdcSrc, [/color][color=#008000]//[/color][color=#008000] 源DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源X起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源Y起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nWidthSrc, [/color][color=#008000]//[/color][color=#008000] 源宽度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nHeightSrc, [/color][color=#008000]//[/color][color=#008000] 源高度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] COLORREF crTransparent [/color][color=#008000]//[/color][color=#008000] 透明色,COLORREF类型[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] );[/color]
适用图片:同1,可拉伸
[b][color=#0000ff]3.指定掩码图,和掩码图属于不同图片[/color][/b]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[color=#0000ff]void[/color][color=#000000] DrawTransBitmap( HDC hdcDest, [/color][color=#008000]//[/color][color=#008000] 目标DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标X偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标Y偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nWidthDest, [/color][color=#008000]//[/color][color=#008000] 目标宽度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nHeightDest, [/color][color=#008000]//[/color][color=#008000] 目标高度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] HDC hdcSrc, [/color][color=#008000]//[/color][color=#008000] 源DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] HDC hdcMask, [/color][color=#008000]//[/color][color=#008000]掩码DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源X起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源Y起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] COLORREF crTransparent [/color][color=#008000]//[/color][color=#008000] 透明色,COLORREF类型[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] );[/color]
适用图片:[img]http://p.blog.csdn.net/images/p_blog_csdn_net/xuweiqun/200.bmp[/img] 和 [img]http://p.blog.csdn.net/images/p_blog_csdn_net/xuweiqun/202.bmp[/img]
[b][color=#0000ff]4.指定图片和掩码图同属于一张图片[/color][/b]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][color=#0000ff]void[/color][color=#000000] DrawTransBitmap(HDC hDC,
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]int[/color][color=#000000] nPosX,
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]int[/color][color=#000000] nPosY,
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]int[/color][color=#000000] nCX,
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]int[/color][color=#000000] nCY,
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] HBITMAP hObj[/color]
[color=#000000] );[/color]
适用图片:[img]http://p.blog.csdn.net/images/p_blog_csdn_net/xuweiqun/20012.bmp[/img]
[b][color=#0000ff][/color][/b][b][color=#0000ff]5.得到位图HRGN[/color][/b]
[color=#000000] HRGN CreateBitmapRgn([/color][color=#0000ff]int[/color][color=#000000] nWidth,[/color][color=#0000ff]int[/color][color=#000000] nHeight,HBITMAP hbmp,COLORREF cTrans);[/color]
适用图片:[img]http://p.blog.csdn.net/images/p_blog_csdn_net/xuweiqun/picback.bmp[/img]
[size=5][/size]
[size=5][b]以下是完整代码[/b][/size]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][color=#008000]//[/color][color=#008000]用于没有掩码图,只有指定透明色,不进行伸缩[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]void[/color][color=#000000] CCommon::DrawTransBitmap( HDC hdcDest, [/color][color=#008000]//[/color][color=#008000] 目标DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标X偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标Y偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nWidthDest, [/color][color=#008000]//[/color][color=#008000] 目标宽度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nHeightDest, [/color][color=#008000]//[/color][color=#008000] 目标高度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] HDC hdcSrc, [/color][color=#008000]//[/color][color=#008000] 源DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源X起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源Y起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] COLORREF crTransparent [/color][color=#008000]//[/color][color=#008000] 透明色,COLORREF类型[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] )
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img]...[/color]...[color=#000000]{
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] HBITMAP hOldImageBMP, hImageBMP [/color][color=#000000]=[/color][color=#000000] CreateCompatibleBitmap(hdcDest, nWidthDest, nHeightDest); [/color][color=#008000]//[/color][color=#008000] 创建兼容位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] HBITMAP hOldMaskBMP, hMaskBMP [/color][color=#000000]=[/color][color=#000000] CreateBitmap(nWidthDest, nHeightDest, [/color][color=#000000]1[/color][color=#000000], [/color][color=#000000]1[/color][color=#000000], NULL); [/color][color=#008000]//[/color][color=#008000] 创建单色掩码位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] HDC hImageDC [/color][color=#000000]=[/color][color=#000000] CreateCompatibleDC(hdcDest);[/color][color=#008000]//[/color][color=#008000]临时DC [/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] HDC hMaskDC [/color][color=#000000]=[/color][color=#000000] CreateCompatibleDC(hdcDest);[/color][color=#008000]//[/color][color=#008000]临时掩码DC [/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] hOldImageBMP [/color][color=#000000]=[/color][color=#000000] (HBITMAP)SelectObject(hImageDC, hImageBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] hOldMaskBMP [/color][color=#000000]=[/color][color=#000000] (HBITMAP)SelectObject(hMaskDC, hMaskBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 将源DC中的位图拷贝到临时DC中,源DC已经载入位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] BitBlt(hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 设置临时DC的透明色[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SetBkColor(hImageDC, crTransparent);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 生成透明区域为白色,其它区域为黑色的临时掩码DC的掩码位图
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 位图来自临时DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] BitBlt(hMaskDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], nWidthDest, nHeightDest, hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCCOPY);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 生成透明区域为黑色,其它区域保持不变的位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SetBkColor(hImageDC, RGB([/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SetTextColor(hImageDC, RGB([/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] BitBlt(hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], nWidthDest, nHeightDest, hMaskDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCAND);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 透明部分保持屏幕不变,其它部分变成黑色[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SetBkColor(hdcDest,RGB([/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SetTextColor(hdcDest,RGB([/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hMaskDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCAND);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] "或"运算,生成最终效果[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCPAINT);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 清理、恢复 [/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SelectObject(hImageDC, hOldImageBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteDC(hImageDC);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SelectObject(hMaskDC, hOldMaskBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteDC(hMaskDC);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteObject(hImageBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteObject(hMaskBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif[/img]}[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#008000]//[/color][color=#008000]用于没有掩码图,只有指定透明色,可以进行伸缩[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]void[/color][color=#000000] CCommon::DrawTransBitmap( HDC hdcDest, [/color][color=#008000]//[/color][color=#008000] 目标DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标X偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标Y偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nWidthDest, [/color][color=#008000]//[/color][color=#008000] 目标宽度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nHeightDest, [/color][color=#008000]//[/color][color=#008000] 目标高度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] HDC hdcSrc, [/color][color=#008000]//[/color][color=#008000] 源DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源X起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源Y起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nWidthSrc, [/color][color=#008000]//[/color][color=#008000] 源宽度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nHeightSrc, [/color][color=#008000]//[/color][color=#008000] 源高度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] COLORREF crTransparent [/color][color=#008000]//[/color][color=#008000] 透明色,COLORREF类型[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] )
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img]...[/color]...[color=#000000]{
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] HBITMAP hOldImageBMP, hImageBMP [/color][color=#000000]=[/color][color=#000000] CreateCompatibleBitmap(hdcDest, nWidthDest, nHeightDest); [/color][color=#008000]//[/color][color=#008000] 创建兼容位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] HBITMAP hOldMaskBMP, hMaskBMP [/color][color=#000000]=[/color][color=#000000] CreateBitmap(nWidthDest, nHeightDest, [/color][color=#000000]1[/color][color=#000000], [/color][color=#000000]1[/color][color=#000000], NULL); [/color][color=#008000]//[/color][color=#008000] 创建单色掩码位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] HDC hImageDC [/color][color=#000000]=[/color][color=#000000] CreateCompatibleDC(hdcDest);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] HDC hMaskDC [/color][color=#000000]=[/color][color=#000000] CreateCompatibleDC(hdcDest);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] hOldImageBMP [/color][color=#000000]=[/color][color=#000000] (HBITMAP)SelectObject(hImageDC, hImageBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] hOldMaskBMP [/color][color=#000000]=[/color][color=#000000] (HBITMAP)SelectObject(hMaskDC, hMaskBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 将源DC中的位图拷贝到临时DC中[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color]
[color=#0000ff]if[/color][color=#000000] (nWidthDest [/color][color=#000000]==[/color][color=#000000] nWidthSrc [/color][color=#000000]&&[/color][color=#000000] nHeightDest [/color][color=#000000]==[/color][color=#000000] nHeightSrc)
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif[/img] ...[/color]...[color=#000000]{
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] BitBlt(hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif[/img] }[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#0000ff]else[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif[/img] ...[/color]...[color=#000000]{
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] StretchBlt(hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], nWidthDest, nHeightDest,
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif[/img] }[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 设置透明色[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SetBkColor(hImageDC, crTransparent);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 生成透明区域为白色,其它区域为黑色的掩码位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] BitBlt(hMaskDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], nWidthDest, nHeightDest, hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCCOPY);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 生成透明区域为黑色,其它区域保持不变的位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SetBkColor(hImageDC, RGB([/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SetTextColor(hImageDC, RGB([/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] BitBlt(hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], nWidthDest, nHeightDest, hMaskDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCAND);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 透明部分保持屏幕不变,其它部分变成黑色[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SetBkColor(hdcDest,RGB([/color][color=#000000]0xff[/color][color=#000000],[/color][color=#000000]0xff[/color][color=#000000],[/color][color=#000000]0xff[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SetTextColor(hdcDest,RGB([/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hMaskDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCAND);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] "或"运算,生成最终效果[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCPAINT);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SelectObject(hImageDC, hOldImageBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteDC(hImageDC);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SelectObject(hMaskDC, hOldMaskBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteDC(hMaskDC);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteObject(hImageBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteObject(hMaskBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif[/img]}[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/color][color=#008000]指定掩码图,和掩码图属于不同图片[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]void[/color][color=#000000] CCommon::DrawTransBitmap( HDC hdcDest, [/color][color=#008000]//[/color][color=#008000] 目标DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nXOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标X偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginDest, [/color][color=#008000]//[/color][color=#008000] 目标Y偏移[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nWidthDest, [/color][color=#008000]//[/color][color=#008000] 目标宽度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nHeightDest, [/color][color=#008000]//[/color][color=#008000] 目标高度[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] HDC hdcSrc, [/color][color=#008000]//[/color][color=#008000] 源DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] HDC hdcMask,
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img] [/color][color=#0000ff]int[/color][color=#000000] nXOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源X起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] nYOriginSrc, [/color][color=#008000]//[/color][color=#008000] 源Y起点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] COLORREF crTransparent [/color][color=#008000]//[/color][color=#008000] 透明色,COLORREF类型[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#000000] )
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img]...[/color]...[color=#000000]{
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] HBITMAP hOldImageBMP, hImageBMP [/color][color=#000000]=[/color][color=#000000] CreateCompatibleBitmap(hdcDest, nWidthDest, nHeightDest); [/color][color=#008000]//[/color][color=#008000] 创建兼容位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] HDC hImageDC [/color][color=#000000]=[/color][color=#000000] CreateCompatibleDC(hdcDest);[/color][color=#008000]//[/color][color=#008000]临时DC [/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] hOldImageBMP [/color][color=#000000]=[/color][color=#000000] (HBITMAP)SelectObject(hImageDC, hImageBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 将源DC中的位图拷贝到临时DC中,源DC已经载入位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] BitBlt(hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 设置临时DC的透明色[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SetBkColor(hImageDC, crTransparent);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 生成透明区域为黑色,其它区域保持不变的位图[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SetBkColor(hImageDC, RGB([/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SetTextColor(hImageDC, RGB([/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] BitBlt(hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], nWidthDest, nHeightDest, hdcMask, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCAND);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 透明部分保持屏幕不变,其它部分变成黑色[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SetBkColor(hdcDest,RGB([/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000],[/color][color=#000000]255[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SetTextColor(hdcDest,RGB([/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000]));
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hdcMask, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCAND);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] "或"运算,生成最终效果[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hImageDC, [/color][color=#000000]0[/color][color=#000000], [/color][color=#000000]0[/color][color=#000000], SRCPAINT);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 清理、恢复 [/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] SelectObject(hImageDC, hOldImageBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteDC(hImageDC);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteObject(hImageBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif[/img]}[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/color][color=#008000]指定图片和掩码图同属于一张图片[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color][color=#0000ff]void[/color][color=#000000] CCommon::DrawTransBitmap(HDC hDC, [/color][color=#0000ff]int[/color][color=#000000] nPosX, [/color][color=#0000ff]int[/color][color=#000000] nPosY, [/color][color=#0000ff]int[/color][color=#000000] nCX, [/color][color=#0000ff]int[/color][color=#000000] nCY, HBITMAP hObj)
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img]...[/color]...[color=#000000]{
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] HDC hMemDC[/color][color=#000000]=[/color][color=#000000] CreateCompatibleDC(hDC);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] HBITMAP hOldBMP[/color][color=#000000]=[/color][color=#000000](HBITMAP)::SelectObject(hMemDC,hObj);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] BitBlt(hDC,nPosX,nPosY,nCX,nCY, hMemDC,nCX,[/color][color=#000000]0[/color][color=#000000],SRCAND);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] BitBlt(hDC,nPosX,nPosY,nCX,nCY, hMemDC,[/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000],SRCPAINT);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] SelectObject(hMemDC,hOldBMP);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] DeleteDC(hMemDC);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif[/img]}[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img]HRGN CCommon::CreateBitmapRgn([/color][color=#0000ff]int[/color][color=#000000] nWidth,[/color][color=#0000ff]int[/color][color=#000000] nHeight,HBITMAP hbmp, COLORREF TransColor)
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img]...[/color]...[color=#000000]{
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] HDC hmemDC;
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000]创建与传入DC兼容的临时DC[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] hmemDC [/color][color=#000000]=[/color][color=#000000] ::CreateCompatibleDC(NULL);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] HBITMAP hOldBmp [/color][color=#000000]=[/color][color=#000000] (HBITMAP)::SelectObject(hmemDC,hbmp);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000]创建总的窗体区域,初始region为0[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] HRGN hrgn;
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] hrgn [/color][color=#000000]=[/color][color=#000000] ::CreateRectRgn([/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000],[/color][color=#000000]0[/color][color=#000000]);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#0000ff]int[/color][color=#000000] y;
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#0000ff]for[/color][color=#000000](y[/color][color=#000000]=[/color][color=#000000]0[/color][color=#000000];y[/color][color=#000000]<[/color][color=#000000]nHeight ;y[/color][color=#000000]++[/color][color=#000000])
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif[/img] ...[/color]...[color=#000000]{
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] HRGN rgnTemp; [/color][color=#008000]//[/color][color=#008000]保存临时region[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#0000ff]int[/color][color=#000000] iX [/color][color=#000000]=[/color]
[color=#000000]0[/color][color=#000000];
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#0000ff]do[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif[/img][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif[/img] ...[/color]...[color=#000000]{
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000]跳过透明色找到下一个非透明色的点.[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color]
[color=#0000ff]while[/color][color=#000000] (iX [/color][color=#000000]<[/color][color=#000000] nWidth [/color][color=#000000]&&[/color][color=#000000] ::GetPixel(hmemDC,iX, y) [/color][color=#000000]==[/color][color=#000000] TransColor)
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] iX[/color][color=#000000]++[/color][color=#000000];
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000]记住这个起始点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color]
[color=#0000ff]int[/color][color=#000000] iLeftX [/color][color=#000000]=[/color][color=#000000] iX;
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000]寻找下个透明色的点[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color]
[color=#0000ff]while[/color][color=#000000] (iX [/color][color=#000000]<[/color][color=#000000] nWidth [/color][color=#000000]&&[/color][color=#000000] ::GetPixel(hmemDC,iX, y) [/color][color=#000000]!=[/color][color=#000000] TransColor)
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#000000]++[/color][color=#000000]iX;
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000]创建一个包含起点与重点间高为1像素的临时“region”[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] rgnTemp[/color][color=#000000]=[/color][color=#000000]::CreateRectRgn(iLeftX, y, iX, y[/color][color=#000000]+[/color][color=#000000]1[/color][color=#000000]);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000]合并到主"region".[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] CombineRgn( hrgn,hrgn,rgnTemp, RGN_OR);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#008000]//[/color][color=#008000]删除临时"region",否则下次创建时和出错[/color][color=#008000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/color][color=#000000] ::DeleteObject(rgnTemp);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif[/img] }[/color][color=#0000ff]while[/color][color=#000000](iX [/color][color=#000000]<[/color][color=#000000]nWidth );
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] iX [/color][color=#000000]=[/color]
[color=#000000]0[/color][color=#000000];
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif[/img] }[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] ::SelectObject(hmemDC,hOldBmp);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] ::DeleteDC(hmemDC);
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img] [/color][color=#0000ff]return[/color][color=#000000] hrgn;
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif[/img]}[/color][color=#000000]
[img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/color]