Search code examples
androidscrolltransformimageviewpinch

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


Solution

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