public static WritableRaster createPackedRaster(int dataType,int w,int h,int bands,int bitsPerBand,Point location){
  DataBuffer d;
  if (bands <= 0) {
    throw new IllegalArgumentException("Number of bands (" + bands + ") must be greater than 0");
  }
  if (bitsPerBand <= 0) {
    throw new IllegalArgumentException("Bits per band (" + bitsPerBand + ") must be greater than 0");
  }
  if (bands != 1) {
    int[] masks=new int[bands];
    int mask=(1 << bitsPerBand) - 1;
    int shift=(bands - 1) * bitsPerBand;
    if (shift + bitsPerBand > DataBuffer.getDataTypeSize(dataType)) {
      throw new IllegalArgumentException("bitsPerBand(" + bitsPerBand + ") * bands is "+ " greater than data type "+ "size.");
    }
switch (dataType) {
case DataBuffer.TYPE_BYTE:
case DataBuffer.TYPE_USHORT:
case DataBuffer.TYPE_INT:
      break;
default :
    throw new IllegalArgumentException("Unsupported data type " + dataType);
}
for (int i=0; i < bands; i++) {
  masks[i]=mask << shift;
  shift=shift - bitsPerBand;
}
return createPackedRaster(dataType,w,h,masks,location);
}
 else {
double fw=w;
switch (dataType) {
case DataBuffer.TYPE_BYTE:
  d=new DataBufferByte((int)(Math.ceil(fw / (8 / bitsPerBand))) * h);
break;
case DataBuffer.TYPE_USHORT:
d=new DataBufferUShort((int)(Math.ceil(fw / (16 / bitsPerBand))) * h);
break;
case DataBuffer.TYPE_INT:
d=new DataBufferInt((int)(Math.ceil(fw / (32 / bitsPerBand))) * h);
break;
default :
throw new IllegalArgumentException("Unsupported data type " + dataType);
}
return createPackedRaster(d,w,h,bitsPerBand,location);
}
}

public static WritableRaster createPackedRaster ( int dataType , int w , int h , int bands , int bitsPerBand , Point location ) { DataBuffer d ; if ( bands <= 0 ) { throw new IllegalArgumentException ( "Number of bands (" + bands + ") must be greater than 0" ) ; } if ( bitsPerBand <= 0 ) { throw new IllegalArgumentException ( "Bits per band (" + bitsPerBand + ") must be greater than 0" ) ; } if ( bands != 1 ) { int [ ] masks = new int [ bands ] ; int mask = ( 1 << bitsPerBand ) - 1 ; int shift = ( bands - 1 ) * bitsPerBand ; if ( shift + bitsPerBand > DataBuffer . getDataTypeSize ( dataType ) ) { throw new IllegalArgumentException ( "bitsPerBand(" + bitsPerBand + ") * bands is " + " greater than data type " + "size." ) ; } switch ( dataType ) { case DataBuffer . TYPE_BYTE : case DataBuffer . TYPE_USHORT : case DataBuffer . TYPE_INT : break ; default : throw new IllegalArgumentException ( "Unsupported data type " + dataType ) ; } for ( int i = 0 ; i < bands ; i ++ ) { masks [ i ] = mask << shift ; shift = shift - bitsPerBand ; } return createPackedRaster ( dataType , w , h , masks , location ) ; } else { double fw = w ; switch ( dataType ) { case DataBuffer . TYPE_BYTE : d = new DataBufferByte ( ( int ) ( Math . ceil ( fw / ( 8 / bitsPerBand ) ) ) * h ) ; break ; case DataBuffer . TYPE_USHORT : d = new DataBufferUShort ( ( int ) ( Math . ceil ( fw / ( 16 / bitsPerBand ) ) ) * h ) ; break ; case DataBuffer . TYPE_INT : d = new DataBufferInt ( ( int ) ( Math . ceil ( fw / ( 32 / bitsPerBand ) ) ) * h ) ; break ; default : throw new IllegalArgumentException ( "Unsupported data type " + dataType ) ; } return createPackedRaster ( d , w , h , bitsPerBand , location ) ; } }
creates a raster based on a packed samplemodel with the specified data type , width , height , number of bands , and bits per band . if the number of bands is one , the samplemodel will be a multipixelpackedsamplemodel . < p > if the number of bands is more than one , the samplemodel will be a singlepixelpackedsamplemodel , with each band having bitsperband bits . in either case , the requirements on datatype and bitsperband imposed by the corresponding samplemodel must be met . < p > the upper left corner of the raster is given by the location argument . if location is null , ( 0 , 0 ) will be used . the datatype parameter should be one of the enumerated values defined in the databuffer class . < p > the only datatypes supported currently are type_byte , type_ushort , and type_int .
