WebView中加载本地图像

WebView中加载本地图像

本文介绍了如何在Android WebView中加载本地图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将存储在数据库中的包含图像的html字符串加载到WebView中.图像存储在内部存储器中.我给html字符串的引用.但这不起作用.有帮助吗?

I'm trying to load a html string stored in the database which contain a image into a WebView. The image is stored in the internal memory. I am giving a reference to the html string.But it doesn't work. Any help?

String content="<p>Can we have a rotational" +
    " symmetry of order more than 1 whose angle of rotation is&nbsp;</p>\n" +
    "\n <p>(i)&nbsp;<img alt=\"45\\degree\" src=\"file:///storage/emulated/01484890695248.jpg\" /></p>\n" +
    "\n<p>(ii)&nbsp;<img alt=\"35\\degree\" src=\"file:///storage/emulated/01484890697301.jpg\" /></p>";

WebView00.loadDataWithBaseURL("", content, "text/html","UTF-8", "");
WebView00.getSettings();

推荐答案

尝试这样

String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file://"+ base + "/image_name.jpg";
String html = "<html><head></head><body> <img src=\""+ imagePath + "\"> </body></html>";
webView.loadDataWithBaseURL("", html, "text/html","utf-8", "");

这篇关于如何在Android WebView中加载本地图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 16:24