2012-04-18 28 views
0

嗨,我製作了一個程序,該圖像位於文件夾中(路徑是sdcard/scheduler/pic.jpg)。 我該如何加載這張圖片並顯示它。我的圖片應該可以放大。所以我使用Web視圖來顯示圖像。該代碼是下面使用webview從特定的floder加載圖像

mWebView = (WebView) findViewById(R.id.webview); 

     mWebView.getSettings().setAllowFileAccess(true); 
     mWebView.getSettings().setJavaScriptEnabled(true); 
     mWebView.getSettings().setBuiltInZoomControls(true); 

    String imagePath = "file:/sdcard/Schedular/233322.jpg"; 
      String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>"; 
      mWebView.loadData(html, "text/html","utf-8"); 

此代碼不加載圖像的問題。它只給白屏。我認爲這是一條路徑問題。請給出一個解決方案..

回答

0

你給圖像的路徑錯誤。 Environment.getExternalStorageDirectory()會給你的SD卡路徑。形成這個起點,你應該建立你的形象的路徑。