Android ImageViewer class supporting Pinch-Zoom and Scrolling

tim.kaufner picture tim.kaufner · Feb 3, 2011 · Viewed 20.6k times · Source

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 :)

Answer

Dmitriy Tarasov picture Dmitriy Tarasov · Jul 19, 2012

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