Hello,
Firstly, you need to get the MaterialEntry
by entry, then get ImageSource
by LeadingImageSource
.
Then you can convert ImageSource to IImageSourceHandler
, please notice you need to convert specific ImageSourceHandler by ImageSource type.
In the end, you can get Bitmap by await iImageSourceHandler.LoadImageAsync(imageSource, MainActivity.Instance);
, You can refer to following code
public static async void MapImage(IMaterialEntryHandler handler, IMaterialEntry entry)
{
// Bitmap bitmap = entry.LeadingImageSource //how to get from ImageSource?
if (entry != null)
{
MaterialEntry materialEntry = entry as MaterialEntry;
ImageSource imageSource = materialEntry.LeadingImageSource;
IImageSourceHandler iImageSourceHandler;
if (imageSource is FileImageSource)
{
iImageSourceHandler = new FileImageSourceHandler();
}
else if (imageSource is StreamImageSource)
{
iImageSourceHandler = new StreamImagesourceHandler(); // sic
}
else if (imageSource is UriImageSource)
{
iImageSourceHandler = new ImageLoaderSourceHandler(); // sic
}
else
{
throw new NotImplementedException();
}
Bitmap bitmap = await iImageSourceHandler.LoadImageAsync(imageSource, MainActivity.Instance);
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.