あなたはそれを誤解している。それを行うには2つの方法があり、それはその画像を何が受け取っているかによって異なります。
ケース1:バイト配列を返したい。この場合、Javascriptで処理して文字列に解析し、webViewのタグのsrcフィールドに割り当てる必要があります。
File imagefile = new File(otherPath);
FileInputStream fis = null;
try {
fis = new FileInputStream(imagefile);
finall = fis;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//PNG OR THE FORMAT YOU WANT
bi.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] data = baos.toByteArray();
InputStream is = new ByteArrayInputStream(finaldata);
return new WebResourceResponse("text/html", "UTF-8", is);
ケース2:アクティビティのすべてを解析し、完全なhtmlコードを渡すので、webViewには、このデータで更新されるinnerHTMLプロパティがあります。
File imagefile = new File(otherPath);
FileInputStream fis = null;
try {
fis = new FileInputStream(imagefile);
finall = fis;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//PNG OR THE FORMAT YOU WANT
bi.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] data = baos.toByteArray();
String image64 = Base64.encodeToString(data, Base64.DEFAULT);
String customHtml = "<html><body><h1>Hello, WebView</h1>" +
"<h2><img src=\"data:image/jpeg;base64," + image64 + "\" /></img></h2></body></html>";
InputStream is = new ByteArrayInputStream(finaldata);
return new WebResourceResponse("text/html", "UTF-8", is);
画像をロードしたいだけの場合は、いつでも実行できますwebView.loadData(String data, String mimeType, String encoding)
それがお役に立てば幸いです、私はちょうどこれで作業するようになりました