blob: 2e9a3984c5b4fed55e87ecb49c7854482771d6d5 [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
davemorrissey126eefa2015-03-22 19:18:54 +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/2.-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)
davemorrissey55dadbb2015-03-22 19:16:07 +000011* [Installation and setup](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/1.-Setup)
12* [Image display notes & limitations](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/2.-Displaying-images)
13* [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)
14
David Morrissey71b94c22015-03-04 23:10:45 +000015#### 2.x.x to 3.x.x migration
16
davemorrissey55dadbb2015-03-22 19:16:07 +000017Version 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 +010018
David Morrisseyef41d8a2014-06-10 01:00:09 +010019#### Download the sample app
20
21[![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)
22
David Morrisseyd4191862014-10-18 23:14:07 +010023#### Hall of fame
David Morrissey0e895c22013-08-26 20:07:35 +010024
David Morrisseyd4191862014-10-18 23:14:07 +010025**Are you using this library in your app? Let me know and I'll add it to this list.**
26
davemorrisseye2d8c462015-02-24 19:21:58 +000027| [![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 +000028|---|---|---|
29| **Fourth Mate** | **Sync for reddit** | **Journal** |
30| [![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) |
31| **Clover** | **Tag Gallery** | **nycTrans.it** |
David Morrisseyd4191862014-10-18 23:14:07 +010032
David Morrissey36cc1252015-01-12 21:42:02 +000033## Features
David Morrissey0e895c22013-08-26 20:07:35 +010034
David Morrisseya0bf8022014-05-30 14:08:31 +010035#### Image display
David Morrissey365ccab2014-07-31 00:08:41 +010036
David Morrissey71b94c22015-03-04 23:10:45 +000037* Display images from assets, resources, the file system or bitmaps
David Morrisseya0bf8022014-05-30 14:08:31 +010038* Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
39* Manually rotate images in 90° increments
David Morrissey0d041ff2015-03-08 21:44:44 +000040* Display a region of the source image
41* Use a preview image while large images load
David Morrisseya0bf8022014-05-30 14:08:31 +010042* Swap images at runtime
David Morrissey36cc1252015-01-12 21:42:02 +000043* Use a custom bitmap decoder
David Morrissey0e895c22013-08-26 20:07:35 +010044
David Morrissey71b94c22015-03-04 23:10:45 +000045*With tiling enabled:*
David Morrissey365ccab2014-07-31 00:08:41 +010046
47* Display huge images, larger than can be loaded into memory
48* Show high resolution detail on zooming in
David Morrissey71b94c22015-03-04 23:10:45 +000049* Tested up to 20,000x20,000px, though larger images are slower
David Morrissey365ccab2014-07-31 00:08:41 +010050
David Morrisseya0bf8022014-05-30 14:08:31 +010051#### Gesture detection
davemorrissey55dadbb2015-03-22 19:16:07 +000052
David Morrisseya0bf8022014-05-30 14:08:31 +010053* One finger pan
54* Two finger pinch to zoom
davemorrisseya0336982015-02-23 21:49:23 +000055* Quick scale (one finger zoom)
David Morrisseya0bf8022014-05-30 14:08:31 +010056* Pan while zooming
57* Seamless switch between pan and zoom
58* Fling momentum after panning
David Morrissey77096ba2014-06-05 21:22:44 +010059* Double tap to zoom in and out
David Morrissey02ceb3d2014-05-30 20:48:51 +010060* Options to disable pan and/or zoom gestures
David Morrisseya0bf8022014-05-30 14:08:31 +010061
David Morrissey9f3fad12014-06-08 10:16:49 +010062#### Animation
davemorrissey55dadbb2015-03-22 19:16:07 +000063
David Morrissey9f3fad12014-06-08 10:16:49 +010064* Public methods for animating the scale and center
65* Customisable duration and easing
66* Optional uninterruptible animations
67
David Morrisseya0bf8022014-05-30 14:08:31 +010068#### Overridable event detection
69* Supports `OnClickListener` and `OnLongClickListener`
70* Supports interception of events using `GestureDetector` and `OnTouchListener`
71* Extend to add your own gestures
72
73#### Easy integration
74* Use within a `ViewPager` to create a photo gallery
75* Easily restore scale, center and orientation after screen rotation
76* Can be extended to add overlay graphics that move and scale with the image
77* Handles view resizing and `wrap_content` layout
78
davemorrissey55dadbb2015-03-22 19:16:07 +000079## Quick start
David Morrisseya0bf8022014-05-30 14:08:31 +010080
davemorrissey55dadbb2015-03-22 19:16:07 +000081**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 +010082
davemorrissey55dadbb2015-03-22 19:16:07 +000083**2)** Add the view to your layout XML.
David Morrisseya0bf8022014-05-30 14:08:31 +010084
85 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
86 android:layout_width="match_parent"
87 android:layout_height="match_parent" >
88
89 <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
90 android:id="@+id/imageView"
David Morrisseye11ee3e2014-05-30 14:09:41 +010091 android:layout_width="match_parent"
92 android:layout_height="match_parent"/>
David Morrisseya0bf8022014-05-30 14:08:31 +010093
94 </RelativeLayout>
95
davemorrissey55dadbb2015-03-22 19:16:07 +000096**3)** Now, in your fragment or activity, set the image resource, asset name or file path.
David Morrisseya0bf8022014-05-30 14:08:31 +010097
98 SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
David Morrissey71b94c22015-03-04 23:10:45 +000099 imageView.setImage(ImageSource.resource(R.drawable.monkey));
David Morrissey36cc1252015-01-12 21:42:02 +0000100 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000101 imageView.setImage(ImageSource.asset("map.png"))
David Morrisseya0bf8022014-05-30 14:08:31 +0100102 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000103 imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));
David Morrisseya0bf8022014-05-30 14:08:31 +0100104
David Morrissey5833e302014-06-06 22:08:14 +0100105## About
106
David Morrissey71b94c22015-03-04 23:10:45 +0000107Copyright 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.