视频监控分屏简单例子

  第一次入住园子,第一次写博客好紧张:)

  最近在做关于一个视频监控的项目涉及到分屏显示功能。下载了几个网上的例子看下都不是太符合要求,所以只能自己动手改造一下

首先定义好要分屏样式的数组:

 //X,Y,row(第几行) ,col(第几列)
        /// <summary>
        /// * X Y row col
        /// </summary>
        public int[, , ,] split1x1 = new int[,,,] { { { { 0, 0, 1, 1 } } } };
        /// <summary>
        /// **
        /// **
        /// </summary>
        public int[, , ,] split2x2 = new int[,,,] 
        { 
        {{{ 0, 0,1,1 }}},{{{1,0,1,1}}},
        {{{ 0, 1,1,1 }}},{{{1,1,1,1}}}
        };
        /// <summary>
        ///   *
        ///   * 
        /// ***
        /// </summary>
        public int[, , ,] split1x5 = new int[,,,] 
        {
         {{{ 0, 0,2,2}}},{{{ 2, 0,1,1}}},
         {{{ 2, 1,1,1}}},
         {{{ 0, 2,1,1}}},{{{ 1, 2,1,1}}},{{{ 2, 2,1,1}}}
        };
        /// <summary>
        ///   *
        ///   *
        ///   *
        ///****
        /// </summary>
        public  int[, , ,] split1x7 = new int[,,,]
        { 
         {{{ 0, 0,3,3 }}},{{{3,0,1,1}}},
        {{{3,1,1,1}}},
        {{{3,2,1,1}}},
         {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}},{{{3,3,1,1}}}
        };

        /// <summary>
        /// ***
        /// ***
        /// ***
        /// </summary>
        public  int[, , ,] split3x3 = new int[,,,]
        { 
            {{{ 0, 0,1,1 }}},{{{1,0,1,1}}},{{{ 2, 0,1,1 }}},
            {{{ 0, 1,1,1 }}},{{{1,1,1,1}}},{{{ 2, 1,1,1 }}},
            {{{ 0, 2,1,1 }}},{{{1,2,1,1}}},{{{ 2, 2,1,1 }}},
            {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}}
        };
        /// <summary>
        /// *  *
        /// *  *
        /// ****
        /// ****
        /// </summary>
        public int[, , ,] split2x8 = new int[,,,] 
        { 
        {{{ 0, 0,1,1 }}},{{{1,0,2,2}}},{{{3,0,1,1}}},
        {{{ 0, 1,1,1 }}},{{{3,1,1,1}}},
        {{{ 0, 2,1,1 }}},{{{1,2,1,1}}},{{{ 2, 2,1,1 }}},{{{3,2,1,1}}},
        {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}},{{{3,3,1,1}}}
        };

        /// <summary>
        /// ****
        /// *  *
        /// *  *
        /// ****
        /// </summary>
        public int[, , ,] split1x8 = new int[,,,] 
        { 
        {{{ 0, 0,1,1 }}},{{{1,0,1,1}}},{{{ 2, 0,1,1 }}},{{{3,0,1,1}}},
         {{{ 0, 1,1,1 }}},{{{1,1,2,2}}},{{{3,1,1,1}}},
        {{{ 0, 2,1,1 }}},{{{3,2,1,1}}},
        {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}},{{{3,3,1,1}}}
        };
        /// <summary>
        /// ****
        /// ****
        /// ****
        /// ****
        /// </summary>
        public int[, , ,] split4x4 = new int[,,,]
        {
            {{{ 0, 0,1,1 }}},{{{1,0,1,1}}},{{{ 2, 0,1,1 }}},{{{3,0,1,1}}},
            {{{ 0, 1,1,1 }}},{{{1,1,1,1}}},{{{ 2, 1,1,1 }}},{{{3,1,1,1}}},
            {{{ 0, 2,1,1 }}},{{{1,2,1,1}}},{{{ 2, 2,1,1 }}},{{{3,2,1,1}}},
            {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}},{{{3,3,1,1}}}
        
        };

最后分屏的代码也很简单

/// <summary>
        /// 显示分屏
        /// </summary>
        /// <param name="row"></param>
        /// <param name="value">显示样式</param>
        public void ShowControl(int row, int[, , ,] value)
        {
            //this.row = row;
            //array = value;
            this.Controls.Clear();
            int itemWidth = this.Width / row;
            int itemHeight = this.Height / row;
            // int length = value.Length == 4 ? value.Length : value.Length / 2;
            for (int i = 0; i < value.Length / 4; i++)
            {
                PlayItem item = new PlayItem() { Width = itemWidth * value[i, 0, 0, 2], Height = itemHeight * value[i, 0, 0, 3] };

                item.Location = new Point(value[i, 0, 0, 0] * itemWidth, value[i, 0, 0, 1] * itemHeight);
                this.Controls.Add(item);
            }
        }

再来几张图片吧

本来想把示例上传上来的但找不到地方:(

原文地址:https://www.cnblogs.com/Noproblem/p/3122982.html