2012-06-29 26 views
0

我有一個html文件。我將它顯示爲webview。我試圖從SD添加圖像,但我不能。 這裏是我使用的代碼:如何從SD卡添加圖片到html

<tr height="21" style='height:15.75pt'> 
    <td height="21" class="xl71" style='height:15.75pt'>&nbsp;</td> 
    <td class="borderLeft">&nbsp;</td> 
    <td>&nbsp;</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" /> 

但沒有奏效。我無法顯示圖像。 你有什麼想法嗎?

回答

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\" />"; 
+0

動態路徑很重要。 –

0

嘗試使用 「文件://mnt/sdcard/SurucuImza.jpg」。 您可能需要允許使用此行: mWebView.getSettings()。setAllowFileAccess(true);

0

我會做的第一件事就是將圖像複製到您的工作目錄中。如果你不這樣做,當你刪除你的SD卡...你可以告別你的照片。

萬一這是不可能的,只需將該地點的完整路徑。