blob: a918dba7817674d1bf56121496de25f0c6c96d18 [file] [log] [blame] [view]
davemorrisseye7e9a6a2015-06-30 15:11:43 +01001Subsampling Scale Image View
David Morrisseya0bf8022014-05-30 14:08:31 +01002===========================
davemorrisseyb064b0b2013-08-26 09:45:26 -07003
David Morrisseycf2f5e92017-11-02 19:12:41 +00004[![Build Status](https://travis-ci.org/davemorrissey/subsampling-scale-image-view.svg?branch=master)](https://travis-ci.org/davemorrissey/subsampling-scale-image-view)
5
David Morrissey71b94c22015-03-04 23:10:45 +00006A 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 +01007
davemorrissey4fcb6132015-03-23 21:04:41 +00008The 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 +00009
davemorrissey55dadbb2015-03-22 19:16:07 +000010#### Guides
11
davemorrissey126eefa2015-03-22 19:18:54 +000012* [Releases & downloads](https://github.com/davemorrissey/subsampling-scale-image-view/releases)
davemorrissey0f4cd932015-03-23 20:12:12 +000013* [Installation and setup](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/01.-Setup)
14* [Image display notes & limitations](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/02.-Displaying-images)
15* [Using preview images](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/03.-Preview-images)
16* [Handling orientation changes](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/05.-Orientation-changes)
17* [Advanced configuration](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/07.-Configuration)
18* [Event handling](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/09.-Events)
19* [Animation](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/08.-Animation)
davemorrissey49fb9342015-03-23 22:24:29 +000020* [Extension](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/10.-Extension)
David Morrissey3fccc742017-11-16 14:57:46 +000021* [Reference (JavaDocs)](http://davemorrissey.github.io/subsampling-scale-image-view/javadoc/)
davemorrissey55dadbb2015-03-22 19:16:07 +000022
David Morrissey71b94c22015-03-04 23:10:45 +000023#### 2.x.x to 3.x.x migration
24
davemorrissey55dadbb2015-03-22 19:16:07 +000025Version 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 +010026
David Morrisseycf188f82017-11-16 12:58:43 +000027#### 3.8.0 migration
28
29Version 3.8.0 includes a default behaviour change. Image quality is now capped at 320dpi (approximately retina quality) instead of matching the screen's density, which results in high memory use and poor performance when displaying large images on very high density screens. The difference in quality is usually unnoticeable, especially with photos. Use `setMinimumTileDpi(int)` to override the default.
30
David Morrissey01028652017-11-17 18:03:50 +000031Support for SDK 10-13 has been dropped. The minimum SDK is now 14.
David Morrisseycf188f82017-11-16 12:58:43 +000032
David Morrisseyef41d8a2014-06-10 01:00:09 +010033#### Download the sample app
34
David Morrisseyed7bd392017-11-27 10:52:56 +000035[![Get it on Google Play](docs/images/google_play.png)](https://play.google.com/store/apps/details?id=com.davemorrissey.labs.subscaleview.sample)
David Morrisseyef41d8a2014-06-10 01:00:09 +010036
David Morrissey01028652017-11-17 18:03:50 +000037#### Demo
38
39![Demo](docs/images/demo.gif)
40
David Morrissey36cc1252015-01-12 21:42:02 +000041## Features
David Morrissey0e895c22013-08-26 20:07:35 +010042
David Morrisseya0bf8022014-05-30 14:08:31 +010043#### Image display
David Morrissey365ccab2014-07-31 00:08:41 +010044
David Morrissey71b94c22015-03-04 23:10:45 +000045* Display images from assets, resources, the file system or bitmaps
David Morrisseya0bf8022014-05-30 14:08:31 +010046* Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
47* Manually rotate images in 90° increments
David Morrissey0d041ff2015-03-08 21:44:44 +000048* Display a region of the source image
49* Use a preview image while large images load
David Morrisseya0bf8022014-05-30 14:08:31 +010050* Swap images at runtime
David Morrissey36cc1252015-01-12 21:42:02 +000051* Use a custom bitmap decoder
David Morrissey0e895c22013-08-26 20:07:35 +010052
David Morrissey71b94c22015-03-04 23:10:45 +000053*With tiling enabled:*
David Morrissey365ccab2014-07-31 00:08:41 +010054
55* Display huge images, larger than can be loaded into memory
56* Show high resolution detail on zooming in
David Morrissey71b94c22015-03-04 23:10:45 +000057* Tested up to 20,000x20,000px, though larger images are slower
David Morrissey365ccab2014-07-31 00:08:41 +010058
David Morrisseya0bf8022014-05-30 14:08:31 +010059#### Gesture detection
davemorrissey55dadbb2015-03-22 19:16:07 +000060
David Morrisseya0bf8022014-05-30 14:08:31 +010061* One finger pan
62* Two finger pinch to zoom
davemorrisseya0336982015-02-23 21:49:23 +000063* Quick scale (one finger zoom)
David Morrisseya0bf8022014-05-30 14:08:31 +010064* Pan while zooming
65* Seamless switch between pan and zoom
66* Fling momentum after panning
David Morrissey77096ba2014-06-05 21:22:44 +010067* Double tap to zoom in and out
David Morrissey02ceb3d2014-05-30 20:48:51 +010068* Options to disable pan and/or zoom gestures
David Morrisseya0bf8022014-05-30 14:08:31 +010069
David Morrissey9f3fad12014-06-08 10:16:49 +010070#### Animation
davemorrissey55dadbb2015-03-22 19:16:07 +000071
David Morrissey9f3fad12014-06-08 10:16:49 +010072* Public methods for animating the scale and center
73* Customisable duration and easing
74* Optional uninterruptible animations
75
David Morrisseya0bf8022014-05-30 14:08:31 +010076#### Overridable event detection
77* Supports `OnClickListener` and `OnLongClickListener`
78* Supports interception of events using `GestureDetector` and `OnTouchListener`
79* Extend to add your own gestures
80
81#### Easy integration
82* Use within a `ViewPager` to create a photo gallery
83* Easily restore scale, center and orientation after screen rotation
84* Can be extended to add overlay graphics that move and scale with the image
85* Handles view resizing and `wrap_content` layout
86
davemorrissey55dadbb2015-03-22 19:16:07 +000087## Quick start
David Morrisseya0bf8022014-05-30 14:08:31 +010088
David Morrisseycf188f82017-11-16 12:58:43 +000089**1)** Add `com.davemorrissey.labs:subsampling-scale-image-view:3.8.0` as a dependency in your build.gradle file.
David Morrissey365ccab2014-07-31 00:08:41 +010090
davemorrissey55dadbb2015-03-22 19:16:07 +000091**2)** Add the view to your layout XML.
David Morrisseya0bf8022014-05-30 14:08:31 +010092
93 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
94 android:layout_width="match_parent"
95 android:layout_height="match_parent" >
96
97 <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
98 android:id="@+id/imageView"
David Morrisseye11ee3e2014-05-30 14:09:41 +010099 android:layout_width="match_parent"
100 android:layout_height="match_parent"/>
David Morrisseya0bf8022014-05-30 14:08:31 +0100101
Ed George86af5fa2015-06-29 17:34:47 +0100102 </LinearLayout>
David Morrisseya0bf8022014-05-30 14:08:31 +0100103
David Morrissey93091802016-11-04 19:13:52 +0000104**3a)** Now, in your fragment or activity, set the image resource, asset name or file path.
David Morrisseya0bf8022014-05-30 14:08:31 +0100105
106 SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
David Morrissey71b94c22015-03-04 23:10:45 +0000107 imageView.setImage(ImageSource.resource(R.drawable.monkey));
David Morrissey36cc1252015-01-12 21:42:02 +0000108 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000109 imageView.setImage(ImageSource.asset("map.png"))
David Morrisseya0bf8022014-05-30 14:08:31 +0100110 // ... or ...
David Morrissey71b94c22015-03-04 23:10:45 +0000111 imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));
David Morrisseya0bf8022014-05-30 14:08:31 +0100112
David Morrissey93091802016-11-04 19:13:52 +0000113**3b)** Or, if you have a `Bitmap` object in memory, load it into the view. This is unsuitable for large images because it bypasses subsampling - you may get an `OutOfMemoryError`.
114
David Morrissey3d3df1c2016-11-04 19:14:54 +0000115 SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
116 imageView.setImage(ImageSource.bitmap(bitmap));
David Morrissey93091802016-11-04 19:13:52 +0000117
David Morrissey5833e302014-06-06 22:08:14 +0100118## About
119
David Morrissey93091802016-11-04 19:13:52 +0000120Copyright 2016 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!