Hello,
Welcome to our Microsoft Q&A platform!
If you do not want to store the image to Cache folder in your application path.
You can copy your select image to File folder in your application path like following screenshot.
Here is code. I use FileSystem.AppDataDirectory
path to copy it
private async void Button_Clicked(object sender, EventArgs e)
{
await TakePhotoAsync();
}
string PhotoPath;
async Task TakePhotoAsync()
{
try
{
var photo = await MediaPicker.PickPhotoAsync();
await LoadPhotoAsync(photo);
Console.WriteLine($"CapturePhotoAsync COMPLETED: {PhotoPath}");
DisplayAlert("in", PhotoPath, "OK");
}
catch (FeatureNotSupportedException fnsEx)
{
// Feature is not supported on the device
}
catch (PermissionException pEx)
{
// Permissions not granted
}
catch (Exception ex)
{
Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}");
}
}
async Task LoadPhotoAsync(FileResult photo)
{
// canceled
if (photo == null)
{
PhotoPath = null;
return;
}
// save the file into local storage
var newFile = Path.Combine(FileSystem.AppDataDirectory, photo.FileName);
using (var stream = await photo.OpenReadAsync())
using (var newStream = File.OpenWrite(newFile))
await stream.CopyToAsync(newStream);
PhotoPath = newFile;
}
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.