Use local files instead of Uri for map icon image #150
-
To use local files instead of Uri remote images for map icon images on an Android , I made the following changes to the MauiMaps sample. I made the following changes to the CustomMapHandler.cs AddPins method: if (pin is MapLocation cp)
{
Bitmap bitmap = null;
if (cp.ImageSource is FileImageSource)
{
var imageFileSourceHandler = new FileImageSourceHandler();
bitmap = await imageFileSourceHandler.LoadImageAsync(cp.ImageSource, Application.Context);
}
else
{
var imageUriSourceHandler = new ImageLoaderSourceHandler();
bitmap = await imageUriSourceHandler.LoadImageAsync(cp.ImageSource, Application.Context);
}
markerOption?.SetIcon(bitmap is null
? BitmapDescriptorFactory.DefaultMarker()
: BitmapDescriptorFactory.FromBitmap(bitmap));
} But I dont know how to make these changes for iOS or MacCatalyst. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
you don't need to change Handler and use FileImageSourceHandler. It should automatically use correct handler to load image from the ImageSource depends on its type. You need to provide a valid ImageSource to make it work |
Beta Was this translation helpful? Give feedback.
-
I had to make the changes I described for the Android because I was getting null for the bitmap using ImageLoaderSourceHandler() to try to load a local file for the pin image. The changes allow it to work. So the Android must not be working as you expect. |
Beta Was this translation helpful? Give feedback.
-
I see that you are passing a memory stream. I was passing a file name |
Beta Was this translation helpful? Give feedback.
you don't need to change Handler and use FileImageSourceHandler. It should automatically use correct handler to load image from the ImageSource depends on its type. You need to provide a valid ImageSource to make it work