@ Override public void setNumberOfBands ( int numberOfBands ) { if ( numberOfBands == this . bands . length ) return ; T [ ] bands = ( T [ ] ) Array . newInstance ( type , numberOfBands ) ; int N = Math . min ( numberOfBands , this . bands . length ) ; for ( int i = 0 ; i < N ; i ++ ) { bands [ i ] = this . bands [ i ] ; } for ( int i = N ; i < bands . length ; i ++ ) { bands [ i ] = GeneralizedImageOps . createSingleBand ( type , width , height ) ; } this . bands = bands ; }
Changes the number of bands in the image . A new array is declared and individual bands are recycled if possible