Subsampling Zoom Image View


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

Subsampling Scale Image View

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

2.x.x to 3.x.x migration

Version 3.x.x includes breaking changes. Please view the migration guide.

Download the sample app

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 com.davemorrissey.labs:subsampling-scale-image-view:3.7.2 as a dependency in your build.gradle file.

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));
 

About

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

Resources

GearLoadingLayout widget for android that can be used as a progress bar, snack bar or yourself to create your own arrangements for their needs.

This library help you to achieve popular tint effect from view.

A simple photo browser for Android applications.

RxObservableDiskCache is a library to save the results of Singles or single value Observables request on a local disk cache, so the next time the same request is called you get an immediate result.

Diagonalify is the library to create diagonal cut view on imageviews

A quick settings tile to quickly set the animator duration scale.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes