blob: f90506ecf7c2641386817e5028a6fb342fd300c0 [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)
davemorrisseyed1f8502015-03-22 19:24:05 +000013* [Handling orientation changes](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/5.-Orientation-changes)
davemorrisseyf9e0d2d2015-03-22 22:16:28 +000014* [Advanced configuration](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/7.-Configuration)
davemorrissey55dadbb2015-03-22 19:16:07 +000015
David Morrissey71b94c22015-03-04 23:10:45 +000016#### 2.x.x to 3.x.x migration
17
davemorrissey55dadbb2015-03-22 19:16:07 +000018Version 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 +010019
David Morrisseyef41d8a2014-06-10 01:00:09 +010020#### Download the sample app
21
22[![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)
23
David Morrisseyd4191862014-10-18 23:14:07 +010024#### Hall of fame
David Morrissey0e895c22013-08-26 20:07:35 +010025
David Morrisseyd4191862014-10-18 23:14:07 +010026**Are you using this library in your app? Let me know and I'll add it to this list.**
27
davemorrisseye2d8c462015-02-24 19:21:58 +000028| [![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 +000029|---|---|---|
30| **Fourth Mate** | **Sync for reddit** | **Journal** |
31| [![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) |
32| **Clover** | **Tag Gallery** | **nycTrans.it** |
David Morrisseyd4191862014-10-18 23:14:07 +010033
David Morrissey36cc1252015-01-12 21:42:02 +000034## Features
David Morrissey0e895c22013-08-26 20:07:35 +010035
David Morrisseya0bf8022014-05-30 14:08:31 +010036#### Image display
David Morrissey365ccab2014-07-31 00:08:41 +010037
David Morrissey71b94c22015-03-04 23:10:45 +000038* Display images from assets, resources, the file system or bitmaps
David Morrisseya0bf8022014-05-30 14:08:31 +010039* Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
40* Manually rotate images in 90° increments
David Morrissey0d041ff2015-03-08 21:44:44 +000041* Display a region of the source image
42* Use a preview image while large images load
David Morrisseya0bf8022014-05-30 14:08:31 +010043* Swap images at runtime
David Morrissey36cc1252015-01-12 21:42:02 +000044* Use a custom bitmap decoder
David Morrissey0e895c22013-08-26 20:07:35 +010045
David Morrissey71b94c22015-03-04 23:10:45 +000046*With tiling enabled:*
David Morrissey365ccab2014-07-31 00:08:41 +010047
48* Display huge images, larger than can be loaded into memory
49* Show high resolution detail on zooming in
David Morrissey71b94c22015-03-04 23:10:45 +000050* Tested up to 20,000x20,000px, though larger images are slower
David Morrissey365ccab2014-07-31 00:08:41 +010051
David Morrisseya0bf8022014-05-30 14:08:31 +010052#### Gesture detection
davemorrissey55dadbb2015-03-22 19:16:07 +000053
David Morrisseya0bf8022014-05-30 14:08:31 +010054* One finger pan
55* Two finger pinch to zoom
davemorrisseya0336982015-02-23 21:49:23 +000056* Quick scale (one finger zoom)
David Morrisseya0bf8022014-05-30 14:08:31 +010057* Pan while zooming
58* Seamless switch between pan and zoom
59* Fling momentum after panning
David Morrissey77096ba2014-06-05 21:22:44 +010060* Double tap to zoom in and out
David Morrissey02ceb3d2014-05-30 20:48:51 +010061* Options to disable pan and/or zoom gestures
David Morrisseya0bf8022014-05-30 14:08:31 +010062
David Morrissey9f3fad12014-06-08 10:16:49 +010063#### Animation
davemorrissey55dadbb2015-03-22 19:16:07 +000064
David Morrissey9f3fad12014-06-08 10:16:49 +010065* Public methods for animating the scale and center
66* Customisable duration and easing
67* Optional uninterruptible animations
68
David Morrisseya0bf8022014-05-30 14:08:31 +010069#### Overridable event detection
70* Supports `OnClickListener` and `OnLongClickListener`
71* Supports interception of events using `GestureDetector` and `OnTouchListener`
72* Extend to add your own gestures
73
74#### Easy integration
75* Use within a `ViewPager` to create a photo gallery
76* Easily restore scale, center and orientation after screen rotation
77* Can be extended to add overlay graphics that move and scale with the image
78* Handles view resizing and `wrap_content` layout
79
davemorrissey55dadbb2015-03-22 19:16:07 +000080## Quick start
David Morrisseya0bf8022014-05-30 14:08:31 +010081
davemorrissey55dadbb2015-03-22 19:16:07 +000082**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 +010083
davemorrissey55dadbb2015-03-22 19:16:07 +000084**2)** Add the view to your layout XML.
David Morrisseya0bf8022014-05-30 14:08:31 +010085
86 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
87 android:layout_width="match_parent"
88 android:layout_height="match_parent" >
89
90 <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
91 android:id="@+id/imageView"
David Morrisseye11ee3e2014-05-30 14:09:41 +010092 android:layout_width="match_parent"
93 android:layout_height="match_parent"/>
David Morrisseya0bf8022014-05-30 14:08:31 +010094
95 </RelativeLayout>
96
davemorrissey55dadbb2015-03-22 19:16:07 +000097**3)** Now, in your fragment or activity, set the image resource, asset name or file path.
David Morrisseya0bf8022014-05-30 14:08:31 +010098
99 SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
David Morrissey71b94c22015-03-04 23:10:45 +0000100 imageView.setImage(ImageSource.resource(R.drawable.monkey));
David Morrissey36cc1252015-01-12 21:42:02 +0000101 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000102 imageView.setImage(ImageSource.asset("map.png"))
David Morrisseya0bf8022014-05-30 14:08:31 +0100103 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000104 imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));
David Morrisseya0bf8022014-05-30 14:08:31 +0100105
David Morrissey5833e302014-06-06 22:08:14 +0100106## About
107
David Morrissey71b94c22015-03-04 23:10:45 +0000108Copyright 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.