Scales an image up or down. This operation will change both the canvas and the image. This is what most people want when they think of "resizing" an image.
If instead, we wish to change the image "canvas" without scaling up or down, then resize is the right operation.
We can perform a scale operation with a specified width and height. Or we can specify only a width or height and Scrimage will adjust the other dimension to keep the aspect ratio constant.
Alternatively, we can specify a scale factor, which will multiply the width and height by that factor.
Using this image as our input:
image.scaleToWidth(400) // keeps aspect ratio
image.scaleToHeight(200) // keeps aspect ratio
// using the fast scale method image.scaleTo(400, 400, ScaleMethod.FastScale)
image.scale(0.5) // keeps aspect ratio, applies factor to width and height
Each scale operation has a
ScaleMethod parameter that allows us to specify the algorithm to be used when
performing the scale. Options are
Bicubic. Bicucbic is the default.
Here is the same image scaled using each of the algorithms. Click on the image to see the full size.