c# - How to crop subsection of 2D array? -
i have 2d array declared new byte[w, h]
. want crop out sub-section of array given coordinates (x1,y1)
-(x2,y2)
. what's quickest way this? there methods "slicing" 2d arrays?
you use array.copy:
int w2 = x2 - x1 + 1; int h2 = y2 - y1 + 1; byte[,] array2 = new byte[w2, h2]; (int = 0; < w2; i++) { array.copy(array1, (i+x1)*h + y1, array2, i*h2, h2); }
this might faster large arrays. 2 nested loops more readable.
Comments
Post a Comment