Last active
October 26, 2015 16:46
-
-
Save r4hulp/19aac056ff6789198c14 to your computer and use it in GitHub Desktop.
GetPathToImage Xamarin's implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) | |
{ | |
if ((requestCode == PickImageId) && (resultCode == Result.Ok) && (data != null)) | |
{ | |
Uri uri = data.Data; | |
_imageView.SetImageURI(uri); | |
string path = GetPathToImage(uri); | |
Toast.MakeText(this, path, ToastLength.Long); | |
} | |
} | |
private string GetPathToImage(Uri uri) | |
{ | |
string path = null; | |
// The projection contains the columns we want to return in our query. | |
string[] projection = new[] { Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data }; | |
using (ICursor cursor = ManagedQuery(uri, projection, null, null, null)) | |
{ | |
if (cursor != null) | |
{ | |
int columnIndex = cursor.GetColumnIndexOrThrow(Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data); | |
cursor.MoveToFirst(); | |
path = cursor.GetString(columnIndex); | |
} | |
} | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment