Android:让 WebView 显示位图的最简单方法?
我有一些从存储在位图变量中的远程源加载的图像,我想显示它们。除了在这些图像之间切换之外,用户还应该能够缩放和平移它们。我的第一个想法是以某种方式通过意图将它们传递到内置图库应用程序,但这似乎不可能。 在多个地方建议的解决方案是使用 WebView,因为它已经支持缩放和平移。 我的问题是我的位图数据如何进入 WebView?我是否必须先将其写入文件,稍后必须再次删除该文件,还是有更简单的方法?
或者是否有更好的方法来实现我的主要目标,即将位图数据显示为可缩放和平移的图像?
I have some images that I loaded from a remote source stored in Bitmap variables and I want to display them. In addition to switching between these images the user should also be able to zoom and pan them. My first idea was to somehow pass them via an intent to the built-in gallery application but this doesn't seem to be possible.
A solution that is suggested in several places is using a WebView since it already supports zooming and panning.
My question is how does my Bitmap data get into the WebView? Do I have to write it to a file first, which I would have to remove again later, or is there an easier way?
Or are there even better ways to accomplish my main goal, which is displaying Bitmap data as zoomable and panable images?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 webview 直接远程查看您的图像。您不再需要将图像保存在文件中。
这是一个示例代码片段。
关于切换图片,只需更改url的值并再次调用webview的loadData即可。
You can just use webview to directly view your image remotely. You do not need to save anymore the image in a file.
Here is a sample code snippet.
About switching images, you can just change the value of the url and call the loadData again of the webview.
毕竟我对 WebView 不满意,所以我最终创建了自己的图像查看 Activity。有关我的操作方法的更多说明,请参阅这篇有关 Google 群组的文章。
I wasn't satisfied with WebView after all so I ended up creating my own image viewing Activity. Further descriptions on how I did it can be found in this post on google groups.