Subsampling Scale Image View

repository·master·Indexed 27 days ago

https://github.com/davemorrissey/subsampling-scale-image-view

An Android library for displaying extremely large images, such as maps or building plans, without triggering OutOfMemoryErrors. It utilizes a tiling system to load high-resolution details only for the visible area during zooming. Supports loading images from resources, assets, file system URIs, and bitmaps.

Tokens
532
Snippets
2
Records
3
Agent score
43%

What's inside Subsampling Scale Image View

  1. Install Subsampling Scale Image View

    master

    Add the library as a dependency in your app's build.gradle file.

    For standard projects, use com.davemorrissey.labs:subsampling-scale-image-view.

    If your project uses AndroidX, you must use the androidx artifact name instead.

    // Standard dependency
    dependencies {
        implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
    }
    
    // AndroidX dependency
    dependencies {
        implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
    }
  2. Add SubsamplingScaleImageView to layout XML

    master

    Include the SubsamplingScaleImageView in your layout XML file. Ensure you provide a unique android:id to reference it in your code.

    <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>
  3. Load images into SubsamplingScaleImageView

    master

    Use the setImage() method with an ImageSource to load images from various sources.

    Supported sources:

    • Resources (R.drawable)
    • Assets
    • File system URIs
    • Bitmaps (Note: Loading a Bitmap directly bypasses subsampling and may cause OutOfMemoryError for large images).

    Note: When using tiling (the default for large images), the view loads a low-resolution base layer and overlays high-resolution tiles as the user zooms in to prevent memory issues.