在Android的资产的子文件夹图片不显示网页视图 [英] Images in Android assets subfolder do not display in WebView

查看:189
本文介绍了在Android的资产的子文件夹图片不显示网页视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过很多类似的问题在这里,但他们都不是正是我的问题。

I've seen a lot of similar questions here, but none of them seem to be exactly my problem.

我是从我的资产的子文件夹中加载本地HTML文件夹成的WebView。该文件位于资产/ MyFolder中/ myfolder2 / test.html的。

I'm loading a local html file from a subfolder of my assets folder into a WebView. The file is located in assets/myfolder/myfolder2/test.html.

此外,在资产/ MyFolder中/ myfolder2 /我有image.jpg的。完整路径:资产/ MyFolder中/ myfolder2 / image.jpg的

Also in assets/myfolder/myfolder2/ I have image.jpg. Full path: assets/myfolder/myfolder2/image.jpg

我加载HTML像这样:

I am loading the html like so:

// html contains the string content of the test.html file
webView.loadDataWithBaseURL("file:///android_asset/myfolder/myfolder2/", html,
                                   "text/html", "utf-8", "about:blank");

在HTML字符串,我有以下标记:

In the html string, I have the following tag:

<img src="image.jpg" />

不显示图像。我试着拼写出完整的文件:/// URL到形象好,没有运气。如果我将其更改为某个链接到的图像了网络上,它工作正常。为什么不能找到我的地方形象?

The image is not displayed. I've tried spelling out the full file:/// url to the image as well, with no luck. If I change it to link to an image somewhere out on the web, it works fine. Why can't it find my local image?

推荐答案

太多的无奈之后,我终于找到了,我不能任何Android设备上,查看此特定的图像,甚至从股票浏览器尽管它是什么,我认为是一个正常的JPG图片。

After much frustration, I finally found out that I couldn't view this particular image on any Android device, even from the stock browser, despite it being what I thought was a normal JPG image.

我仍然不知道什么是错的,但是当我在我的照片编辑器打开它,并与正常JPG编码再次救了它,它的工作。这包括我在我的WebView从资产文件夹中引用它。

I'm still not sure what was wrong with it, but when I opened it up in my photo editor and saved it again with normal JPG encoding, it worked. That includes when I reference it from the assets folder in my WebView.

这篇关于在Android的资产的子文件夹图片不显示网页视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆