Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

WebView Load Bundled Image (GIF) in Xamarin.Mac

AllanChin.6924AllanChin.6924 USUniversity ✭✭✭
edited March 2018 in Xamarin.iOS

Can somebody show me how to load a bundled image resource into a WebKit.WebView? The image resides in the Resources folder and is set as BundleResource/Do not copy? I'm trying to LoadHtmlString(), but I can't seem to get the "<img src=..." reference correct. At least I think this is the problem I'm having. I've tried both of these for the src, but to no avail.

        string filePath = "Resources/ready.png"; // remember case-sensitive
        string localGifPath = Path.Combine(NSBundle.MainBundle.BundlePath, filePath);

Actually, I'm doing this to display an animated GIF because the GIF does not animate as the Image property in an NSImage object. Is the WebView the only way to do this, assuming the WebView even works? If tire's a better way, please let me know.

Thanks

Answers

  • AllanChin.6924AllanChin.6924 USUniversity ✭✭✭

    I was finally able to get the animated GIF to display in the WebView. Here's my code snippet.

            string filePath = "spinner.gif"; // remember case-sensitive
    
            var html = "<html><body><img src=\"";
            html += filePath;
            html += "\" width=\"25\" height=\"25\" \" /></body></html>"; //48
    
            WebViewGif.MainFrame.LoadHtmlString(html, NSBundle.MainBundle.ResourceUrl);
    

    But I think it would still be great if we could use an NSImage for the animated GIF. Can this be done?

    Thanks.

  • jonathannicholsjonathannichols USMember ✭✭

    Could you please voice your code for WebViewGif so this thread can be useful to others?

  • KokulJoseKokulJose INMember ✭✭

    File "loading.gif" is at Assets folder of Android Project

    WebView webView=new WebView{
    Source = new HtmlWebViewSource
    {
    Html = $"<body\">image"
    }
    };
    Content = webView;

  • KokulJoseKokulJose INMember ✭✭

    File "loading.gif" is at Assets folder of Android Project

    WebView webView=new WebView{
    Source = new HtmlWebViewSource
    {
    Html = $"<body\">image"
    }
    };
    Content = webView;
    
  • AllanChin.6924AllanChin.6924 USUniversity ✭✭✭

    @jonathannichols said:
    Could you please voice your code for WebViewGif so this thread can be useful to others?

    I'm all for being useful, but I'm not sure I understand what "voice your code for WebViewGif" means?

Sign In or Register to comment.