From c0d16eab82f540220671a5195d2461b739f4a5fe Mon Sep 17 00:00:00 2001 From: Andres Pineda Date: Mon, 30 Mar 2020 23:12:11 -0400 Subject: [PATCH] feat: (macOS) Add #2844 support for Image --- src/Uno.UI/UI/Xaml/Media/ImageSource.macOS.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Uno.UI/UI/Xaml/Media/ImageSource.macOS.cs b/src/Uno.UI/UI/Xaml/Media/ImageSource.macOS.cs index ae838b02018c..92895369041c 100644 --- a/src/Uno.UI/UI/Xaml/Media/ImageSource.macOS.cs +++ b/src/Uno.UI/UI/Xaml/Media/ImageSource.macOS.cs @@ -66,7 +66,7 @@ public bool HasSource() /// internal NSImage OpenBundle() { - ImageData = OpenBundleFromString(BundleName) ?? OpenBundleFromString(BundlePath); + ImageData = OpenBundleFromString(BundleName) ?? OpenResourceFromString(BundlePath); if (ImageData == null) { @@ -86,6 +86,23 @@ private static NSImage OpenBundleFromString(string bundle) return null; } + private static NSImage OpenResourceFromString(string name) + { + if (name.HasValueTrimmed()) + { + var extension = Path.GetExtension(name); + var fileName = name.Replace(extension, string.Empty); + + var path = NSBundle.MainBundle.PathForResource(fileName, extension); + + return !string.IsNullOrEmpty(path) + ? new NSImage(path) + : null; + } + + return null; + } + internal async Task Open(CancellationToken ct) { using (