Android:如何在WebView中显示位图?

bre*_*bin 7 android bitmap webview

由于内置的​​平移和缩放功能,我使用WebView显示类似地图的图像.但是,我需要在地图图像的某些点上叠加一些其他信息(标记等),并显示所有这些信息.

所以我把我的基本地图图像作为一个位图,然后将我的其他图像覆盖(使用Canvas和更多位图),给我一个包含所有信息的最终位图.因为我需要在运行时编辑图像,所以我不能使用预制文件.实现位图的重叠不是问题,问题是我不知道如何使用平移和缩放功能轻松显示生成的图像.

有没有办法使用WebView显示位图?还是其他任何建议?

pet*_*tos 25

使用itsrajesh4uguys中的链接,我创建了这段代码:

// Desired Bitmap and the html code, where you want to place it
Bitmap bitmap = YOUR_BITMAP;
String html="<html><body><img src='{IMAGE_PLACEHOLDER}' /></body></html>";

// Convert bitmap to Base64 encoded image for web
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String imgageBase64 = Base64.encodeToString(byteArray, Base64.DEFAULT);
    String image = "data:image/png;base64," + imgageBase64;

// Use image for the img src parameter in your html and load to webview
html = html.replace("{IMAGE_PLACEHOLDER}", image);
webview.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", "");
Run Code Online (Sandbox Code Playgroud)