/// <summary> /// Load an EmbeddedResource as a Xamarin.Forms.FileImageSource /// </summary> /// <param name="resourceId"></param> /// <param name="assembly"></param> /// <returns></returns> public static Xamarin.Forms.FileImageSource FromResourceAsFile(string resourceId, Assembly assembly = null) { assembly = EmbeddedResourceExtensions.FindAssemblyForResource(resourceId, assembly); /* * assembly = assembly ?? AssemblyExtensions.AssemblyFromResourceId(resourceId); * if (assembly == null && Device.RuntimePlatform != Device.UWP) * assembly = (Assembly)typeof(Assembly).GetTypeInfo().GetDeclaredMethod("GetCallingAssembly")?.Invoke(null, new object[0]); */ if (assembly == null) { return(null); } var r = BestGuessResource(resourceId, assembly); var path = r == null ? resourceId : r.Path; var localPath = P42.Utils.EmbeddedResourceCache.LocalStorageFullPathForEmbeddedResource(path, assembly); var imageSource = new FileImageSource { File = localPath }; if (imageSource != null) { imageSource.SetValue(ImageScaleProperty, 1.0f); imageSource.SetValue(EmbeddedResourceIdProperty, resourceId); imageSource.SetValue(AssemblyProperty, assembly); } return(imageSource); }