Issue
How to create a image picker on Xamarin Forms?
This worked, managed to stream the file to the app directory 'files' from any device folder.
But when picking an image file from the Camera folder the image file does not appear in the image tag. The images from all other folders do appear. Any ideas?
...
Stream stream = await DependencyService.Get<IPhotoPickerService>().GetImageStreamAsync();
if (stream != null)
{
string filePath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal), thewordsetid.ToString());
FileStream fileStream = File.Open(filePathName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
stream.Position = 0;
stream.CopyTo(fileStream);
fileStream.Flush();
fileStream.Close();
}
public class PhotoPickerService : IPhotoPickerService
{
public Task<Stream> GetImageStreamAsync()
{
// Define the Intent for getting images
Intent intent = new Intent();
intent.SetType("image/*");
intent.SetAction(Intent.ActionGetContent);
// Start the picture-picker activity (resumes in MainActivity.cs)
MainActivity.Instance.StartActivityForResult(
Intent.CreateChooser(intent, "Select Photo"),
MainActivity.PickImageId);
// Save the TaskCompletionSource object as a MainActivity property
MainActivity.Instance.PickImageTaskCompletionSource = new TaskCompletionSource<Stream>();
// Return Task object
return MainActivity.Instance.PickImageTaskCompletionSource.Task;
}
}
...
Solution
You could check your Output Window. It caused by the too large image.
Bitmap too large to be uploaded into a texture (3120x4160, max=4096x4096)
The photo which match the max size(4096x4096) would be loaded. You could check the screenshot.
Answered By - Wendy Zang - MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.