/// <summary>将指定区域分块 /// </summary> /// <param name="nSize_Block_R">分块行高</param> /// <param name="nSize_Block_C">分块列宽</param> /// <param name="nMax">行最大块数</param> /// <param name="bBase_Zero">是否从0,0开始计算</param> /// <returns></returns> public virtual List <Rectangle> Block(int nSize_Block_R, int nSize_Block_C, int nMax, bool bBase_Zero = false) { List <Rectangle> rectBlocks = new List <System.DrawingCore.Rectangle>(); Rectangle rectBlock; Rectangle rectArea = new System.DrawingCore.Rectangle(0, 0, m_Rect.Width, m_Rect.Height); int nRows, nCols, nCols_Block, nLeft, nTop; int nBase_X = 0, nBase_Y = 0; try { //计算行列块数 nCols_Block = nSize_Block_C * nMax; nRows = (int)Math.Ceiling(1.0 * m_Rect.Height / nSize_Block_R); nCols = (int)Math.Ceiling(1.0 * m_Rect.Width / nCols_Block); //基点调整 if (bBase_Zero == false) { nBase_X = this.p_Left; nBase_Y = this.p_Top; rectArea = m_Rect; } //分区行分段 (均逐分区行扫描) for (int i = 0; i < nRows; i++) { for (int j = 0; j < nCols; j++) { //示例分区 nLeft = nBase_X + j * nCols_Block; nTop = nBase_Y + i * nSize_Block_R; rectBlock = new System.DrawingCore.Rectangle(nLeft, nTop, nCols_Block, nSize_Block_R); //与原区叠加 rectBlock.Intersect(rectArea); rectBlocks.Add(rectBlock); } } return(rectBlocks); } catch { throw; } }
/// <summary> /// Intersect Method /// </summary> /// /// <remarks> /// Replaces the Rectangle with the intersection of itself /// and another Rectangle. /// </remarks> public void Intersect(Rectangle rect) { this = Rectangle.Intersect(this, rect); }