code: private static byte[] createScaledJPEG(final Image image, final Dimension scaledSize) throws
  			IOException {
  		// Scale the image.
  		Image scaledImage = image.getScaledInstance(scaledSize.width, scaledSize.height,
  				Image.SCALE_SMOOTH);
  
  		// Create a BufferedImage copy of the scaledImage.
  		BufferedImage bufferedImage = new BufferedImage(scaledImage.getWidth(null), scaledImage.
  				getHeight(null),
  				BufferedImage.TYPE_INT_RGB);
  		Graphics2D graphics = bufferedImage.createGraphics();
  		graphics.drawImage(scaledImage, 0, 0, null);
  		scaledImage.flush();
  		graphics.dispose();
  
  		// Convert the scaled image to a JPEG byte array.
  		ByteArrayOutputStream baos = new ByteArrayOutputStream();
  
  		MemoryCacheImageOutputStream mciis = new MemoryCacheImageOutputStream(baos);
  		ImageIO.write(bufferedImage, IMAGE_JPEG_FORMAT, mciis);
  		mciis.flush();
  		bufferedImage.flush();
  
  		byte[] jpeg = baos.toByteArray();
  		mciis.close();
  
  		return jpeg;
  	}
docs: This method creates an array of bytes representing a JPEG image that is a "scaled" version of the given
  {@link Image}.
  
  @param image The image to be turned into a scaled JPEG.
  @param scaledSize The size to which the given <em>image</em> is to be scaled.
  @return A byte[] representing the JPEG image containing the scaled {@link Image}.
  @throws IOException on any sort of error.