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
Peter
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.
Thx for the confirmation. I came up with the same. It would be great if you'd put it into the xamarin library.
Greetings
For now, you can put this class in your .NET Standard project, and you'll get the extension method to use everywhere:
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Threading<SPAN class="punctuation token">.</SPAN>Tasks<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">using</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>UI<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">namespace</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Xamarin<SPAN class="punctuation token">.</SPAN>Forms <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">/// <summary></SPAN> <SPAN class="comment token">/// Provides conversions of the <see cref="RuntimeImage"/> generic type to a platform specific image type</SPAN> <SPAN class="comment token">/// </summary></SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">static</SPAN> <SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">RuntimeImageExtensions</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">/// <summary></SPAN> <SPAN class="comment token">/// Converts a <see cref="RuntimeImage"/> to a Xamarin.Forms image source.</SPAN> <SPAN class="comment token">/// </summary></SPAN> <SPAN class="comment token">/// <param name="image">Runtime Image to convert</param></SPAN> <SPAN class="comment token">/// <returns>A Xamarin.Forms image source</returns></SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">static</SPAN> <SPAN class="keyword token">async</SPAN> Task<SPAN class="operator token"><</SPAN><SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Xamarin<SPAN class="punctuation token">.</SPAN>Forms<SPAN class="punctuation token">.</SPAN>ImageSource<SPAN class="operator token">></SPAN> <SPAN class="token function">ToImageSourceAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">this</SPAN> RuntimeImage image<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>image <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> imageStream <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> image<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetEncodedBufferAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">global</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">:</SPAN>Xamarin<SPAN class="punctuation token">.</SPAN>Forms<SPAN class="punctuation token">.</SPAN>ImageSource<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FromStream</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> imageStream<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.