Created
July 1, 2021 07:19
-
-
Save siscofran999/f892eea589d6b69216ad3e9eeaad8d59 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
fun getImageUri(inContext: Context, inImage: Bitmap): Uri { | |
val path: String = MediaStore.Images.Media.insertImage( | |
inContext.contentResolver, | |
inImage, | |
"Title", | |
null | |
) | |
Log.i("TAG", "getImageUri: $path") | |
return Uri.parse(path) | |
} | |
fun getRealPathFromURI(context: Context, contentUri: Uri?): String? { | |
var cursor: Cursor? = null | |
return try { | |
val proj = arrayOf(MediaStore.Images.Media.DATA) | |
cursor = context.contentResolver.query(contentUri!!, proj, null, null, null) | |
val column_index: Int = cursor!!.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) | |
cursor.moveToFirst() | |
cursor.getString(column_index) | |
} finally { | |
cursor?.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment