Android的:如何显示在一个web视图一个位图? [英] Android: How to Display a Bitmap in a WebView?

查看:96
本文介绍了Android的:如何显示在一个web视图一个位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的web视图用于显示地图状图像,由于内置的​​平移和缩放功能。不过,我需要叠加在地图图像上的一些其他信息(标志等)在某些点上,并显示了这一切。

I'm using a WebView for displaying a map-like image, due to the built-in panning and zooming functionality. However, I need to overlay some other information (markers etc) at certain points on the map image, and display all of this.

所以,我把我的基本地图图像作为一个位图,并覆盖我的其他图片上的(使用Canvas和更多的位图),给我所有的信息最后的位图。因为我需要编辑的图像在运行时,我不能使用pre-发文件。实现位图的叠加是没有问题的,问题是我不知道如何轻松地平移和缩放功能,显示生成的图像。

So I take my base map image as a Bitmap, and overlay my other images over that (using Canvas and more Bitmaps), giving me a final Bitmap with all the info. Because I need to edit the image at runtime, I can't use a pre-made file. Implementing the overlaying of bitmaps is not the problem, the problem is that I don't know how to easily display the resulting image with pan and zoom capabilities.

有没有一种方法来显示使用的WebView位图?或者有什么其他的建议?

Is there a way to display a Bitmap using a WebView? Or any other suggestions?

推荐答案

使用链接从itsrajesh4uguys,我创造了这个code片断:

Using the link from itsrajesh4uguys, I've created this code snippet:

// 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", "");

这篇关于Android的:如何显示在一个web视图一个位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆