Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

HybridWebView to load local image not working

$
0
0

Hi all. I have issue with android customization for WebView.
I`m using HybridWebView on my Xamarin.Forms page to show my custom HTML. XAML is looking like this:

<base:MyDescendentFromWebView Source="{Binding ViewModel.SomeHtmlBody, Converter={StaticResource ConvertImagesToLocalPathes}}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></base:MyDescendentFromWebView>

Fair enough... Images was saved into local application folder like '/data/data/myApp/files/Root/'. So image file exists (100%)!
On other hand ViewModel.SomeHtmlBody equals "html img src="image1.jpeg" /html"; (of course with brackets)

:::::::Problem::::::::::
So, I want my web view to show this image. I thought it is simple. But it is not. I had 2 ways:
1) BASE64 implementation:
1) Get imageData bytes from local storage (/data/data/myApp/files/Root/image1.jpeg)
2) Convert to base64
3) Replace img src="image1.jpeg" to img src="data:image/jpg;base64,.........."

**Result: It works ONLY on 4.4.4, BUT application simply hangs off (on emulator and phone) after clicking on several views (which contains this WebView). **
I assume that there is some problem with memory. AND on 4.1.1 image simple transparent or white, so invisible, but space (in DOM) is allocated for it.

2) The way which works in IPhone: simply put into img tag full path to image like this:
img src="file:///data/data/myApp/files/Root/image1.jpeg"
When I tried this it writes in application logs:
[chromium] [INFO:CONSOLE(1)] "Not allowed to load local resource: file:///data/data/maApp/files/Root/image1.jpeg", source: data:text/html,!DOCTYPE html html xmlns=..........
and I don`t see image at all and even place allocated for it.

GUYS, Please provide official(or at least working) way to do it. Thank you!

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>