簡體   English   中英

如何從SD卡添加圖像到HTML

[英]How to add image to html from sd card

我有一個html文件。 我把它顯示為webview。 我試圖從SD添加圖像,但我不能。 這是我使用的代碼:

<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" />

但它沒有用。 我無法顯示圖像。 你有什么主意嗎?

試試吧

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

試試“file://mnt/sdcard/SurucuImza.jpg”。 您可能需要允許使用此行訪問:mWebView.getSettings()。setAllowFileAccess(true);

我要做的第一件事就是將圖像復制到您的工作目錄中。 如果你不這樣做,當你取出SD卡時...你可以告別你的照片。

如果無法做到這一點,只需將完整路徑放到該位置即可。

采用

src="file:///" + Environment.getExternalStorageDirectory() + "your_image_folder_name/SurucuImza.jpg"

保證

src="/sdcard/SurucuImza.jpg"

注意:首先提供清單的權限..

android.permission.WRITE_EXTERNAL_STORAGE 
android.permission.READ_EXTERNAL_STORAGE

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM