zoukankan      html  css  js  c++  java
  • H264解码之ddraw画矩形框和画字(滤镜)

    void display::showOSD(HRESULT ddrval, int in_width, int in_height, FaceStructInfo *pUser, int nCount)
    {
    	HDC hDC = NULL;
    	ddrval = m_pOsdSurface->GetDC(&hDC);
    
    	if ((ddrval == DD_OK) && (hDC != NULL))
    	{
    		LOGFONT lf; //定义字体结构
    		lf.lfWeight = 100; //字体磅数=10
    		lf.lfHeight = 15; //字体高度(旋转后的字体宽度)=56
    		lf.lfWidth = 5; //字体宽度(旋转后的字体高度)=20
    		lf.lfUnderline = FALSE; //无下划线
    		lf.lfStrikeOut = FALSE; //无删除线
    		lf.lfItalic = FALSE; //非斜体
    		lf.lfEscapement = 0; //字体显示角度=270°
    		lf.lfCharSet = GB2312_CHARSET; //使用缺省字符集
    		strcpy(lf.lfFaceName, "华文隶书"); //字体名=@system
    
    		HFONT myLogFont = CreateFontIndirect(&lf);
    		HGDIOBJ pOldFont  = SelectObject(hDC, myLogFont);//选入设备描述表
    
    		//叠加文字
    		SetBkMode(hDC, TRANSPARENT);
    
    		std::string strColor = "#FF0000";
    		DWORD r, g, b;
    		sscanf(strColor.c_str(), "#%2X%2X%2X", &r, &g, &b);
    		COLORREF rgb = RGB(r, g, b);
    		SetTextColor(hDC, rgb);
    
    		
    		strColor = "#0000CD";
    		sscanf(strColor.c_str(), "#%2X%2X%2X", &r, &g, &b);
    		COLORREF rgbRect = RGB(r, g, b);
    
    		HBRUSH hbrush;
    		hbrush = CreateSolidBrush(rgbRect);
    
    // 		HDC memdc = CreateCompatibleDC(hDC);
    // 		BITMAP bmp;
    // 		HBITMAP holdbmp, hbmp = (HBITMAP)LoadImage(0, "E:\111.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    // 		holdbmp = (HBITMAP)SelectObject(memdc, hbmp);//这里把hbmp的位图选择到兼容DC memdc,之后这个兼容DC就拥有和
    // 													 //hbmp同样大小的绘图区域,注意超出位图返回的GDI输出都是无效的.
    // 		GetObject(hbmp, sizeof(BITMAP), &bmp);//这里获取位图的大小信息,事实上也是兼容DC绘图输出的范围
    
     		for (int i = 0; i < nCount; i++)
     		{
    			RECT rect;
    			GetClientRect(m_hwnd, &rect);
     			char info[128];
    			rect.left = pUser[i].face_x * rect.right / m_rctSour.right;
    			rect.top = pUser[i].face_y * rect.bottom / m_rctSour.bottom;
    			rect.right = (pUser[i].face_x+ pUser[i].face_w) * rect.right / m_rctSour.right;
    			rect.bottom = (pUser[i].face_y + pUser[i].face_h) * rect.bottom / m_rctSour.bottom;
    
    			MONITORINFO mi;
    			memset(&mi, 0, sizeof(MONITORINFO));
    			mi.cbSize = sizeof(MONITORINFO);
    			HMONITOR hmon = ::MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTONEAREST);
    			if (!hmon)
    			{
    				OutputDebugStringA("display::inputsource MonitorFromWindow error[hmon equ null]
    ");
    				return ;
    			}
    			::GetMonitorInfo(hmon, &mi);
    			rect.left -= mi.rcMonitor.left;
    			rect.right -= mi.rcMonitor.left;
    			rect.top -= mi.rcMonitor.top;
    			rect.bottom -= mi.rcMonitor.top;
    			ClientToScreen(m_hwnd, (LPPOINT)&rect.left);
    			ClientToScreen(m_hwnd, (LPPOINT)&rect.right);
    			
    			int nWidth = pUser[i].face_w * m_rctDest.right / m_rctSour.right;
    			int nX = rect.left + nWidth+5;
    			int nY = rect.top;
    
    // 			RECT rc;
    // 			rc.left = nX;
    // 			rc.top = nY;
    // 			rc.right = nX + 40;
    // 			rc.top = nY + 140;
    
    			//SetRect(&rc, 0, 0, bmp.bmWidth, bmp.bmHeight);
     			std::string strTemp = parseSex(pUser[i].usrSex);
     			_snprintf_s(info, sizeof(info), "性别:%s", strTemp.c_str());
     			TextOut(hDC, nX, nY, info, strlen(info));
     
     			strTemp = parseAge(pUser[i].userAge);
     			_snprintf_s(info, sizeof(info), "年龄:%s", strTemp.c_str());
     			TextOut(hDC, nX, nY + 20, info, strlen(info));
     
     			strTemp = parseBrow(pUser[i].userBrow);
     			_snprintf_s(info, sizeof(info), "表情:%s", strTemp.c_str());
     			TextOut(hDC, nX, nY + 40, info, strlen(info));
     
     			strTemp = parseHairstyle(pUser[i].userHairstyle);
     			_snprintf_s(info, sizeof(info), "发型:%s", strTemp.c_str());
     			TextOut(hDC, nX, nY + 60, info, strlen(info));
     
     			strTemp = parseGlasses(pUser[i].userGlasses);
     			_snprintf_s(info, sizeof(info), "眼镜:%s", strTemp.c_str());
     			TextOut(hDC, nX, nY + 80, info, strlen(info));
     
     			strTemp = parseHat(pUser[i].userHat);
     			_snprintf_s(info, sizeof(info), "帽子:%s", strTemp.c_str());
     			TextOut(hDC, nX, nY + 100, info, strlen(info));
     
     			strTemp = parseMask(pUser[i].userMask);
     			_snprintf_s(info, sizeof(info), "口罩:%s", strTemp.c_str());
     			TextOut(hDC, nX, nY + 120, info, strlen(info));
     
     			strTemp = parseRace(pUser[i].userRace);
     			_snprintf_s(info, sizeof(info), "人种:%s", strTemp.c_str());
     			TextOut(hDC, nX, nY + 140, info, strlen(info));
     
    			
     			//画空心矩形
     			FrameRect(hDC, &rect, hbrush);
    
    			rect.left -= 1;
    			rect.right -= 1;
    			rect.top -= 1;
    			rect.bottom -= 1;
    			FrameRect(hDC, &rect, hbrush);
     		}
    
    // 		SelectObject(memdc, holdbmp);//复原兼容DC数据.
    // 		DeleteDC(memdc);
    
    		SelectObject(hDC, pOldFont); //将myFont从设备环境中分离
    		DeleteObject(myLogFont); //删除myLogFont对象
    
    		DeleteObject(hbrush);
    		m_pOsdSurface->ReleaseDC(hDC);
    		m_lpddsprimary->Blt(&m_rctDest, m_pOsdSurface, &m_rctDest, DDBLT_WAIT, NULL);
    	}
    }
  • 相关阅读:
    搭建wamp环境,数据库基础知识
    练习题:选择器和选择好友
    例子:滑动效果
    TCPDump
    内存
    Cache和Buffer的区别(转载)
    经典问题回忆
    history
    DNS
    bc的用法
  • 原文地址:https://www.cnblogs.com/SunkingYang/p/11049139.html
Copyright © 2011-2022 走看看