code: private static void setPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels) {
  		if (pixels == null || w == 0 || h == 0) {
  			return;
  		} else if (pixels.length < w * h) {
  			throw new IllegalArgumentException("pixels array must have a length >= w*h");
  		}
  
  		final int imageType = img.getType();
  		if (imageType == BufferedImage.TYPE_INT_ARGB || imageType == BufferedImage.TYPE_INT_RGB) {
  			final WritableRaster raster = img.getRaster();
  			raster.setDataElements(x, y, w, h, pixels);
  		} else {
  			// Unmanages the image
  			img.setRGB(x, y, w, h, pixels, 0, w);
  		}
  	}
docs: <p>Writes a rectangular area of pixels in the destination
  <code>BufferedImage</code>. Calling this method on
  an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
  and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
  
  @param img the destination image
  @param x the x location at which to start storing pixels
  @param y the y location at which to start storing pixels
  @param w the width of the rectangle of pixels to store
  @param h the height of the rectangle of pixels to store
  @param pixels an array of pixels, stored as integers
  @throws IllegalArgumentException is <code>pixels</code> is non-null and
  of length &lt; w*h