[英]Unable to get Image real path from image uri in android
I am trying to the get the real path of my image from its uri but getting null in return as path.我试图从它的 uri 中获取我的图像的真实路径,但将 null 作为路径返回。 I am using the following referenced code to get the real path.我正在使用以下参考代码来获取真实路径。
https://gist.github.com/tatocaster/32aad15f6e0c50311626
Sample Image Uri: content://com.android.providers.media.documents/document/image%3A102173示例图像 Uri: content://com.android.providers.media.documents/document/image%3A102173
Returned Real Path: null返回的真实路径: null
Try this it didn't work for me but you can try Get filename and path from URI from mediastore as it has apparently worked for many people's.试试这个,它对我不起作用,但你可以尝试从 mediastore 的 URI 获取文件名和路径,因为它显然对很多人都有效。 If you still get null you can do what I have done.如果你仍然得到 null 你可以做我所做的。
I tried many ways but I was still getting the result null.我尝试了很多方法,但仍然得到结果 null。 basically, I am trying to upload an image from local storage compress it, and used the compressed image.基本上,我正在尝试从本地存储上传图像压缩它,并使用压缩图像。
val path = this.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)`try {
val file = File(path, "/Image")
file.mkdirs()
val image = File(file.absolutePath, "image1.jpeg")
intent1.data = image.absolutePath.toUri()
val bitmap = BitmapFactory.decodeStream(this.contentResolver.openInputStream(uri))
val array = ByteArrayOutputStream()
val out = FileOutputStream(image)
bitmap.compress(Bitmap.CompressFormat.JPEG, 70,out)
out.flush()
out.close()
Log.d("Path", image.absolutePath)
} catch (e: Exception) {
e.printStackTrace()
}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.