xref: /aosp_15_r20/external/subsampling-scale-image-view/README.md (revision b596130c744e645677984e0225561b580e00a40b)
1*b596130cSAndroid Build Coastguard WorkerSubsampling Scale Image View
2*b596130cSAndroid Build Coastguard Worker===========================
3*b596130cSAndroid Build Coastguard Worker
4*b596130cSAndroid Build Coastguard Worker[![Build Status](https://travis-ci.org/davemorrissey/subsampling-scale-image-view.svg?branch=master)](https://travis-ci.org/davemorrissey/subsampling-scale-image-view)
5*b596130cSAndroid Build Coastguard Worker
6*b596130cSAndroid Build Coastguard WorkerA 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.
7*b596130cSAndroid Build Coastguard Worker
8*b596130cSAndroid Build Coastguard WorkerThe 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).
9*b596130cSAndroid Build Coastguard Worker
10*b596130cSAndroid Build Coastguard Worker#### Guides
11*b596130cSAndroid Build Coastguard Worker
12*b596130cSAndroid Build Coastguard Worker* [Releases & downloads](https://github.com/davemorrissey/subsampling-scale-image-view/releases)
13*b596130cSAndroid Build Coastguard Worker* [Installation and setup](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/01.-Setup)
14*b596130cSAndroid Build Coastguard Worker* [Image display notes & limitations](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/02.-Displaying-images)
15*b596130cSAndroid Build Coastguard Worker* [Using preview images](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/03.-Preview-images)
16*b596130cSAndroid Build Coastguard Worker* [Handling orientation changes](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/05.-Orientation-changes)
17*b596130cSAndroid Build Coastguard Worker* [Advanced configuration](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/07.-Configuration)
18*b596130cSAndroid Build Coastguard Worker* [Event handling](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/09.-Events)
19*b596130cSAndroid Build Coastguard Worker* [Animation](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/08.-Animation)
20*b596130cSAndroid Build Coastguard Worker* [Extension](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/10.-Extension)
21*b596130cSAndroid Build Coastguard Worker* [Reference (JavaDocs)](http://davemorrissey.github.io/subsampling-scale-image-view/javadoc/)
22*b596130cSAndroid Build Coastguard Worker
23*b596130cSAndroid Build Coastguard Worker#### Migration guides
24*b596130cSAndroid Build Coastguard Worker
25*b596130cSAndroid Build Coastguard WorkerVersions 3.9.0, 3.8.0 and 3.0.0 contain breaking changes. Migration instructions can be found [in the wiki](https://github.com/davemorrissey/subsampling-scale-image-view/wiki/X.--Migration-guides).
26*b596130cSAndroid Build Coastguard Worker
27*b596130cSAndroid Build Coastguard Worker#### Download the sample app
28*b596130cSAndroid Build Coastguard Worker
29*b596130cSAndroid Build Coastguard Worker[![Get it on Google Play](docs/images/google_play.png)](https://play.google.com/store/apps/details?id=com.davemorrissey.labs.subscaleview.sample)
30*b596130cSAndroid Build Coastguard Worker
31*b596130cSAndroid Build Coastguard Worker[Kotlin Sample App on GitHub](https://github.com/davemorrissey/ssiv-kotlin-sample)
32*b596130cSAndroid Build Coastguard Worker
33*b596130cSAndroid Build Coastguard Worker#### Demo
34*b596130cSAndroid Build Coastguard Worker
35*b596130cSAndroid Build Coastguard Worker![Demo](docs/images/demo.gif)
36*b596130cSAndroid Build Coastguard Worker
37*b596130cSAndroid Build Coastguard Worker## Features
38*b596130cSAndroid Build Coastguard Worker
39*b596130cSAndroid Build Coastguard Worker#### Image display
40*b596130cSAndroid Build Coastguard Worker
41*b596130cSAndroid Build Coastguard Worker* Display images from assets, resources, the file system or bitmaps
42*b596130cSAndroid Build Coastguard Worker* Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
43*b596130cSAndroid Build Coastguard Worker* Manually rotate images in 90° increments
44*b596130cSAndroid Build Coastguard Worker* Display a region of the source image
45*b596130cSAndroid Build Coastguard Worker* Use a preview image while large images load
46*b596130cSAndroid Build Coastguard Worker* Swap images at runtime
47*b596130cSAndroid Build Coastguard Worker* Use a custom bitmap decoder
48*b596130cSAndroid Build Coastguard Worker
49*b596130cSAndroid Build Coastguard Worker*With tiling enabled:*
50*b596130cSAndroid Build Coastguard Worker
51*b596130cSAndroid Build Coastguard Worker* Display huge images, larger than can be loaded into memory
52*b596130cSAndroid Build Coastguard Worker* Show high resolution detail on zooming in
53*b596130cSAndroid Build Coastguard Worker* Tested up to 20,000x20,000px, though larger images are slower
54*b596130cSAndroid Build Coastguard Worker
55*b596130cSAndroid Build Coastguard Worker#### Gesture detection
56*b596130cSAndroid Build Coastguard Worker
57*b596130cSAndroid Build Coastguard Worker* One finger pan
58*b596130cSAndroid Build Coastguard Worker* Two finger pinch to zoom
59*b596130cSAndroid Build Coastguard Worker* Quick scale (one finger zoom)
60*b596130cSAndroid Build Coastguard Worker* Pan while zooming
61*b596130cSAndroid Build Coastguard Worker* Seamless switch between pan and zoom
62*b596130cSAndroid Build Coastguard Worker* Fling momentum after panning
63*b596130cSAndroid Build Coastguard Worker* Double tap to zoom in and out
64*b596130cSAndroid Build Coastguard Worker* Options to disable pan and/or zoom gestures
65*b596130cSAndroid Build Coastguard Worker
66*b596130cSAndroid Build Coastguard Worker#### Animation
67*b596130cSAndroid Build Coastguard Worker
68*b596130cSAndroid Build Coastguard Worker* Public methods for animating the scale and center
69*b596130cSAndroid Build Coastguard Worker* Customisable duration and easing
70*b596130cSAndroid Build Coastguard Worker* Optional uninterruptible animations
71*b596130cSAndroid Build Coastguard Worker
72*b596130cSAndroid Build Coastguard Worker#### Overridable event detection
73*b596130cSAndroid Build Coastguard Worker* Supports `OnClickListener` and `OnLongClickListener`
74*b596130cSAndroid Build Coastguard Worker* Supports interception of events using `GestureDetector` and `OnTouchListener`
75*b596130cSAndroid Build Coastguard Worker* Extend to add your own gestures
76*b596130cSAndroid Build Coastguard Worker
77*b596130cSAndroid Build Coastguard Worker#### Easy integration
78*b596130cSAndroid Build Coastguard Worker* Use within a `ViewPager` to create a photo gallery
79*b596130cSAndroid Build Coastguard Worker* Easily restore scale, center and orientation after screen rotation
80*b596130cSAndroid Build Coastguard Worker* Can be extended to add overlay graphics that move and scale with the image
81*b596130cSAndroid Build Coastguard Worker* Handles view resizing and `wrap_content` layout
82*b596130cSAndroid Build Coastguard Worker
83*b596130cSAndroid Build Coastguard Worker## Quick start
84*b596130cSAndroid Build Coastguard Worker
85*b596130cSAndroid Build Coastguard Worker**1)** Add this library as a dependency in your app's build.gradle file.
86*b596130cSAndroid Build Coastguard Worker
87*b596130cSAndroid Build Coastguard Worker    dependencies {
88*b596130cSAndroid Build Coastguard Worker        implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
89*b596130cSAndroid Build Coastguard Worker    }
90*b596130cSAndroid Build Coastguard Worker
91*b596130cSAndroid Build Coastguard Worker**2)** Add the view to your layout XML.
92*b596130cSAndroid Build Coastguard Worker
93*b596130cSAndroid Build Coastguard Worker    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
94*b596130cSAndroid Build Coastguard Worker        android:layout_width="match_parent"
95*b596130cSAndroid Build Coastguard Worker        android:layout_height="match_parent" >
96*b596130cSAndroid Build Coastguard Worker
97*b596130cSAndroid Build Coastguard Worker        <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
98*b596130cSAndroid Build Coastguard Worker            android:id="@+id/imageView"
99*b596130cSAndroid Build Coastguard Worker            android:layout_width="match_parent"
100*b596130cSAndroid Build Coastguard Worker            android:layout_height="match_parent"/>
101*b596130cSAndroid Build Coastguard Worker
102*b596130cSAndroid Build Coastguard Worker    </LinearLayout>
103*b596130cSAndroid Build Coastguard Worker
104*b596130cSAndroid Build Coastguard Worker**3a)** Now, in your fragment or activity, set the image resource, asset name or file path.
105*b596130cSAndroid Build Coastguard Worker
106*b596130cSAndroid Build Coastguard Worker    SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
107*b596130cSAndroid Build Coastguard Worker    imageView.setImage(ImageSource.resource(R.drawable.monkey));
108*b596130cSAndroid Build Coastguard Worker    // ... or ...
109*b596130cSAndroid Build Coastguard Worker    imageView.setImage(ImageSource.asset("map.png"))
110*b596130cSAndroid Build Coastguard Worker    // ... or ...
111*b596130cSAndroid Build Coastguard Worker    imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));
112*b596130cSAndroid Build Coastguard Worker
113*b596130cSAndroid Build Coastguard Worker**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*b596130cSAndroid Build Coastguard Worker
115*b596130cSAndroid Build Coastguard Worker    SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
116*b596130cSAndroid Build Coastguard Worker    imageView.setImage(ImageSource.bitmap(bitmap));
117*b596130cSAndroid Build Coastguard Worker
118*b596130cSAndroid Build Coastguard Worker## Photo credits
119*b596130cSAndroid Build Coastguard Worker
120*b596130cSAndroid Build Coastguard Worker* San Martino by Luca Bravo, via [unsplash.com](https://unsplash.com/photos/lWAOc0UuJ-A)
121*b596130cSAndroid Build Coastguard Worker* Swiss Road by Ludovic Fremondiere, via [unsplash.com](https://unsplash.com/photos/3XN-BNRDUyY)
122*b596130cSAndroid Build Coastguard Worker
123*b596130cSAndroid Build Coastguard Worker## About
124*b596130cSAndroid Build Coastguard Worker
125*b596130cSAndroid Build Coastguard WorkerCopyright 2018 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!
126