DecodeUtils

A collection of useful utility methods for decoding images.

Functions

Link copied to clipboard
fun calculateInSampleSize(srcWidth: Int, srcHeight: Int, dstWidth: Int, dstHeight: Int, scale: Scale): Int

Calculate the BitmapFactory.Options.inSampleSize given the source dimensions of the image (srcWidth and srcHeight), the output dimensions (dstWidth, dstHeight), and the scale.

Link copied to clipboard
fun computeDstSize(srcWidth: Int, srcHeight: Int, targetSize: Size, scale: Scale, maxSize: Size): IntPair

Parse targetSize and return the destination dimensions that the source image should be scaled into. The returned dimensions can be passed to computeSizeMultiplier to get the final size multiplier.

Link copied to clipboard
fun computeSizeMultiplier(srcWidth: Double, srcHeight: Double, dstWidth: Double, dstHeight: Double, scale: Scale): Double
fun computeSizeMultiplier(srcWidth: Float, srcHeight: Float, dstWidth: Float, dstHeight: Float, scale: Scale): Float

fun computeSizeMultiplier(srcWidth: Int, srcHeight: Int, dstWidth: Int, dstHeight: Int, scale: Scale): Double

Calculate the percentage to multiply the source dimensions by to fit/fill the destination dimensions while preserving aspect ratio.