Transparent 之 TransparentBlt

Transparent 之 TransparentBltTransparentB 函数 BOOLTranspar HDChdcDest handletodest x coordofdesti leftcornerin y coord

  • TransparentBlt函数
    BOOL TransparentBlt( HDC hdcDest, // handle to destination DC int nXOriginDest, // x-coord of destination upper-left corner int nYOriginDest, // y-coord of destination upper-left corner int nWidthDest, // width of destination rectangle int hHeightDest, // height of destination rectangle HDC hdcSrc, // handle to source DC int nXOriginSrc, // x-coord of source upper-left corner int nYOriginSrc, // y-coord of source upper-left corner int nWidthSrc, // width of source rectangle int nHeightSrc, // height of source rectangle UINT crTransparent // color to make transparent 

  • 示例
    static HBITMAP hBmp; static int cxBmp; static int cyBmp; case WM_CREATE: { //load bmp and get bmp info hBmp = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BALL)); BITMAP bmpInfo; GetObject(hBmp,sizeof(BITMAP),&bmpInfo); cxBmp = bmpInfo.bmWidth; cyBmp = bmpInfo.bmHeight; //put window int the middle screen int cxScr = GetSystemMetrics(SM_CXSCREEN); int cyScr = GetSystemMetrics(SM_CYSCREEN); int cxWnd = 400; int cyWnd = 400; MoveWindow(hWnd,(cxScr-cxWnd)/2,(cyScr-cyWnd)/2,cxWnd,cyWnd,TRUE); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); { //bg color RECT rcWnd; HBRUSH hBrush; GetClientRect(hWnd,&rcWnd); hBrush = CreateSolidBrush(RGB(0,128,128)); FillRect(hdc,&rcWnd,hBrush); DeleteObject(hBrush); //disp bmp HDC hMemDC = CreateCompatibleDC(hdc); HBITMAP hOldBmp = (HBITMAP)SelectObject(hMemDC,hBmp); //BitBlt(hdc,73,58,cxBmp,cyBmp,hMemDC,0,0,SRCCOPY); TransparentBlt(hdc,73,58,cxBmp,cyBmp,hMemDC,0,0,cxBmp,cyBmp,RGB(255,255,255)); SelectObject(hMemDC,hOldBmp); DeleteDC(hMemDC); } EndPaint(hWnd, &ps); break; 

  • 结果
  • BitBlt:
  • 2011070910235844.jpg
  • TransparentBlt:
  • 2011070910242377.jpg

转载于:https://www.cnblogs.com/dahai/archive/2011/07/09/2101645.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/217424.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 上午9:36
下一篇 2026年3月18日 上午9:36


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号