Skip to content

Comparison

Chris Kroells edited this page Sep 20, 2015 · 4 revisions

Comparisons

The following are comparison of images created using conventional image resizing techniques, such as using the Graphics.drawImage method and Image.getScaledInstance method, along with resizing using Thumbnailator.

Image Quality and Rendering Speed

Graphics.drawImage Graphics.drawImage
using bilinear interpolation
Graphics.drawImage
using bicubic interpolation
Image.getScaledInstance using Image.SCALE_DEFAULT Image.getScaledInstance
using Image.SCALE_SMOOTH
Thumbnailator
0 ms 0 ms 5 ms 422 ms 771 ms 94 ms
0 ms 5 ms 5 ms 677 ms 1161 ms 235 ms
  • The thumbnail of the photograph in the first row was created from a 2112 pixel by 2816 pixel JPEG image.
  • The thumbnail of the image of the gradient in the second row was created from a 3000 pixel by 3000 pixel PNG image.
  • Times listed is the amount of time that each technique took to resize the image. The time is an average over three runs (using System.currentTimeMillis), measured on a Core 2 Duo system running Java 6 Update 21 on Windows XP.

Code

The following are the relevant sections of code used to generate the above images.

Graphics.drawImage

BufferedImage thumbnail = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
		
Graphics2D g = thumbnail.createGraphics();
g.drawImage(originalImage, 0, 0, WIDTH, HEIGHT, null);
g.dispose();

Graphics.drawImage using bilinear interpolation

BufferedImage thumbnail = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
		
Graphics2D g = thumbnail.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.drawImage(originalImage, 0, 0, WIDTH, HEIGHT, null);
g.dispose();

Graphics.drawImage using bicubic interpolation

BufferedImage thumbnail = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
		
Graphics2D g = thumbnail.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.drawImage(originalImage, 0, 0, WIDTH, HEIGHT, null);
g.dispose();

Image.getScaledInstance using Image.SCALE_DEFAULT

BufferedImage thumbnail = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
		
Graphics2D g = thumbnail.createGraphics();
g.drawImage(originalImage.getScaledInstance(WIDTH, HEIGHT, Image.SCALE_DEFAULT), 0, 0, WIDTH, HEIGHT, null);
g.dispose();

Image.getScaledInstance using Image.SCALE_SMOOTH

BufferedImage thumbnail = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
		
Graphics2D g = thumbnail.createGraphics();
g.drawImage(originalImage.getScaledInstance(WIDTH, HEIGHT, Image.SCALE_SMOOTH), 0, 0, WIDTH, HEIGHT, null);
g.dispose();

Thumbnailator

BufferedImage thumbnail = Thumbnails.of(originalImage)
        .size(WIDTH, HEIGHT)
        .asBufferedImage();