Skip to content

Scaling images

Ralph Niemitz edited this page May 18, 2017 · 5 revisions

Absolute scaling

Absolute scaling is resizing the image to have the given width and height. It doesn't matter if the result is proportional to the original.

This can be done with the scale(int, int) method. The parameters of this method are the new width and height of the image and optional the algorithm to use. Nearest neighbour interpolation will be used by default. The width and height of the new image must be bigger than zero.

Example:

SimpleImage orig = new SimpleImage("myImage.jpg");
SimpleImage scaled = orig.scale(600, 289, SimpleImge.SCALE_NEAREST_NEIGHBOUR);

Original:
Original

Scaled:
Scaled

Scale to fit

With this method of scaling the image will be resized proportional until it hits either the given width or height of the target size.

This can be done with the method scaleToFit(int, int). The parameters of this method are the target size and optional the algorithm to use. Nearest neighbour interpolation will be used by default. The width and height of the new image must be bigger than zero.

Example:

SimpleImage orig = new SimpleImage("myImage.jpg");
SimpleImage scaled = orig.scaleToFit(600, 600, SimpleImge.SCALE_NEAREST_NEIGHBOUR);

Original:
Original

Scaled:
Scaled

Scale by factor

With this method of scaling the image will be resized proportional by a given factor.

This can be done with the method scaleByFactor(float). The parameters of this method are the factor by wich the image should be scaled and optional the algorithm to use.

Example:

SimpleImage orig = new SimpleImage("myImage.jpg");
SimpleImage scaled = orig.scaleByFactor(2.0F, SimpleImge.SCALE_NEAREST_NEIGHBOUR);

Original:
Original

Scaled:
Scaled

Clone this wiki locally