我有一个html文件。我把它显示为webview。我试图从SD添加图像,但我不能。 这是我使用的代码:
<tr height="21" style='height:15.75pt'>
<td height="21" class="xl71" style='height:15.75pt'> </td>
<td class="borderLeft"> </td>
<td> </td>
<td>
<![if !vml]>
<span style='mso-ignore:vglayout;add
position:absolute;z-index:20;margin-left:24px;margin-top:3px;width:73px;
height:144px'><img src="/sdcard/SurucuImza.jpg" alt="" width="168" height="120" v:shapes="Picture_x0020_421" /></span>
<![endif]>
<span
style='mso-ignore:vglayout2'>
<table cellpadding="0" cellspacing="0">
<tr>
我在这里使用了路径:
<img src="/sdcard/SurucuImza.jpg" alt="" width="168" height="120" v:shapes="Picture_x0020_421" />
但它没有用。我无法显示图像。 你有什么想法吗?
答案 0 :(得分:2)
尝试
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file:/"+ base + "/SurucuImza.jpg";
String strimg="<img src=\""+ imagePath + "\" alt=\"\" width=\"168\" height=\"120\" v:shapes=\Picture_x0020_421\" />";
答案 1 :(得分:0)
尝试使用“file://mnt/sdcard/SurucuImza.jpg”。 您可能需要允许此行访问: 。mWebView.getSettings()setAllowFileAccess(真);
答案 2 :(得分:0)
我要做的第一件事就是将图像复制到您的工作目录中。如果你不这样做,当你取出SD卡时...你可以告别你的照片。
如果无法做到这一点,只需将完整路径放到那个地方。
答案 3 :(得分:0)
使用
src="file:///" + Environment.getExternalStorageDirectory() + "your_image_folder_name/SurucuImza.jpg"
保证
src="/sdcard/SurucuImza.jpg"
注意:首先授予显示权限。
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE