WindSekirun/RichUtilsKt

Add feature - get Image's Width, Height, Mimetype without load bitmap into Memory

WindSekirun opened this issue · 1 comments

Add feature - get Image's Width, Height, Mimetype without load bitmap into Memory

Prototype:

fun String.getImageWidth(): Int {
    val options = BitmapFactory.Options()
    options.inJustDecodeBounds = true
    BitmapFactory.decodeFile(this, options)
    return options.outWidth
}

fun String.getImageHeight(): Int {
    val options = BitmapFactory.Options()
    options.inJustDecodeBounds = true
    BitmapFactory.decodeFile(this, options)
    return options.outHeight
}

fun String.getImageMimeType(): String {
    val options = BitmapFactory.Options()
    options.inJustDecodeBounds = true
    BitmapFactory.decodeFile(this, options)
    return options.outMimeType ?: ""
}