zoukankan      html  css  js  c++  java
  • Transparent 之 TransparentBlt

    • 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:
    • TransparentBlt:
  • 相关阅读:
    H5小游戏的坑点小结
    禁用iOS的UIView长按默认操作
    chrome诡异的Provisional headers are shown
    手机浏览器音频内核的坑
    libuv在cocos2d-x中的使用
    windows下codelite的使用
    windows下clang的安装与使用
    ztree选父不选子选子不选父
    <c:forEach>判断第一条或最后一条记录
    iframe高度自适应的方法
  • 原文地址:https://www.cnblogs.com/dahai/p/2101645.html
Copyright © 2011-2022 走看看