public static WritableRaster createWritableRaster( int width, int height, Class< ? > dataClass, SampleModel sampleModel,
            Object value ) {
        int dataType = DataBuffer.TYPE_DOUBLE;
        if (dataClass != null) {
            if (dataClass.isAssignableFrom(Integer.class)) {
                dataType = DataBuffer.TYPE_INT;
            } else if (dataClass.isAssignableFrom(Float.class)) {
                dataType = DataBuffer.TYPE_FLOAT;
            } else if (dataClass.isAssignableFrom(Byte.class)) {
                dataType = DataBuffer.TYPE_BYTE;
            } else if (dataClass.isAssignableFrom(Short.class)) {
                dataType = DataBuffer.TYPE_SHORT;
            }
        }

        if (!doesOverFlow(width, height)) {
            if (sampleModel == null) {
                sampleModel = new ComponentSampleModel(dataType, width, height, 1, width, new int[]{0});
            }

            WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
            if (value != null) {
                // autobox only once
                if (value instanceof Double) {
                    Double valueObj = (Double) value;
                    double v = valueObj;
                    double[] dArray = new double[sampleModel.getNumBands()];
                    for( int i = 0; i < dArray.length; i++ ) {
                        dArray[i] = v;
                    }
                    for( int y = 0; y < height; y++ ) {
                        for( int x = 0; x < width; x++ ) {
                            raster.setPixel(x, y, dArray);
                        }
                    }
                } else if (value instanceof Integer) {
                    Integer valueObj = (Integer) value;
                    int v = valueObj;
                    int[] dArray = new int[sampleModel.getNumBands()];
                    for( int i = 0; i < dArray.length; i++ ) {
                        dArray[i] = v;
                    }
                    for( int y = 0; y < height; y++ ) {
                        for( int x = 0; x < width; x++ ) {
                            raster.setPixel(x, y, dArray);
                        }
                    }
                } else if (value instanceof Float) {
                    Float valueObj = (Float) value;
                    float v = valueObj;
                    float[] dArray = new float[sampleModel.getNumBands()];
                    for( int i = 0; i < dArray.length; i++ ) {
                        dArray[i] = v;
                    }
                    for( int y = 0; y < height; y++ ) {
                        for( int x = 0; x < width; x++ ) {
                            raster.setPixel(x, y, dArray);
                        }
                    }
                } else {
                    double v = ((Number) value).doubleValue();
                    double[] dArray = new double[sampleModel.getNumBands()];
                    for( int i = 0; i < dArray.length; i++ ) {
                        dArray[i] = v;
                    }
                    for( int y = 0; y < height; y++ ) {
                        for( int x = 0; x < width; x++ ) {
                            raster.setPixel(x, y, dArray);
                        }
                    }
                }

            }
            return raster;
        } else {
            WritableRaster raster = new GrassLegacyWritableRaster(new double[height][width]);
            return raster;
        }
    }
public static WritableRaster createWritableRaster ( int width , int height , Class < ? > dataClass , SampleModel sampleModel , Object value ) { int dataType = DataBuffer . TYPE_DOUBLE ; if ( dataClass != null ) { if ( dataClass . isAssignableFrom ( Integer . class ) ) { dataType = DataBuffer . TYPE_INT ; } else if ( dataClass . isAssignableFrom ( Float . class ) ) { dataType = DataBuffer . TYPE_FLOAT ; } else if ( dataClass . isAssignableFrom ( Byte . class ) ) { dataType = DataBuffer . TYPE_BYTE ; } else if ( dataClass . isAssignableFrom ( Short . class ) ) { dataType = DataBuffer . TYPE_SHORT ; } } if ( ! doesOverFlow ( width , height ) ) { if ( sampleModel == null ) { sampleModel = new ComponentSampleModel ( dataType , width , height , 1 , width , new int [ ] { 0 } ) ; } WritableRaster raster = RasterFactory . createWritableRaster ( sampleModel , null ) ; if ( value != null ) { if ( value instanceof Double ) { Double valueObj = ( Double ) value ; double v = valueObj ; double [ ] dArray = new double [ sampleModel . getNumBands ( ) ] ; for ( int i = 0 ; i < dArray . length ; i ++ ) { dArray [ i ] = v ; } for ( int y = 0 ; y < height ; y ++ ) { for ( int x = 0 ; x < width ; x ++ ) { raster . setPixel ( x , y , dArray ) ; } } } else if ( value instanceof Integer ) { Integer valueObj = ( Integer ) value ; int v = valueObj ; int [ ] dArray = new int [ sampleModel . getNumBands ( ) ] ; for ( int i = 0 ; i < dArray . length ; i ++ ) { dArray [ i ] = v ; } for ( int y = 0 ; y < height ; y ++ ) { for ( int x = 0 ; x < width ; x ++ ) { raster . setPixel ( x , y , dArray ) ; } } } else if ( value instanceof Float ) { Float valueObj = ( Float ) value ; float v = valueObj ; float [ ] dArray = new float [ sampleModel . getNumBands ( ) ] ; for ( int i = 0 ; i < dArray . length ; i ++ ) { dArray [ i ] = v ; } for ( int y = 0 ; y < height ; y ++ ) { for ( int x = 0 ; x < width ; x ++ ) { raster . setPixel ( x , y , dArray ) ; } } } else { double v = ( ( Number ) value ) . doubleValue ( ) ; double [ ] dArray = new double [ sampleModel . getNumBands ( ) ] ; for ( int i = 0 ; i < dArray . length ; i ++ ) { dArray [ i ] = v ; } for ( int y = 0 ; y < height ; y ++ ) { for ( int x = 0 ; x < width ; x ++ ) { raster . setPixel ( x , y , dArray ) ; } } } } return raster ; } else { WritableRaster raster = new GrassLegacyWritableRaster ( new double [ height ] [ width ] ) ; return raster ; } }
Creates a {@link WritableRaster writable raster}.

@param width width of the raster to create.
@param height height of the raster to create.
@param dataClass data type for the raster. If <code>null</code>, defaults to double.
@param sampleModel the samplemodel to use. If <code>null</code>, defaults to
<code>new ComponentSampleModel(dataType, width, height, 1, width, new int[]{0});</code>.
@param value value to which to set the raster to. If null, the default of the raster creation is
used, which is 0.
@return a {@link WritableRaster writable raster}.