To downscale images:
Construct a
new ImageScaler
object with source and destination
path of the image.
//Construct a new ImageScaler object to downscale a JPEG image on the device ImageScaler is = new ImageScaler("file:///Phone/big.jpg", "file:///Phone/small.jpg");
Use the ImageScaler.setJpegQuality
method for specifiying output
quality of the JPEG image.
//Set image quality for the JPEG image is.setJpegQuality(70);
Use the ImageScaler.scaleImage
method for downscaling image. You
can construct the ImageScaler.scaleImage
method in
one of two ways
ImageScaler.scaleImage(int maxFileSize)
Use this constructor to specify the maximum output file size, in kilobytes, for the downscaled image.
//Set the downscaled image’s file size to be less than or equal to 100kb is.scaleImage(100);
ImageScaler.scaleImage(int width, int height, boolean
keepAspectRatio)
Use this constructor to specify the desired width and height in pixels for the downscaled image. You must also specify if the aspect ratio of the source image needs to be retained.
//Set the downscaled image’s dimensions to 320x480px, and ignore the source image’s aspect ratio is.scaleImage(320, 480, false);
Note: See the Image Scaling API reference for other options in downscaling images by dimensions.