blob: 8c77767544933e64a13d7905b41dcc83a039dc35 [file] [log] [blame] [view]
Minh T. Nguyen952218f2015-06-16 12:00:49 -04001Subsampling Scale Image View
David Morrisseya0bf8022014-05-30 14:08:31 +01002===========================
davemorrisseyb064b0b2013-08-26 09:45:26 -07003
David Morrissey71b94c22015-03-04 23:10:45 +00004A custom image view for Android, designed for photo galleries and displaying huge images (e.g. maps and building plans) without `OutOfMemoryError`s. Includes pinch to zoom, panning, rotation and animation support, and allows easy extension so you can add your own overlays and touch event detection.
David Morrisseyd4191862014-10-18 23:14:07 +01005
davemorrissey4fcb6132015-03-23 21:04:41 +00006The view optionally uses subsampling and tiles to support very large images - a low resolution base layer is loaded and as you zoom in, it is overlaid with smaller high resolution tiles for the visible area. This avoids holding too much data in memory. It's ideal for displaying large images while allowing you to zoom in to the high resolution details. You can disable tiling for smaller images and when displaying a bitmap object. There are some advantages and disadvantages to disabling tiling so to decide which is best, see [the wiki](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/02.-Displaying-images).
David Morrissey71b94c22015-03-04 23:10:45 +00007
davemorrissey55dadbb2015-03-22 19:16:07 +00008#### Guides
9
davemorrissey126eefa2015-03-22 19:18:54 +000010* [Releases & downloads](https://github.com/davemorrissey/subsampling-scale-image-view/releases)
davemorrissey0f4cd932015-03-23 20:12:12 +000011* [Installation and setup](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/01.-Setup)
12* [Image display notes & limitations](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/02.-Displaying-images)
13* [Using preview images](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/03.-Preview-images)
14* [Handling orientation changes](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/05.-Orientation-changes)
15* [Advanced configuration](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/07.-Configuration)
16* [Event handling](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/09.-Events)
17* [Animation](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/08.-Animation)
davemorrissey49fb9342015-03-23 22:24:29 +000018* [Extension](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/10.-Extension)
davemorrissey55dadbb2015-03-22 19:16:07 +000019
David Morrissey71b94c22015-03-04 23:10:45 +000020#### 2.x.x to 3.x.x migration
21
davemorrissey55dadbb2015-03-22 19:16:07 +000022Version 3.x.x includes breaking changes. Please view the [migration guide](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/X.--2.x.x-to-3.x.x-migration).
David Morrissey365ccab2014-07-31 00:08:41 +010023
David Morrisseyef41d8a2014-06-10 01:00:09 +010024#### Download the sample app
25
26[![Get it on Google Play](https://developer.android.com/images/brand/en_generic_rgb_wo_60.png)](https://play.google.com/store/apps/details?id=com.davemorrissey.labs.subscaleview.sample)
27
David Morrisseyd4191862014-10-18 23:14:07 +010028#### Hall of fame
David Morrissey0e895c22013-08-26 20:07:35 +010029
David Morrisseyd4191862014-10-18 23:14:07 +010030**Are you using this library in your app? Let me know and I'll add it to this list.**
31
davemorrissey529ab3e2015-06-06 10:58:18 +010032| [![Fourth Mate](https://lh3.ggpht.com/2ALnL-05ILKLwP9U8Dfy7n4iI54OlXeZG-rHf31FP5l8Bup9wws9wnSlyX56ShgzlQ=w100)](https://play.google.com/store/apps/details?id=com.sleetworks.serenity.android) | [![Sync for reddit](https://lh5.ggpht.com/eOcmQUHHFCXM5uiajTkTsak5sIB5eTLKXaKSGGGWi8TJ3edYtqz8EtvjlOto5eFYvoLb=w100)](https://play.google.com/store/apps/details?id=com.laurencedawson.reddit_sync) | [![Journey](https://lh3.ggpht.com/Mz6YqxKsLfVbjYVHj_3nfUxLe5Yvl9W4KO2sKnwud6hZl5mnGitm55PnILT2jx4Hafv6=w100)](https://play.google.com/store/apps/details?id=com.journey.app) | [![Clover](https://lh5.ggpht.com/Q8vw6LLyj3AjRev4ID3uvFUxnMp4ca4eBEaPlkupcK7cNn2xtVg-wIxVsKSJ-IIFaUM=w100)](https://play.google.com/store/apps/details?id=org.floens.chan) |
33|---|---|---|---|
34| **Fourth Mate** | **Sync for reddit** | **Journal** | **Clover** |
davemorrisseyee67ed72015-06-16 21:40:40 +010035| [![Tag Gallery](https://lh5.ggpht.com/mKch3_fgPYswBPmZ-qEvp91_fPKdbvN2UubCvUTDqy1sAaLJBzfFYETb-sJgPfCvDg=w100)](https://play.google.com/store/apps/details?id=me.snapdiary.us.taggallery) | [![nycTrans.it](https://lh5.ggpht.com/eDe_bnb2KVXd6fwjJDroWYfEs7Qy-ity93s4LnOwei3S8AGZIeJy8wwmjllt1TKciD4=w100)](https://play.google.com/store/apps/details?id=com.nyctrans.it) | [![RR File Locker](https://lh4.ggpht.com/taUucj91wLM_uLq-XMLo-9Urk4SeQYW1WO4oquJ_ynyJPrX7S0j0xoQ8k6q66ZElFg=w100)](https://play.google.com/store/apps/details?id=com.redrabbitsw.android.locker) | [![TransitMe NYC](https://lh3.googleusercontent.com/aErQHPHTn6TeqmGRHybIZoEE7uF1MwTXTN4upuIsMpJurwWGuF_9tAhaxspMvTBdGaqG=w100)](https://play.google.com/store/apps/details?id=com.transitme.app) |
36| **Tag Gallery** | **nycTrans.it** | **RR File Locker** | **TransitMe NYC** |
David Morrisseyd4191862014-10-18 23:14:07 +010037
David Morrissey36cc1252015-01-12 21:42:02 +000038## Features
David Morrissey0e895c22013-08-26 20:07:35 +010039
David Morrisseya0bf8022014-05-30 14:08:31 +010040#### Image display
David Morrissey365ccab2014-07-31 00:08:41 +010041
David Morrissey71b94c22015-03-04 23:10:45 +000042* Display images from assets, resources, the file system or bitmaps
David Morrisseya0bf8022014-05-30 14:08:31 +010043* Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
44* Manually rotate images in 90° increments
David Morrissey0d041ff2015-03-08 21:44:44 +000045* Display a region of the source image
46* Use a preview image while large images load
David Morrisseya0bf8022014-05-30 14:08:31 +010047* Swap images at runtime
David Morrissey36cc1252015-01-12 21:42:02 +000048* Use a custom bitmap decoder
David Morrissey0e895c22013-08-26 20:07:35 +010049
David Morrissey71b94c22015-03-04 23:10:45 +000050*With tiling enabled:*
David Morrissey365ccab2014-07-31 00:08:41 +010051
52* Display huge images, larger than can be loaded into memory
53* Show high resolution detail on zooming in
David Morrissey71b94c22015-03-04 23:10:45 +000054* Tested up to 20,000x20,000px, though larger images are slower
David Morrissey365ccab2014-07-31 00:08:41 +010055
David Morrisseya0bf8022014-05-30 14:08:31 +010056#### Gesture detection
davemorrissey55dadbb2015-03-22 19:16:07 +000057
David Morrisseya0bf8022014-05-30 14:08:31 +010058* One finger pan
59* Two finger pinch to zoom
davemorrisseya0336982015-02-23 21:49:23 +000060* Quick scale (one finger zoom)
David Morrisseya0bf8022014-05-30 14:08:31 +010061* Pan while zooming
62* Seamless switch between pan and zoom
63* Fling momentum after panning
David Morrissey77096ba2014-06-05 21:22:44 +010064* Double tap to zoom in and out
David Morrissey02ceb3d2014-05-30 20:48:51 +010065* Options to disable pan and/or zoom gestures
David Morrisseya0bf8022014-05-30 14:08:31 +010066
David Morrissey9f3fad12014-06-08 10:16:49 +010067#### Animation
davemorrissey55dadbb2015-03-22 19:16:07 +000068
David Morrissey9f3fad12014-06-08 10:16:49 +010069* Public methods for animating the scale and center
70* Customisable duration and easing
71* Optional uninterruptible animations
72
David Morrisseya0bf8022014-05-30 14:08:31 +010073#### Overridable event detection
74* Supports `OnClickListener` and `OnLongClickListener`
75* Supports interception of events using `GestureDetector` and `OnTouchListener`
76* Extend to add your own gestures
77
78#### Easy integration
79* Use within a `ViewPager` to create a photo gallery
80* Easily restore scale, center and orientation after screen rotation
81* Can be extended to add overlay graphics that move and scale with the image
82* Handles view resizing and `wrap_content` layout
83
davemorrissey55dadbb2015-03-22 19:16:07 +000084## Quick start
David Morrisseya0bf8022014-05-30 14:08:31 +010085
Minh T. Nguyen952218f2015-06-16 12:00:49 -040086**1)** Add `com.davemorrissey.labs:subsampling-scale-image-view:3.1.4` as a dependency in your build.gradle file.
David Morrissey365ccab2014-07-31 00:08:41 +010087
davemorrissey55dadbb2015-03-22 19:16:07 +000088**2)** Add the view to your layout XML.
David Morrisseya0bf8022014-05-30 14:08:31 +010089
90 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
91 android:layout_width="match_parent"
92 android:layout_height="match_parent" >
93
94 <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
95 android:id="@+id/imageView"
David Morrisseye11ee3e2014-05-30 14:09:41 +010096 android:layout_width="match_parent"
97 android:layout_height="match_parent"/>
David Morrisseya0bf8022014-05-30 14:08:31 +010098
Ed George86af5fa2015-06-29 17:34:47 +010099 </LinearLayout>
David Morrisseya0bf8022014-05-30 14:08:31 +0100100
davemorrissey55dadbb2015-03-22 19:16:07 +0000101**3)** Now, in your fragment or activity, set the image resource, asset name or file path.
David Morrisseya0bf8022014-05-30 14:08:31 +0100102
103 SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
David Morrissey71b94c22015-03-04 23:10:45 +0000104 imageView.setImage(ImageSource.resource(R.drawable.monkey));
David Morrissey36cc1252015-01-12 21:42:02 +0000105 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000106 imageView.setImage(ImageSource.asset("map.png"))
David Morrisseya0bf8022014-05-30 14:08:31 +0100107 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000108 imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));
David Morrisseya0bf8022014-05-30 14:08:31 +0100109
David Morrissey5833e302014-06-06 22:08:14 +0100110## About
111
David Morrissey71b94c22015-03-04 23:10:45 +0000112Copyright 2015 David Morrissey, and licensed under the Apache License, Version 2.0. No attribution is necessary but it's very much appreciated. Star this project if you like it, and send a link to your project on GitHub or app in Google Play if you'd like me to add it to this page.