Android ImageViewer 类支持捏合缩放和滚动

发布于 2024-10-15 21:19:17 字数 736 浏览 4 评论 0原文

我正在搜索一个 ImageViewer 库,它可以在我的应用程序中为给定的 URI 打开图像(由 Web 服务获取的图像已经存储在我的应用程序中的安全位置)。我真的很喜欢“Samsung Galaxy S”ImageViewer-Activity,因为它使用捏缩放和“滚动”垂直/水平。而且它在我的三星手机上缩放图片的速度非常快:)

我知道我可以以这样的意图打开图像:

Intent i = new Intent(Intent.ACTION_VIEW);  
i.setDataAndType(uri, "image/*");
startActivity(i);

正在调用最合适的查看器,当找不到任何查看器时,会引发 ActivityNotFoundException。太酷了!

但问题是我不允许打开具有外部意图的图像(出于安全目的)。即:用户不应该能够通过菜单选项将打开的图像保存到其外部 SD 卡或将此图片发送到其他服务(电子邮件/Twitter 等)。所以我必须编写自己的 ImageViewer 类(活动),只能在我的应用程序中调用...... 不幸的是,我不太擅长转换图像,那么是否有任何开源项目(或库)涵盖这个用例?

我已经问过谷歌并找到了这个 http://code.google.com/p/android-捏/但效果不是很好(而且它没有滚动功能)。

感谢您的提示:)

I am searching an ImageViewer library that opens an image in my application for a given URI (the image fetched by a webservice is already stored within my application in a secured place). I really like the "Samsung Galaxy S" ImageViewer-Activity because it uses pinch-zoom and "scrolling" vertical/horizontal. Also it scales the picture very fast on my samsung phone :)

I know that I can open an image with an intent like this:

Intent i = new Intent(Intent.ACTION_VIEW);  
i.setDataAndType(uri, "image/*");
startActivity(i);

The best suitable viewer is being called, when none is found an ActivityNotFoundException is raised. So thats cool!

But the problem is that I am not allowed to open an image with an external intent (for security purposes). i.e: The user should not have the posibility to save the opened image via a menu option to his external sd-card or send this picture to another service (email/twitter or s.o.). So I have to write my own ImageViewer-Class (Activity) that can only be called within my application...
Unfortunately I am not very skilled transforming images, so is there any open source project (or library) that covers this use case?

I already asked google and found this one http://code.google.com/p/android-pinch/ but it didnt work very well (also it has no scroll-functionality).

Thanks for your tips :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜血缘 2024-10-22 21:19:17

此时我也使用WebView。但这在概念上是错误的,WebView 不是用于显示图像的,它是用于显示网页内容的。 WebView 体积庞大且笨重。您限制对其进行定制。例如,我需要缩放,但我不想看到缩放控件,或者我想将它们移动到默认位置以外的其他位置。

因此,我搜索了这个问题并找到了一些解决方案:

UPDATE

Chris Banes 创建了很棒的库,它支持缩放图片的手势,请参阅上面的第一点

At this moment I'm too use WebView. But this is conceptually wrong, WebView is not for displaying images, it for displaying web content. WebView is bulky and cumbersome. You restricted in customizing it. For example, I need scaling, but I don't want to see zoom controls, or I want to move them in other place then default.

Therefore, I searched about this problem and found some solutions:

  • PhotoView widget from Chris Banes
  • Also, you can look at this tutorial from Sony Ericsson (sources available) and can implement your own widget: part1, part2, part3
  • And another one library ImageViewZoom at github

UPDATE

Chris Banes was created awesome library which supports gestures for zooming pictures, see first point above

扮仙女 2024-10-22 21:19:17

如果图像存储在本地或在线某处,处理图像的最简单方法是使用 WebView。 WebView支持捏合缩放等功能。

Java 示例:

String imageUrl = "file:///local/dir/image.jpg"; // http://example.com/image.jpg
WebView wv = (WebView) findViewById(R.id.yourwebview);
wv.getSettings().setBuiltInZoomControls(true);
wv.loadUrl(imageUrl);

XML 源:

<WebView android:id="@+id/yourwebview"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />

The easiest way to handle images is using a WebView, if the image is stored local or somewhere online. WebView supports pinch to zoom and other functions.

Example Java:

String imageUrl = "file:///local/dir/image.jpg"; // http://example.com/image.jpg
WebView wv = (WebView) findViewById(R.id.yourwebview);
wv.getSettings().setBuiltInZoomControls(true);
wv.loadUrl(imageUrl);

XML source:

<WebView android:id="@+id/yourwebview"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文