Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从inputStream获取文件路径_Android_Image_File Io_Inputstream - Fatal编程技术网

Android 从inputStream获取文件路径

Android 从inputStream获取文件路径,android,image,file-io,inputstream,Android,Image,File Io,Inputstream,我正在从gallery加载图片并将其设置为imageview,但我有一个旋转图像的函数,该函数需要图像Uri。当我从内存中读取图片时,我使用以下代码 if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){ ActivityCompat.requestPermissions(this, ne

我正在从gallery加载图片并将其设置为imageview,但我有一个旋转图像的函数,该函数需要图像Uri。当我从内存中读取图片时,我使用以下代码

if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
        ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_PERMISSION);
    }else{
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, SELECT_FILE);
    }
然后

函数
rotateBitmap()
需要图像的文件路径,我不知道如何获取…

使用光标:

Uri selectedImageUri = data.getData();
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImageUri, proj, null, null, null);
if (cursor.moveToFirst()) {
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    String  file_path = cursor.getString(column_index);
}
cursor.close();

使用Uri可以获取图像的路径。。。 尝试此代码,可能会对您有所帮助

    Cursor cursor = getContentResolver().query(Use_Uri_Here, null, null, null, null); 
cursor.moveToFirst(); 
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 
String imagePath = cursor.getString(idx); 

没有“文件路径”。您的
rotateBitmap()
方法需要重写,或者您需要提供自己的写入路径。完美-工作正常。万分感谢!!
    Cursor cursor = getContentResolver().query(Use_Uri_Here, null, null, null, null); 
cursor.moveToFirst(); 
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 
String imagePath = cursor.getString(idx);