private <T> T scaleImageUsingAffineTransformation(final BufferedImage bufferedImage, T target) {
    BufferedImage destinationImage = generateDestinationImage();
    Graphics2D graphics2D = destinationImage.createGraphics();
    AffineTransform transformation =
        AffineTransform.getScaleInstance(
            ((double) getQualifiedWidth() / bufferedImage.getWidth()),
            ((double) getQualifiedHeight() / bufferedImage.getHeight()));
    graphics2D.drawRenderedImage(bufferedImage, transformation);
    graphics2D.addRenderingHints(retrieveRenderingHints());
    try {
      if (target instanceof File) {
        LOGGER.info(String.format(M_TARGET_TYPE_OF, "File"));
        ImageIO.write(destinationImage, imageType.toString(), (File) target);
      } else if (target instanceof ImageOutputStream) {
        LOGGER.info(String.format(M_TARGET_TYPE_OF, "ImageOutputStream"));
        ImageIO.write(destinationImage, imageType.toString(), (ImageOutputStream) target);
      } else if (target instanceof OutputStream) {
        LOGGER.info(String.format(M_TARGET_TYPE_OF, "OutputStream"));
        ImageIO.write(destinationImage, imageType.toString(), (OutputStream) target);
      } else {
        target = null;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    return target;
  }
 private static ImageElement fetchImageProperties(
     final BufferedImage source,
     final ImageType imageType,
     final String id,
     final Date modifiedDate,
     final String mimeType)
     throws NullPointerException, IOException {
   if (verifyNotNull(source)) {
     ImageElement image = new ImageElement();
     image.setBitDepth(
         verifyNotNull(source.getColorModel().getPixelSize())
             ? source.getColorModel().getPixelSize()
             : 0);
     image.setHeight(verifyNotNull(source.getHeight()) ? source.getHeight() : 0);
     image.setWidth(verifyNotNull(source.getWidth()) ? source.getWidth() : 0);
     image.setSizeInBytes(determineSizeOfBufferedImage(source, imageType.toString()));
     image.setCreated(new Date(System.currentTimeMillis()));
     image.setTransparent(
         determineTransparencyType(source.getGraphics().getColor().getTransparency()));
     if (verifyNotNull(modifiedDate)) image.setModified(modifiedDate);
     image.setId((verifyNotNull(id) ? id : ""));
     image.setFontType(
         verifyNotNull(source.getGraphics().getFont())
             ? source.getGraphics().getFont()
             : new Font("Default", 0, 0));
     image.setMediaType(MediaType.Missing);
     return image;
   }
   throw new NullPointerException(E_OBJECT_WAS_NULL);
 }
 private static BufferedImage convert(final BufferedImage source, final ImageType imageType)
     throws NullPointerException, IOException {
   if (verifyNotNull(source)) {
     File targetedFile = null;
     ImageIO.write(source, imageType.toString(), targetedFile);
     if (verifyNotNull(targetedFile)) {
       return ImageIO.read(targetedFile);
     }
   }
   throw new NullPointerException(
       "Something bad happened. You should never try that again. Ever.");
 }