If this question has already been answered, please let me know. I am about 3 weeks into using Xamarin and so far I like it. I am working on an app where I am allowing the user to take a picture. I am able to do this successfully and retrieve the image using Xlabs. I need to be able to go back and retrieve that same image - potentially after closing the application. I really just need to maintain some sort of link to that image. If the user deletes it later (e.g. if it is on the phone gallery I am okay with that). Without getting into the details of the app, these are non-critical photos that the user may or may not decide to delete. I don't want to store them within my app or send them to a server at this point.
I am following the example below that is referred to numerous times on these forums. This works great for displaying the initial photo after taking it. I get a path that looks like this:
/var/mobile/Containers/Data/Application/B7E0B09A-E39C-4A30-BAE0-E277AC3214CA/Documents/IMG_20150729_080622.jpg
I did make a feeble attempt at re-loading the image but it didn't work (see below).
` private async Task TakePicture()
{
Setup ();
ImageSource = null;
try {
_statusEntry.Text = "Launching Camera...";
return await _mediaPicker.TakePhotoAsync (new CameraMediaStorageOptions {
DefaultCamera = CameraDevice.Rear,
MaxPixelDimension = 400,
SaveMediaOnCapture = true
}).ContinueWith (t => {
if (t.IsFaulted) {
_statusEntry.Text = t.Exception.InnerException.ToString ();
} else if (t.IsCanceled) {
_statusEntry.Text = "Canceled";
} else {
_statusEntry.Text = "Got Result";
var mediaFile = t.Result;
ImageSource = ImageSource.FromStream (() => mediaFile.Source);
_img.Source = ImageSource;
_statusEntry.Text = mediaFile.Path;
return mediaFile;
}
return null;
}, _scheduler);
} catch (Exception ex) {
_statusEntry.Text = ex.Message;
return null;
}
}`
My attempt at retrieving the file:
` public class ShowPicture : ContentPage
{
private Image _img;
public ImageSource ImageSource;
public ShowPicture ()
{
_img = new Image(){HeightRequest = 300, WidthRequest = 300, BackgroundColor = Color.FromHex("#D6D6D2"),Aspect = Aspect.AspectFit };
ImageSource = ImageSource.FromFile ("/var/mobile/Containers/Data/Application/B7E0B09A-E39C-4A30-BAE0-E277AC3214CA/Documents/IMG_20150729_080622.jpg");
_img.Source = ImageSource;
Content = new StackLayout {
Children = {
_img
}
};
}
}`