EasyPlayer播放器系列项目可以说是目前市面中一款非常开放的播放器项目,用户可以根据自己的需求调用接口或者进行开发,实用性强,稳定性也足够优越。
上一篇我们讲了《EasyPlayer-RTMP定制窗体开发》,对于其中OSD的功能仍然有可以继续完善的点,比如用户希望可以自己定义OSD内容的颜色。
默认的是红色字体,如下图:
接下来介绍下OSD实现的过程,就可以方便大家自己来修改叠加内容的位置、颜色等信息。
/// <summary> /// 附加信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddScreenFontTSMenuItem_Click(object sender, EventArgs e) { int ret = -1; var rect = new Rect { X = 10, Y = 10, Width = panel1.Width, Height = panel1.Height }; var panelSize = this.panel1.ClientSize; PlayerSdk.EASY_PALYER_OSD fontInfo = new PlayerSdk.EASY_PALYER_OSD { alpha = 255, size = 35, color = (uint)ToArgb(Color.Red), shadowcolor = (uint)ToArgb(Color.Black), stOSD = XMLOperate.BYCSB, rect = new PlayerSdk.tagRECT { left = (int)rect.X, top = (int)rect.Y, right = (int)rect.Width, bottom = (int)rect.Height } }; var checkState = (sender as ToolStripMenuItem).CheckState; if (checkState == CheckState.Unchecked) { ret = PlayerSdk.EasyPlayer_ShowOSD(channelID, fontInfo); (sender as ToolStripMenuItem).CheckState = CheckState.Checked; } if (checkState == CheckState.Checked) { ret = PlayerSdk.EasyPlayer_ShowOSD(channelID, fontInfo, false); (sender as ToolStripMenuItem).CheckState = CheckState.Unchecked; } } OSD有定义一个结构体如下:color可以修改颜色,stOSD传参是需要显示的内容,tagRECT也是一个结构体,可以自己定义显示位置。 /// <summary> /// OSD 信息集合 /// </summary> [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct EASY_PALYER_OSD { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] public string stOSD; public uint alpha; //0-255 public uint color; //RGB(0xf9,0xf9,0xf9) public uint shadowcolor; //RGB(0x4d,0x4d,0x4d) 全为0背景透明 public tagRECT rect; //OSD基于图像右上角显示区域 public int size; //just D3D Support } /// <summary> /// 像素信息 /// </summary> [StructLayoutAttribute(LayoutKind.Sequential)] public struct tagRECT { public int left; public int top; public int right; public int bottom; }
我们将color赋值为 (uint)ToArgb(Color.Yellow),如下效果:
其他颜色也可以通过此种方式进行赋值。