Android ImageViewer class supporting Pinch-Zoom and Scrolling

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

Answers


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" />

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


Need Your Help

Datetime.now as TimeSpan value?

c# datetime timespan seconds

I need the current Datetime minus myDate1 in seconds.

Node.js Mongoose.js string to ObjectId function

mongodb node.js mongoose

Is there a function to turn a string into an objectId in node using mongoose? The schema specifies that something is an ObjectId, but when it is saved from a string, mongo tells me it is still just a