对图像进行分切成若干份小图像

 1         /// <summary>
 2         /// 图像裁切 将一张图像裁切成若干个等大的小图像
 3         /// 先计算出分切小图像的尺寸,创建Rectangle来复制,复制一次产生一个小图像
 4         /// </summary>
 5         /// <param name="bmpRes"></param>
 6         /// <param name="rowNum"></param>
 7         /// <param name="colNum"></param>
 8         /// <returns></returns>
 9         public Bitmap[] SpliteImage(Bitmap bmpRes, int rowNum,int colNum)
10         {           
11             Bitmap[] bmpaClipBmpArr = new Bitmap[rowNum * colNum];
12             for (int row = 0; row < rowNum; row++)
13             {
14                 for (int col = 0; col < colNum; col++)
15                 {
16                     int nClipWidth = bmpRes.Width / colNum;
17                     int nClipHight = bmpRes.Height / rowNum;
18                     
19                     Rectangle rClipRect = new Rectangle(
20                         nClipWidth * col,
21                         nClipHight * row,
22                         nClipWidth,
23                         nClipHight );
24 
25                     int index = col + row * colNum;
26                     bmpaClipBmpArr[index] = bmpRes.Clone(rClipRect, bmpRes.PixelFormat);
27                 }
28             }
29             return bmpaClipBmpArr;
30         }

猜你喜欢

转载自www.cnblogs.com/BKYZFSN/p/10913835.html