Android: use WebView to load large images from resources

I need to use WebView to load large images (about 3500 x 3500 pixels) from resources

I've done a lot of research on stack overflow, but none of the answers are useful to me. I think this may be the problem of using assets in Android 4.0

My current code is as follows:

@H_404_9@WebView webView = (WebView)findViewById(R.id.myWebView);
webView.loadUrl("file:///android_asset/test.html");

Test.html looks like:

@H_404_9@<html>

  <table>

    <tr>

      <td>

        <img src="testimage.png" width="3500px" alt="TestAlt">

      </td>

    </tr>

  </table>

</html>

Testimage.png and test.html are both in the asset. After testing on my physical Android device, I get:

Logcat as required:

@H_404_9@I/webclipboard: clipservice:       android.sec.clipboard.ClipboardExManager@43ac41b0
V/webkit: BrowserFrame constructor:  this=Handler (android.webkit.BrowserFrame) {43ac3dc8}
D/WebView: loadUrlImpl: called
D/webcore: CORE loadUrl: called
D/webkit: Firewall not null
D/webkit: euler: isUrlBlocked = false
D/chromium: UnkNown chromium error: -6
I/GATE: <GATE-M>DEV_ACTION_ERROR</GATE-M>
V/webkit: reportError errorCode(-1) desc(There was a network error)
I/GATE: <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
I/Adreno200-EGLSUB: <ConfigWindowMatch:2136>: Format RGBA_8888.
D/WebView: onSizeChanged - w:480 h:0
D/WebView: onSizeChanged - w:480 h:446

resolvent:

Find the answer here:

https://stackoverflow.com/a/7480245/2060140

@H_404_9@webview.getSettings().setBuiltInZoomControls(true);
webview.loadDataWithBaseURL("file:///android_asset/", "<img src='file:///android_res/drawable/example.png' />", "text/html", "utf-8", null);

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>