Skip to content

Commit 36cc125

Browse files
committed
Updated readme for 2.3.0
1 parent f06b6c0 commit 36cc125

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

README.md

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Subsampling Zoom Image View
22
===========================
33

4-
Custom image views for Android with pinch to zoom, panning, rotation and animation support, with easy extension so you can add your own overlays and touch event detection.
4+
Custom image views 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.
55

6-
This library includes two classes, `ScaleImageView` and `SubsamplingScaleImageView`. `SubsamplingScaleImageView` is best for large images but doesn't support display of `Bitmap` objects or resources, and `ScaleImageView` supports `Bitmap` objects but not subsampling or large images. To decide which is best for you, see below.
6+
This library includes two view classes. `SubsamplingScaleImageView` uses subsampling and tiles to support large images - as you zoom in, the low resolution initial image is overlaid with smaller high resolution tiles to avoid holding too much data in memory. It's ideal for displaying large images while allowing you to zoom in to the high resolution details. `ScaleImageView` doesn't subsample images but can display `Bitmap` objects and supports all the same features. To decide which is best for you, see below.
77

88
#### Download the sample app
99

@@ -17,28 +17,23 @@ This library includes two classes, `ScaleImageView` and `SubsamplingScaleImageVi
1717
| ------------- | ------------- | ------------- | ------------- |
1818
| **Fourth Mate** | **Journal** | **Clover** | **Tag Gallery** |
1919

20-
#### About
21-
22-
`SubsamplingScaleImageView` uses subsampling and tiles to support large images. While zooming in, the
23-
low resolution, full size base layer is overlaid with smaller tiles at least as high resolution as the screen, and
24-
tiles are loaded and discarded during panning to avoid holding too much bitmap data in memory. This is ideal for use in image gallery apps where the size of the images may be large enough to require subsampling, and where
25-
pinch to zoom is required to view the high resolution detail.
26-
27-
*These views don't extend `ImageView` and aren't intended as a general purpose replacement for it. They're specialised for the display of photos and other large images, not the display of 9-patches, shapes and the other types of drawable that ImageView supports.*
20+
## Features
2821

2922
#### Image display
3023

31-
* Display images from assets or the file system
24+
* Display images from assets, resources or the file system
3225
* Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
3326
* Manually rotate images in 90° increments
3427
* Swap images at runtime
28+
* Use a custom bitmap decoder
3529

3630
*`SubsamplingScaleImageView` only:*
3731

3832
* Display huge images, larger than can be loaded into memory
3933
* Show high resolution detail on zooming in
4034
* Tested up to 20,000x13,000px, though larger images are slower
4135

36+
*These views don't extend `ImageView` and aren't intended as a general purpose replacement for it. They're specialised for the display of photos and other large images, not the display of 9-patches, shapes and the other types of drawable that ImageView supports.*
4237

4338
#### Gesture detection
4439
* One finger pan
@@ -67,10 +62,10 @@ pinch to zoom is required to view the high resolution detail.
6762

6863
#### Limitations
6964
* `SubsamplingScaleImageView` requires SDK 10 (Gingerbread).
70-
* `SubsamplingScaleImageView` cannot decode an image from resources or display a `Bitmap` object - the image file needs to be in assets or external storage.
71-
* `SubsamplingScaleImageView` cannot display grayscale PNGs on Android Lollipop, due to bugs in the skia library and/or BitmapRegionDecoder. Earlier versions of Android also have issues displaying some grayscale PNGs, but not all. I have reported these bugs to Google.
65+
* `SubsamplingScaleImageView` cannot display a `Bitmap` object - the image file needs to be in assets, resources or external storage.
66+
* `SubsamplingScaleImageView` cannot display grayscale PNGs on Android Lollipop, due to bugs in the skia library and/or BitmapRegionDecoder. Earlier versions of Android also have issues displaying some grayscale PNGs, but not all. I have reported these bugs to Google. For a workaround, see the section on custom bitmap decoders below.
7267
* These views do not extend ImageView so attributes including android:tint, android:scaleType and android:src are not supported.
73-
* Images stored in assets cannot be rotated based on EXIF, you'll need to do it manually. You probably know the orientation of your own assets :-)
68+
* Images stored in resources and assets cannot be rotated based on EXIF, you'll need to do it manually. You probably know the orientation of your own files :-)
7469

7570
## Which view is best?
7671

@@ -89,18 +84,11 @@ Use `ScaleImageView` if:
8984
* Your images are no larger than 2048px, or you are able to scale them down.
9085
* You need to support devices older than SDK 10.
9186

92-
## Quality notes
93-
94-
Images are decoded as dithered RGB_565 bitmaps by default, because this requires half as much memory as ARGB_8888. For most
95-
JPGs you won't notice the difference in quality. If you are displaying large PNGs with alpha channels, Android will probably
96-
decode them as ARGB_8888, and this may cause `OutOfMemoryError`s. **If possible, remove the alpha channel from PNGs larger than about 2,000x2,000.**
97-
This allows them to be decoded as RGB_565.
98-
99-
## Basic setup
87+
## Installation
10088

10189
Add the library to your app using one of these methods:
10290

103-
* Add `com.davemorrissey.labs:subsampling-scale-image-view:2.2.1` as a dependency in your build.gradle file
91+
* Add `com.davemorrissey.labs:subsampling-scale-image-view:2.3.0` as a dependency in your build.gradle file
10492
* *or* download the library aar file from the releases page and add to your app manually
10593
* *or* clone the project and import the library subproject as a module in your app
10694
* *or* clone the project and copy the resources and classes from `com.davemorrissey.labs.subscaleview` into your project
@@ -118,12 +106,14 @@ Add the view to your layout XML as shown below. Normally you should set width an
118106

119107
</RelativeLayout>
120108

121-
Now, in your fragment or activity, set the image asset name or file path.
109+
Now, in your fragment or activity, set the image resource, asset name or file path.
122110

123111
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
112+
imageView.setImageResource(R.drawable.monkey);
113+
// ... or ...
124114
imageView.setImageAsset("map.png");
125115
// ... or ...
126-
imageView.setImageFile("/sdcard/DCIM/DSCM00123.JPG");
116+
imageView.setImageUri("/sdcard/DCIM/DSCM00123.JPG");
127117

128118
That's it! Keep reading for some more options.
129119

@@ -177,12 +167,29 @@ If you want the current scale, center and orientation to be preserved when the s
177167
}
178168
}
179169

170+
## Custom bitmap decoders
171+
172+
Android's `BitmapRegionDecoder` class is based on the Skia library. Some users have reported problems with this library, particularly when displaying grayscale JPGs. Unfortunately it seems to be less reliable in recent versions of Android. If you don't control the format of the images displayed in your app (for example, they are user generated content) you may require a more reliable decoder.
173+
174+
To use your own decoder based on a different library, implement the `ImageRegionDecoder` class (do not include a constructor) and enable it using this call:
175+
176+
imageView.setDecoderClass(MyImageRegionDecoder.class);
177+
178+
As an example, see the [`RapidImageRegionDecoder`](https://github.com/davemorrissey/subsampling-scale-image-view/blob/master/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/decoders/RapidImageRegionDecoder.java) class, which is based on [RapidDecoder](https://github.com/suckgamony/RapidDecoder). This library is better at decoding grayscale JPG images but does not handle large images as well as `BitmapRegionDecoder` - it is significantly slower and more likely to throw out of memory errors. It appears to be very fast and reliable for PNG images. If you can detect the size and type of an image before displaying it, you can use different decoders for different images to get the best results.
179+
180+
Whenever possible, convert your images to a format Android's Skia library can support, and test with a variety of devices.
181+
182+
## Quality notes
183+
184+
Images are decoded as dithered RGB_565 bitmaps by default, because this requires half as much memory as ARGB_8888. For most
185+
JPGs you won't notice the difference in quality. If you are displaying large PNGs with alpha channels, Android will probably
186+
decode them as ARGB_8888, and this may cause `OutOfMemoryError`s. **If possible, remove the alpha channel from PNGs larger than about 2,000x2,000.**
187+
This allows them to be decoded as RGB_565.
188+
180189
## Extending functionality
181190

182191
Take a look at the sample app for examples of classes that overlay graphics on top of the image so that they move and scale with it. `FreehandView` adds event detection, capturing only the touch events it needs so pan and zoom still work normally.
183192

184193
## About
185194

186-
Copyright 2014 David Morrissey, and licensed under the Apache License, Version 2.0. No attribution is necessary but it's very much appreciated. Star this project to show your gratitude.
187-
188-
This project started life as a way of showing very large images (e.g. a large building floor plan) with gestures to pan and zoom, with support for extensions that showed overlays (location pins, annotations) aligned with the image. It's grown massively, but for the moment I am keeping everything in one class to prevent subclasses and extensions breaking the assumptions (or violating invariants) on which the class depends.
195+
Copyright 2014 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.

0 commit comments

Comments
 (0)