从OnActivityResult传递data.Data(Uri)到另一个Activity在Imageview中显示图像

时间:2015-05-18 11:22:28

标签: xamarin xamarin.android

当我从图库上传图像时,代码工作正常,但问题是当我想在另一个活动的imageview中显示图像时

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);

    if (resultCode == Result.Canceled) return;

    // make it available in the gallery
    Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
    if (_file != null)
    {
        Android.Net.Uri contentUri = Android.Net.Uri.FromFile(_file);
        mediaScanIntent.SetData(contentUri);
        SendBroadcast(mediaScanIntent);

        // display in ImageView. We will resize the bitmap to fit the display
        // Loading the full sized image will consume to much memory 
        // and cause the application to crash.
            _imageView.SetImageURI(contentUri);
    }
}

ContentUri存储实际图像uri,我想在另一个活动中检索它,但我该怎么做?

1 个答案:

答案 0 :(得分:0)

尝试使用位图设置imageview。 以下链接可帮助您从相机活动中获取位图

http://developer.xamarin.com/recipes/android/other_ux/camera_intent/take_a_picture_and_save_using_camera_app/