简体   繁体   English

图片库中的RealPath

[英]RealPath from Gallery image

I Use classes from this answer 我使用这个答案中的课程

Stack Answer 堆叠答案

and I have problem implementing code which returned me real path from selected image, I need real route for get FILE on other method (for send to server) 并且我在实现代码时遇到了问题,该代码从所选图像返回了我的真实路径,我需要在其他方法上获取文件的真实路径(用于发送到服务器)

But I'm not successful. 但是我没有成功。

I was trying for hours find something on the web but unsuccessful too. 我尝试了好几个小时才能在网上找到东西,但也没有成功。

Please do you have some idea? 请问您有什么主意吗?

(I need send image for server so I need File image1 = new File(PathString) ) (我需要为服务器发送图像,因此我需要File image1 = new File(PathString)

I need real route for get FILE on other method 我需要通过其他方法获取FILE的真实路径

Step #1: Use ContentResolver and openInputStream() to get an InputStream on the content represented by the Uri that you received. 步骤#1:使用ContentResolveropenInputStream()获得关于您收到的Uri表示的内容的InputStream

Step #2: Create a FileOutputStream on some temporary file that you control (eg, in getCacheDir() ). 步骤#2:在您控制的某个临时文件上创建FileOutputStream (例如,在getCacheDir() )。

Step #3: Copy the content from the InputStream to the FileOutputStream , using standard Java I/O. 步骤#3:使用标准Java I / O将内容从InputStream复制到FileOutputStream

Step #4: Use the file that you just created. 步骤4:使用刚创建的文件。

Step #5: When you are done with that file, delete it. 步骤5:使用完该文件后,将其删除。

My problem solve this code... 我的问题解决了此代码...

here is good everything 一切都很好

solution

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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