[英]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.