Skip to content
davemorrissey edited this page Mar 23, 2015 · 7 revisions

About

This is a custom image view for Android, designed for photo galleries and displaying huge images. It includes all the standard gestures for zooming and panning images, and provides some extra useful features for animating the image position and scale and rotating the image.

The view is highly configurable, and designed for extension from the ground up. You can easily add your own overlays anchored to points on your image, and customise event detection. See the sample app and its source code for some examples.

The aim of this library is to solve some of the common problems when displaying large images in Android:

  • "Bitmap too large to be uploaded into a texture" errors caused by attempting to display images over 2048px wide or high. The view will automatically load images larger than this limit in tiles so no single bitmap is too large to display.
  • OutOfMemoryErrors caused by loading a large image into memory without subsampling. The view subsamples images, then loads high resolution tiles for the visible area as the user zooms in.

This view doesn't extend ImageView and isn't intended as a general purpose replacement for it. It's specialised for the display of photos and other large images, not the display of 9-patches, shapes and the other types of drawable that ImageView supports.

Features

Image display

  • Display images from assets, resources, the file system or bitmaps
  • Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
  • Manually rotate images in 90° increments
  • Display a region of the source image
  • Use a preview image while large images load
  • Swap images at runtime
  • Use a custom bitmap decoder

With tiling enabled:

  • Display huge images, larger than can be loaded into memory
  • Show high resolution detail on zooming in
  • Tested up to 20,000x20,000px, though larger images are slower

Gesture detection

  • One finger pan
  • Two finger pinch to zoom
  • Quick scale (one finger zoom)
  • Pan while zooming
  • Seamless switch between pan and zoom
  • Fling momentum after panning
  • Double tap to zoom in and out
  • Options to disable pan and/or zoom gestures

Animation

  • Public methods for animating the scale and center
  • Customisable duration and easing
  • Optional uninterruptible animations

Overridable event detection

  • Supports OnClickListener and OnLongClickListener
  • Supports interception of events using GestureDetector and OnTouchListener
  • Extend to add your own gestures

Easy integration

  • Use within a ViewPager to create a photo gallery
  • Easily restore scale, center and orientation after screen rotation
  • Can be extended to add overlay graphics that move and scale with the image
  • Handles view resizing and wrap_content layout