Created
December 19, 2018 21:02
-
-
Save DevPicon/a2484202d02d1a11db8b64dbb17d5866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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