I want to convert a runtime image into a native image? why cant i do this in a .net standard project?
The according extension method is only available in uwp, android, and ios assemblies...
Because the type returned is platform-specific. All the UI specific types like MapView, SceneView etc are only available at the platform-specific level.
For .NET Standard you use the RuntimeImage type which is cross-platform.
Ok, then let me pose the question differently.
I have a xamarin.forms project (.net standard). I want to show the thumbnail of an mmpk in a xamarin.forms control. How can i achieve this while I have no ThumbnailUri, just the thumbnail? How do i convert from RuntimeImage to Xamarin.Forms.Image?
Thanks in advance
I was able to use the StreamImageSource for this:
RuntimeImage img = await mapView.ExportImageAsync();
StreamImageSource sis = new StreamImageSource();
sis.Stream = (token) => img.GetEncodedBufferAsync();
image.Source = sis;
This is good feedback though. I'll see if it's possible to add this extension method to the Xamarin.Forms library.
For now, you can put this class in your .NET Standard project, and you'll get the extension method to use everywhere:
/// Provides conversions of the <see cref="RuntimeImage"/> generic type to a platform specific image type
public static class RuntimeImageExtensions
/// Converts a <see cref="RuntimeImage"/> to a Xamarin.Forms image source.
/// <param name="image">Runtime Image to convert</param>
/// <returns>A Xamarin.Forms image source</returns>
public static async Task<global::Xamarin.Forms.ImageSource> ToImageSourceAsync(this RuntimeImage image)
if (image == null)
var imageStream = await image.GetEncodedBufferAsync();
return global::Xamarin.Forms.ImageSource.FromStream(() => imageStream);