My use case requires the user to select multiple photos from his device gallery and display the selected images as a gridview inside my xamarin forms application. I already have done the Take photo using the device camera and display the photo taken on the app, but this is just one photo at a time. The code for take photo is as below.
public async void DoTakePhoto()
{
try
{
VisualState = State.Loading;
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
return;
}
MediaFile file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
SaveToAlbum = true,
Directory = "App Photo Folder",
MaxWidthHeight = 2048,
CompressionQuality = 50,
PhotoSize = PhotoSize.MaxWidthHeight,
});
if (file == null && ImageSource == null)
{
return;
}
else if (file == null)
{
return;
}
MediaWithFile = new MediumWithFile(m_ExifDataParser) {
Id = new Guid(),
Data = file,
Path = file.Path,
AlbumPath = file.AlbumPath,
Version = 1
};
}
catch (Exception ex)
{
DisplayAlert("B5", ex.ToString(), "B5");
return;
}
finally
{
VisualState = State.None;
}
}
And i am having a bindable ImageSource variable as follows:
public ImageSource ImageSource => MediaWithFile?.Data == null ? null : ImageSource.FromFile(MediaWithFile.Data.Path);
I am displaying the clicked photo on my UI using the following code:
<Frame Grid.Row="0"
Grid.ColumnSpan="2"
Padding="0"
CornerRadius="8">
<Image Aspect="AspectFill"
BackgroundColor="Transparent"
Source="{Binding ImageSource}" />
</Frame>
Is there a way to upload multiple images from gallery and display them using the same Crossmedia plugin. Any idea on this is appreciated.