我正在使用以下代码在webview上加载pdf文件
try {
imageByteArray =loadFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"/sample.pdf");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
webview = (WebView)findViewById(R.id.webView1);
String image64 = Base64.encodeToString(imageByteArray, Base64.DEFAULT);
String imgTag = "<img src=\"data:image/jpeg;base64," + image64 + "\" />" ;
webview.getSettings().setBuiltInZoomControls(true);
webview.setInitialScale(30);
WebSettings webSettings = webview.getSettings();
webSettings.setUseWideViewPort(true);
webview.loadData(imgTag, "text/html", "utf-8");
但在将字节代码转换为字符串
时获得 Outofmemory异常问题:
1.如何将大字节代码加载到字符串类型
2.我可以使用其他数据类型在webview中显示字节数组
见这一行
"<imgsrc=\"data:image/jpeg;base64," + image64 + "\" />"
我必须给字符串image64。或者有其他选择吗?