code: public static WritableRaster renderedImage2WritableRaster( RenderedImage renderedImage, boolean nullBorders ) {
          int width = renderedImage.getWidth();
          int height = renderedImage.getHeight();
  
          Raster data = renderedImage.getData();
          WritableRaster writableRaster = data.createCompatibleWritableRaster();
          writableRaster.setDataElements(0, 0, data);
          if (nullBorders) {
              for( int c = 0; c < width; c++ ) {
                  writableRaster.setSample(c, 0, 0, doubleNovalue);
                  writableRaster.setSample(c, height - 1, 0, doubleNovalue);
              }
              for( int r = 0; r < height; r++ ) {
                  writableRaster.setSample(0, r, 0, doubleNovalue);
                  writableRaster.setSample(width - 1, r, 0, doubleNovalue);
              }
          }
  
          return writableRaster;
      }
docs: Creates a compatible {@link WritableRaster} from a {@link RenderedImage}.
  
  @param renderedImage the image to convert.
  @param nullBorders a flag that indicates if the borders should be set to null.
  @return the converted writable raster.