Skip to content

Instantly share code, notes, and snippets.

@DevPicon
Created December 19, 2018 21:02
Show Gist options
  • Save DevPicon/a2484202d02d1a11db8b64dbb17d5866 to your computer and use it in GitHub Desktop.
Save DevPicon/a2484202d02d1a11db8b64dbb17d5866 to your computer and use it in GitHub Desktop.
import android.graphics.BitmapFactory
import android.net.Uri
class ImageUtils {
companion object {
@JvmStatic
fun getImageInfoFromUri(fileUri: Uri): ImageInfo {
val options = BitmapFactory.Options().apply {
inJustDecodeBounds = true
}
BitmapFactory.decodeFile(fileUri.path, options)
return ImageInfo(width = options.outWidth, height = options.outHeight, mimeType = options.outMimeType)
}
}
class ImageInfo(val width: Int, val height: Int, val mimeType: String?) {
fun isValid() = width != -1 && height != -1
fun hasValidMimeType() = mimeType != null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment