繁体   English   中英

无法从 android 中的图像 uri 获取图像真实路径

[英]Unable to get Image real path from image uri in android

我试图从它的 uri 中获取我的图像的真实路径,但将 null 作为路径返回。 我正在使用以下参考代码来获取真实路径。

https://gist.github.com/tatocaster/32aad15f6e0c50311626

示例图像 Uri: content://com.android.providers.media.documents/document/image%3A102173

返回的真实路径: null

试试这个,它对我不起作用,但你可以尝试从 mediastore 的 URI 获取文件名和路径,因为它显然对很多人都有效。 如果你仍然得到 null 你可以做我所做的。

我尝试了很多方法,但仍然得到结果 null。 基本上,我正在尝试从本地存储上传图像压缩它,并使用压缩图像。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM