C#視訊監控分屏
阿新 • • 發佈:2019-01-23
private void panel1_Paint(object sender, PaintEventArgs e)
{
SetActiveWnd(m_nCurIndex);
}
public void DrawActivePage(bool bActive)
{
Rectangle rt = new Rectangle(m_videoform[m_nCurIndex].Left, m_videoform[m_nCurIndex].Top, m_videoform[m_nCurIndex].Width, m_videoform[m_nCurIndex].Height);
if (!bActive)
{
Rectangle rtInvalidate = new Rectangle(rt.X - 1, rt.Y - 1, rt.Width + 2, rt.Height + 2);
Invalidate(rtInvalidate, true);
}
else
{
Graphics graphic = Graphics.FromHwnd(this.Handle);
Pen pen = new Pen(Color.Red, 2);
graphic.DrawRectangle(pen, rt);
}
}
private void SetColor(int nIndex)
{
/*int nBright = 0;
int nHue = 0;
int nSaturation = 0;
int nContrast = 0;*/
IntPtr lPlayHandle = m_videoform[m_nCurIndex].Handle;
if (lPlayHandle.ToInt32() <= 0)
{
return;
}
// m_videoform[nIndex].GetColor(out nBright, out nContrast, out nSaturation, out nHue);
}
public void SetActiveWnd(int nIndex)
{
if (-1 != m_nCurIndex && m_nCurIndex != nIndex)
{
DrawActivePage(false);
}
if (m_nCurIndex != nIndex)
{
m_nCurIndex = nIndex;
}
DrawActivePage(true);
SetColor(m_nCurIndex);
}
public void ArrayWindow(int iNumber)
{
m_nTotalWnd = iNumber;
int iWidth, iHeight;
int nStartLeft = this.panel1.Left;//視訊顯示的靠左位置
int nStartTop = this.panel1.Top;//視訊顯示的靠上位置
int nFullWidth = this.panel1.Width;//視訊總寬
int nFullHeight = this.panel1.Height;//視訊總高
iWidth = nFullWidth-6;
iHeight = nFullHeight-6;
int i = 0;
for (i = 0; i < 32; i++) //MAXWNDNUM ==32
{
m_videoform[i].Hide();
}
int nNull = 3;
switch (iNumber)
{
case 1:
m_videoform[0].SetBounds(nStartLeft, nStartTop, iWidth, iHeight);
m_videoform[0].Show();
break;
case 4:
for (i = 0; i < 2; i++)
{
m_videoform[i].SetBounds(nStartLeft + i * (iWidth / 2) + i * nNull, nStartTop, (iWidth / 2), iHeight / 2);
m_videoform[i].Show();
}
for (i = 2; i < 4; i++)
{
m_videoform[i].SetBounds(nStartLeft + (i - 2) * (iWidth / 2) + (i - 2) * nNull, nStartTop + iHeight / 2 + nNull, (iWidth / 2), iHeight / 2);
m_videoform[i].Show();
}
break;
case 9:
for (i = 0; i < 3; i++)
{
m_videoform[i].SetBounds(nStartLeft + i * (iWidth / 3) + i * nNull,nStartTop, (iWidth / 3), iHeight / 3);
m_videoform[i].Show();
}
for (i = 3; i < 6; i++)
{
m_videoform[i].SetBounds(nStartLeft + (i - 3) * (iWidth / 3) + (i - 3) * nNull, nStartTop + iHeight / 3 + nNull, (iWidth / 3), iHeight / 3);
m_videoform[i].Show();
}
for (i = 6; i < 9; i++)
{
m_videoform[i].SetBounds(nStartLeft + (i - 6) * (iWidth / 3) + (i - 6) * nNull, nStartTop + 2 * iHeight / 3 + 2 * nNull, (iWidth / 3), iHeight / 3);
m_videoform[i].Show();
}
break;
case 16:
for (i = 0; i < 4; i++)
{
m_videoform[i].SetBounds(nStartLeft + i * (iWidth / 4) + (i) * nNull, nStartTop, (iWidth / 4), iHeight / 4);
m_videoform[i].Show();
}
for (i = 4; i < 8; i++)
{
m_videoform[i].SetBounds(nStartLeft + (i - 4) * (iWidth / 4) + (i - 4) * nNull, nStartTop + iHeight / 4 + nNull, (iWidth / 4), iHeight / 4);
m_videoform[i].Show();
}
for (i = 8; i < 12; i++)
{
m_videoform[i].SetBounds(nStartLeft + (i - 8) * (iWidth / 4) + (i - 8) * nNull, nStartTop + iHeight / 2 + 2 * nNull, (iWidth / 4), iHeight / 4);
m_videoform[i].Show();
}
for (i = 12; i < 16; i++)
{
m_videoform[i].SetBounds(nStartLeft + (i - 12) * (iWidth / 4) + (i - 12) * nNull, nStartTop + 3 * iHeight / 4 + 3 * nNull, (iWidth / 4), iHeight / 4);
m_videoform[i].Show();
}
break;
default:
break;
}
}
private void g_displaySplitcomboBox_SelectedIndexChanged(object sender, EventArgs e)
{
int nWndNum = 1;
if (g_displaySplitcomboBox.SelectedIndex == 0)
{
nWndNum = 1;
}
else if (g_displaySplitcomboBox.SelectedIndex == 1)
{
nWndNum = 4;
}
else if (g_displaySplitcomboBox.SelectedIndex == 2)
{
nWndNum = 9;
}
else if (g_displaySplitcomboBox.SelectedIndex == 3)
{
nWndNum = 16;
}
ArrayWindow(nWndNum);
}
視訊監控分屏其實比較簡單,比方我要做最大16個畫面,那麼做一個視訊類繼承自UserControl,為了方便管理16個畫面,做了一個panel用於放置畫面。至於視訊怎麼播放,獲取m_videoform[0].Handle的控制代碼
IntPtr render_wnd = m_videoform[0].Handle;
public VideoForm[] m_videoform = new VideoForm[16];
在主函式先初始化。
for (int i = 0; i < 16; i++)
{
m_videoform[i] = new VideoForm();
this.Controls.Add(this.m_videoform[i]);
m_videoform[i].SetWndIndex(i);
}
public partial class VideoForm : UserControl { int m_nIndex; //index public int m_iPlayhandle; //play handle public void SetWndIndex(int nIndex) { m_nIndex = nIndex; } public VideoForm() { InitializeComponent(); } private void VideoForm_Click(object sender, EventArgs e) { GMApplicationMain clientdemo = (GMApplicationMain)this.Parent; clientdemo.SetActiveWnd(m_nIndex); clientdemo.g_displaySplitcomboBox.Focus(); } }