blob: b972768ad22d5c4881f38ae294692d2ec03af4a2 [file] [log] [blame] [view]
davemorrisseya0336982015-02-23 21:49:23 +00001Subsampling 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
David Morrissey71b94c22015-03-04 23:10:45 +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 below.
7
davemorrissey55dadbb2015-03-22 19:16:07 +00008#### Guides
9
10* [Installation and setup](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/1.-Setup)
11* [Image display notes & limitations](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/2.-Displaying-images)
12* [2.x.x to 3.x.x migration](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/X.--2.x.x-to-3.x.x-migration)
13
David Morrissey71b94c22015-03-04 23:10:45 +000014#### 2.x.x to 3.x.x migration
15
davemorrissey55dadbb2015-03-22 19:16:07 +000016Version 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 +010017
David Morrisseyef41d8a2014-06-10 01:00:09 +010018#### Download the sample app
19
20[![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)
21
David Morrisseyd4191862014-10-18 23:14:07 +010022#### Hall of fame
David Morrissey0e895c22013-08-26 20:07:35 +010023
David Morrisseyd4191862014-10-18 23:14:07 +010024**Are you using this library in your app? Let me know and I'll add it to this list.**
25
davemorrisseye2d8c462015-02-24 19:21:58 +000026| [![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) |
davemorrisseyc7e461c2015-02-24 15:33:01 +000027|---|---|---|
28| **Fourth Mate** | **Sync for reddit** | **Journal** |
29| [![Clover](https://lh5.ggpht.com/Q8vw6LLyj3AjRev4ID3uvFUxnMp4ca4eBEaPlkupcK7cNn2xtVg-wIxVsKSJ-IIFaUM=w100)](https://play.google.com/store/apps/details?id=org.floens.chan) | [![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) |
30| **Clover** | **Tag Gallery** | **nycTrans.it** |
David Morrisseyd4191862014-10-18 23:14:07 +010031
David Morrissey36cc1252015-01-12 21:42:02 +000032## Features
David Morrissey0e895c22013-08-26 20:07:35 +010033
David Morrisseya0bf8022014-05-30 14:08:31 +010034#### Image display
David Morrissey365ccab2014-07-31 00:08:41 +010035
David Morrissey71b94c22015-03-04 23:10:45 +000036* Display images from assets, resources, the file system or bitmaps
David Morrisseya0bf8022014-05-30 14:08:31 +010037* Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
38* Manually rotate images in 90° increments
David Morrissey0d041ff2015-03-08 21:44:44 +000039* Display a region of the source image
40* Use a preview image while large images load
David Morrisseya0bf8022014-05-30 14:08:31 +010041* Swap images at runtime
David Morrissey36cc1252015-01-12 21:42:02 +000042* Use a custom bitmap decoder
David Morrissey0e895c22013-08-26 20:07:35 +010043
David Morrissey71b94c22015-03-04 23:10:45 +000044*With tiling enabled:*
David Morrissey365ccab2014-07-31 00:08:41 +010045
46* Display huge images, larger than can be loaded into memory
47* Show high resolution detail on zooming in
David Morrissey71b94c22015-03-04 23:10:45 +000048* Tested up to 20,000x20,000px, though larger images are slower
David Morrissey365ccab2014-07-31 00:08:41 +010049
David Morrisseya0bf8022014-05-30 14:08:31 +010050#### Gesture detection
davemorrissey55dadbb2015-03-22 19:16:07 +000051
David Morrisseya0bf8022014-05-30 14:08:31 +010052* One finger pan
53* Two finger pinch to zoom
davemorrisseya0336982015-02-23 21:49:23 +000054* Quick scale (one finger zoom)
David Morrisseya0bf8022014-05-30 14:08:31 +010055* Pan while zooming
56* Seamless switch between pan and zoom
57* Fling momentum after panning
David Morrissey77096ba2014-06-05 21:22:44 +010058* Double tap to zoom in and out
David Morrissey02ceb3d2014-05-30 20:48:51 +010059* Options to disable pan and/or zoom gestures
David Morrisseya0bf8022014-05-30 14:08:31 +010060
David Morrissey9f3fad12014-06-08 10:16:49 +010061#### Animation
davemorrissey55dadbb2015-03-22 19:16:07 +000062
David Morrissey9f3fad12014-06-08 10:16:49 +010063* Public methods for animating the scale and center
64* Customisable duration and easing
65* Optional uninterruptible animations
66
David Morrisseya0bf8022014-05-30 14:08:31 +010067#### Overridable event detection
68* Supports `OnClickListener` and `OnLongClickListener`
69* Supports interception of events using `GestureDetector` and `OnTouchListener`
70* Extend to add your own gestures
71
72#### Easy integration
73* Use within a `ViewPager` to create a photo gallery
74* Easily restore scale, center and orientation after screen rotation
75* Can be extended to add overlay graphics that move and scale with the image
76* Handles view resizing and `wrap_content` layout
77
davemorrissey55dadbb2015-03-22 19:16:07 +000078## Quick start
David Morrisseya0bf8022014-05-30 14:08:31 +010079
davemorrissey55dadbb2015-03-22 19:16:07 +000080**1)** Add `com.davemorrissey.labs:subsampling-scale-image-view:3.1.2` as a dependency in your build.gradle file.
David Morrissey365ccab2014-07-31 00:08:41 +010081
davemorrissey55dadbb2015-03-22 19:16:07 +000082**2)** Add the view to your layout XML.
David Morrisseya0bf8022014-05-30 14:08:31 +010083
84 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
85 android:layout_width="match_parent"
86 android:layout_height="match_parent" >
87
88 <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
89 android:id="@+id/imageView"
David Morrisseye11ee3e2014-05-30 14:09:41 +010090 android:layout_width="match_parent"
91 android:layout_height="match_parent"/>
David Morrisseya0bf8022014-05-30 14:08:31 +010092
93 </RelativeLayout>
94
davemorrissey55dadbb2015-03-22 19:16:07 +000095**3)** Now, in your fragment or activity, set the image resource, asset name or file path.
David Morrisseya0bf8022014-05-30 14:08:31 +010096
97 SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
David Morrissey71b94c22015-03-04 23:10:45 +000098 imageView.setImage(ImageSource.resource(R.drawable.monkey));
David Morrissey36cc1252015-01-12 21:42:02 +000099 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000100 imageView.setImage(ImageSource.asset("map.png"))
David Morrisseya0bf8022014-05-30 14:08:31 +0100101 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000102 imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));
David Morrisseya0bf8022014-05-30 14:08:31 +0100103
David Morrissey5833e302014-06-06 22:08:14 +0100104## About
105
David Morrissey71b94c22015-03-04 23:10:45 +0000106Copyright 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.