視頻監控分屏簡單例子


  第一次入住園子,第一次寫博客好緊張:)

  最近在做關於一個視頻監控的項目涉及到分屏顯示功能。下載了幾個網上的例子看下都不是太符合要求,所以只能自己動手改造一下

首先定義好要分屏樣式的數組:

 //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);
            }
        }

再來幾張圖片吧

本來想把示例上傳上來的但找不到地方:(


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM