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;
        
    • 结果:
  • 相关阅读:
    vsftpd的详细配置讲解
    ActiveMQ安装与配置
    Apache安装完之后再安装其他模块
    搭建 LAMP apache2.4 + php5.5 + mysql5.5/6 配置文件没有作用的问题
    LAMP apache2.4 + php5.5 + mysql5.5/6
    进制之间的转换
    Mac 常用属性
    关于颜色值透明度的设置
    关于TextView 的属性
    Android 关于软键盘
  • 原文地址:https://www.cnblogs.com/dahai/p/2103030.html
Copyright © 2011-2022 走看看