MCPcopy
hub / github.com/davemorrissey/subsampling-scale-image-view

github.com/davemorrissey/subsampling-scale-image-view @v3.10.0 sqlite

repository ↗ · DeepWiki ↗ · release v3.10.0 ↗
360 symbols 983 edges 34 files 174 documented · 48%
README

Subsampling Scale Image View

Build Status

A custom image view for Android, designed for photo galleries and displaying huge images (e.g. maps and building plans) without OutOfMemoryErrors. Includes pinch to zoom, panning, rotation and animation support, and allows easy extension so you can add your own overlays and touch event detection.

The 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.

Guides

Migration guides

Versions 3.9.0, 3.8.0 and 3.0.0 contain breaking changes. Migration instructions can be found in the wiki.

Download the sample app

Get it on Google Play

Kotlin Sample App on GitHub

Demo

Demo

Features

Image display

  • Display images from assets, resources, the file system or bitmaps
  • Automatically rotate images from the file system (e.g. the camera or gallery) according to EXIF
  • Manually rotate images in 90° increments
  • Display a region of the source image
  • Use a preview image while large images load
  • Swap images at runtime
  • Use a custom bitmap decoder

With tiling enabled:

  • Display huge images, larger than can be loaded into memory
  • Show high resolution detail on zooming in
  • Tested up to 20,000x20,000px, though larger images are slower

Gesture detection

  • One finger pan
  • Two finger pinch to zoom
  • Quick scale (one finger zoom)
  • Pan while zooming
  • Seamless switch between pan and zoom
  • Fling momentum after panning
  • Double tap to zoom in and out
  • Options to disable pan and/or zoom gestures

Animation

  • Public methods for animating the scale and center
  • Customisable duration and easing
  • Optional uninterruptible animations

Overridable event detection

  • Supports OnClickListener and OnLongClickListener
  • Supports interception of events using GestureDetector and OnTouchListener
  • Extend to add your own gestures

Easy integration

  • Use within a ViewPager to create a photo gallery
  • Easily restore scale, center and orientation after screen rotation
  • Can be extended to add overlay graphics that move and scale with the image
  • Handles view resizing and wrap_content layout

Quick start

1) Add this library as a dependency in your app's build.gradle file.

dependencies {
    implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
}

2) Add the view to your layout XML.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

3a) Now, in your fragment or activity, set the image resource, asset name or file path.

SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
imageView.setImage(ImageSource.resource(R.drawable.monkey));
// ... or ...
imageView.setImage(ImageSource.asset("map.png"))
// ... or ...
imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));

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.

SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
imageView.setImage(ImageSource.bitmap(bitmap));

Photo credits

About

Copyright 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!

Extension points exported contracts — how you extend this code

ImageRegionDecoder (Interface)
Interface for image decoding classes, allowing the default android.graphics.BitmapRegionDecoder based on the Ski [4 implementers]
library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/ImageRegionDecoder.java
OnAnimationEventListener (Interface)
An event listener for animations, allows events to be triggered when an animation completes, is aborted by another anima [2 …
library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
OnImageEventListener (Interface)
An event listener, allowing subclasses and activities to be notified of significant events. [2 implementers]
library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
OnStateChangedListener (Interface)
An event listener, allowing activities to be notified of pan and zoom events. Initialisation and calls made by your code [2 …
library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
ImageDecoder (Interface)
Interface for image decoding classes, allowing the default android.graphics.BitmapFactory based on the Skia libr [2 implementers]
library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/ImageDecoder.java

Core symbols most depended-on inside this repo

sWidth
called by 24
library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
sHeight
called by 24
library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
px
called by 19
library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
setImage
called by 14
library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
getRequiredRotation
called by 14
library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
recycle
called by 14
library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/ImageRegionDecoder.java
fitToBounds
called by 13
library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
asset
called by 13
library/src/main/java/com/davemorrissey/labs/subscaleview/ImageSource.java

Shape

Method 308
Class 44
Interface 6
Function 2

Languages

Java99%
TypeScript1%

Modules by API surface

library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java165 symbols
library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/SkiaPooledImageRegionDecoder.java26 symbols
library/src/main/java/com/davemorrissey/labs/subscaleview/ImageSource.java21 symbols
sample/src/main/java/com/davemorrissey/labs/subscaleview/test/AbstractPagesActivity.java12 symbols
sample/src/main/java/com/davemorrissey/labs/subscaleview/test/AbstractFragmentsActivity.java10 symbols
sample/src/main/java/com/davemorrissey/labs/subscaleview/test/viewpager/ViewPagerActivity.java9 symbols
sample/src/main/java/com/davemorrissey/labs/subscaleview/test/viewpager/VerticalViewPager.java8 symbols
sample/src/main/java/com/davemorrissey/labs/subscaleview/test/extension/views/FreehandView.java7 symbols
sample/src/main/java/com/davemorrissey/labs/subscaleview/test/eventhandlingadvanced/AdvancedEventHandlingActivity.java7 symbols
library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/SkiaImageRegionDecoder.java7 symbols
sample/src/main/java/com/davemorrissey/labs/subscaleview/test/animation/AnimationActivity.java6 symbols
sample/src/main/java/com/davemorrissey/labs/subscaleview/test/MainActivity.java6 symbols

For agents

$ claude mcp add subsampling-scale-image-view \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact