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

    • 函数:
      • The AlphaBlend function displays bitmaps that have transparent or semitransparent pixels.
      • BOOL AlphaBlend(
          HDC hdcDest,                 // handle to destination DC
          int nXOriginDest,            // x-coord of upper-left corner
          int nYOriginDest,            // y-coord of upper-left corner
          int nWidthDest,              // destination width
          int nHeightDest,             // destination height
          HDC hdcSrc,                  // handle to source DC
          int nXOriginSrc,             // x-coord of upper-left corner
          int nYOriginSrc,             // y-coord of upper-left corner
          int nWidthSrc,               // source width
          int nHeightSrc,              // source height
          BLENDFUNCTION blendFunction  // alpha-blending function
        );
        
    • 代码:
      • 	static HBITMAP hBmp1;
        	static HBITMAP hBmp2;
        	static int cxBmp;
        	static int cyBmp;
        
        	case WM_CREATE:
        		{
        			//load bmp
        			hBmp1 = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP1));
        			if (hBmp1 == NULL)
        			{
        				MessageBox(hWnd,L"failed to load bmp1!",NULL,MB_OK);
        			}
        			hBmp2 = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP2));
        			if (hBmp2 == NULL)
        			{
        				MessageBox(hWnd,L"failed to load bmp2!",NULL,MB_OK);
        			}
        			//get bmp info
        			BITMAP bmpInfo;
        			GetObject(hBmp1,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 = cxBmp + 2 * GetSystemMetrics(SM_CXFRAME);
        			int cyWnd = cyBmp + 2 * GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CYCAPTION);
        			MoveWindow(hWnd,(cxScr-cxWnd)/2,(cyScr-cyWnd)/2,cxWnd,cyWnd,TRUE);
        		}
        		break;
        
        	case WM_PAINT:
        		hdc = BeginPaint(hWnd, &ps);
        		{
        			//disp bmp
        			HDC hMemDC1 = CreateCompatibleDC(hdc);
        			HDC hMemDC2 = CreateCompatibleDC(hdc);
        			SelectObject(hMemDC1, hBmp1);
        			SelectObject(hMemDC2, hBmp2);
        			
        			BLENDFUNCTION bf;
        			bf.BlendOp = AC_SRC_OVER;
        			bf.BlendFlags = 0;
        			bf.SourceConstantAlpha = 128;//alpha transparency value
        			bf.AlphaFormat = 0;
        			AlphaBlend(hMemDC1,0,0,cxBmp,cyBmp,hMemDC2,0,0,cxBmp,cyBmp,bf);
        
        			BitBlt(hdc, 0, 0,cxBmp, cyBmp, hMemDC1, 0, 0, SRCCOPY);			
        
        			DeleteDC(hMemDC1);
        			DeleteDC(hMemDC2);
        
        		}
        		EndPaint(hWnd, &ps);
        		break;
        
    • 结果:
  • 相关阅读:
    使用 Traefik 代理 UDP 服务
    KubeOperator界面,集群详情中的存储,存储提供商
    centos7使用yum方式安装node_exporter
    Traefik2.3.x 使用大全(更新版)
    jumpserver堡垒机版本升级,从2.14.2升级到2.16.3
    Traefik 2.0 实现灰度发布
    matplotlib 中文问题
    数据采集实战(五) 当当网童书排名
    雅可比行列式迭代及优化(golang版)
    mysql8.x docker 远程访问配置
  • 原文地址:https://www.cnblogs.com/dahai/p/2103030.html
Copyright © 2011-2022 走看看