Skip to content

Instantly share code, notes, and snippets.

@r4hulp
Last active October 26, 2015 16:46
Show Gist options
  • Save r4hulp/19aac056ff6789198c14 to your computer and use it in GitHub Desktop.
Save r4hulp/19aac056ff6789198c14 to your computer and use it in GitHub Desktop.
GetPathToImage Xamarin's implementation
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