# SubsamplingScaleImageView

public class SubsamplingScaleImageView

Displays an image subsampled as necessary to avoid loading too much image data into memory. After a pinch to zoom in, a set of image tiles subsampled at higher resolution are loaded and displayed over the base layer. During pinch and zoom, tiles off screen or higher/lower resolution than required are discarded from memory.

Tiles are no larger than the max supported bitmap size, so with large images tiling may be used even when zoomed out.

v prefixes - coordinates, translations and distances measured in screen (view) pixels s prefixes - coordinates, translations and distances measured in source image pixels (scaled)

## Constructors

SubsamplingScaleImageView
Link copied to clipboard
public void SubsamplingScaleImageView(Context context, AttributeSet attr)
public void SubsamplingScaleImageView(Context context)

## Types

AnimationBuilder
Link copied to clipboard
public final class AnimationBuilder
Builder class used to set additional options for a scale animation.
DefaultOnAnimationEventListener
Link copied to clipboard
public class DefaultOnAnimationEventListener implements SubsamplingScaleImageView.OnAnimationEventListener
Default implementation of OnAnimationEventListener for extension.
DefaultOnImageEventListener
Link copied to clipboard
public class DefaultOnImageEventListener implements SubsamplingScaleImageView.OnImageEventListener
Default implementation of OnImageEventListener for extension.
DefaultOnStateChangedListener
Link copied to clipboard
public class DefaultOnStateChangedListener implements SubsamplingScaleImageView.OnStateChangedListener
Default implementation of OnStateChangedListener.
OnAnimationEventListener
Link copied to clipboard
public interface OnAnimationEventListener
An event listener for animations, allows events to be triggered when an animation completes, is aborted by another animation starting, or is aborted by a touch event.
OnImageEventListener
Link copied to clipboard
public interface OnImageEventListener
An event listener, allowing subclasses and activities to be notified of significant events.
OnStateChangedListener
Link copied to clipboard
public interface OnStateChangedListener
An event listener, allowing activities to be notified of pan and zoom events.

## Properties

EASE_IN_OUT_QUAD
Link copied to clipboard
public final static int EASE_IN_OUT_QUAD
Quadratic ease in and out.
EASE_OUT_QUAD
Link copied to clipboard
public final static int EASE_OUT_QUAD
Quadratic ease out.
maxScale
Link copied to clipboard
public float maxScale
minScale
Link copied to clipboard
public float minScale
orientation
Link copied to clipboard
public int orientation
ORIENTATION_0
Link copied to clipboard
public final static int ORIENTATION_0
Display the image file in its native orientation.
ORIENTATION_180
Link copied to clipboard
public final static int ORIENTATION_180
Rotate the image 180 degrees.
ORIENTATION_270
Link copied to clipboard
public final static int ORIENTATION_270
Rotate the image 270 degrees clockwise.
ORIENTATION_90
Link copied to clipboard
public final static int ORIENTATION_90
Rotate the image 90 degrees clockwise.
ORIENTATION_USE_EXIF
Link copied to clipboard
public final static int ORIENTATION_USE_EXIF
Attempt to use EXIF information on the image to rotate it.
ORIGIN_ANIM
Link copied to clipboard
public final static int ORIGIN_ANIM
State change originated from animation.
ORIGIN_DOUBLE_TAP_ZOOM
Link copied to clipboard
public final static int ORIGIN_DOUBLE_TAP_ZOOM
State change originated from a double tap zoom anim.
ORIGIN_FLING
Link copied to clipboard
public final static int ORIGIN_FLING
State change originated from a fling momentum anim.
ORIGIN_TOUCH
Link copied to clipboard
public final static int ORIGIN_TOUCH
State change originated from touch gesture.
PAN_LIMIT_CENTER
Link copied to clipboard
public final static int PAN_LIMIT_CENTER
Allows the image to be panned until a corner reaches the center of the screen but no further.
PAN_LIMIT_INSIDE
Link copied to clipboard
public final static int PAN_LIMIT_INSIDE
Don't allow the image to be panned off screen.
PAN_LIMIT_OUTSIDE
Link copied to clipboard
public final static int PAN_LIMIT_OUTSIDE
Allows the image to be panned until it is just off screen, but no further.
preferredBitmapConfig
Link copied to clipboard
public static Config preferredBitmapConfig
scale
Link copied to clipboard
public float scale
SCALE_TYPE_CENTER_CROP
Link copied to clipboard
public final static int SCALE_TYPE_CENTER_CROP
Scale the image uniformly so that both dimensions of the image will be equal to or larger than the corresponding dimension of the view.
SCALE_TYPE_CENTER_INSIDE
Link copied to clipboard
public final static int SCALE_TYPE_CENTER_INSIDE
Scale the image so that both dimensions of the image will be equal to or less than the corresponding dimension of the view.
SCALE_TYPE_CUSTOM
Link copied to clipboard
public final static int SCALE_TYPE_CUSTOM
Scale the image so that both dimensions of the image will be equal to or less than the maxScale and equal to or larger than minScale.
SCALE_TYPE_START
Link copied to clipboard
public final static int SCALE_TYPE_START
Scale the image so that both dimensions of the image will be equal to or larger than the corresponding dimension of the view.
sHeight
Link copied to clipboard
public int sHeight
sWidth
Link copied to clipboard
public int sWidth
TILE_SIZE_AUTO
Link copied to clipboard
public final static int TILE_SIZE_AUTO
uri
Link copied to clipboard
public Uri uri
ZOOM_FOCUS_CENTER
Link copied to clipboard
public final static int ZOOM_FOCUS_CENTER
During zoom animation, move the point of the image that was tapped to the center of the screen.
ZOOM_FOCUS_CENTER_IMMEDIATE
Link copied to clipboard
public final static int ZOOM_FOCUS_CENTER_IMMEDIATE
Zoom in to and center the tapped point immediately without animating.
ZOOM_FOCUS_FIXED
Link copied to clipboard
public final static int ZOOM_FOCUS_FIXED
During zoom animation, keep the point of the image that was tapped in the same place, and scale the image around it.

## Functions

animateCenter
Link copied to clipboard
public SubsamplingScaleImageView.AnimationBuilder animateCenter(PointF sCenter)
Creates a panning animation builder, that when started will animate the image to place the given coordinates of the image in the center of the screen.
animateScale
Link copied to clipboard
public SubsamplingScaleImageView.AnimationBuilder animateScale(float scale)
Creates a scale animation builder, that when started will animate a zoom in or out.
animateScaleAndCenter
Link copied to clipboard
public SubsamplingScaleImageView.AnimationBuilder animateScaleAndCenter(float scale, PointF sCenter)
Creates a scale animation builder, that when started will animate a zoom in or out.
getAppliedOrientation
Link copied to clipboard
public final int getAppliedOrientation()
Returns the actual orientation of the image relative to the source file.
getCenter
Link copied to clipboard
public final PointF getCenter()
Returns the source point at the center of the view.
getMaxScale
Link copied to clipboard
public float getMaxScale()
Returns the maximum allowed scale.
getMinScale
Link copied to clipboard
public final float getMinScale()
Returns the minimum allowed scale.
getOrientation
Link copied to clipboard
public final int getOrientation()
Returns the orientation setting.
getPanRemaining
Link copied to clipboard
public final void getPanRemaining(RectF vTarget)
Calculate how much further the image can be panned in each direction.
getPreferredBitmapConfig
Link copied to clipboard
public static Config getPreferredBitmapConfig()
Get the current preferred configuration for decoding bitmaps.
getScale
Link copied to clipboard
public final float getScale()
Returns the current scale value.
getSHeight
Link copied to clipboard
public final int getSHeight()
Get source height, ignoring orientation.
getState
Link copied to clipboard
public final ImageViewState getState()
Get the current state of the view (scale, center, orientation) for restoration after rotate.
getSWidth
Link copied to clipboard
public final int getSWidth()
Get source width, ignoring orientation.
getUri
Link copied to clipboard
public Uri getUri()
Return the uri that has been set.
hasImage
Link copied to clipboard
public boolean hasImage()
Check if an image has been set.
isImageLoaded
Link copied to clipboard
public final boolean isImageLoaded()
Call to find whether the main image (base layer tiles where relevant) have been loaded.
isPanEnabled
Link copied to clipboard
public final boolean isPanEnabled()
Returns true if pan gesture detection is enabled.
isQuickScaleEnabled
Link copied to clipboard
public final boolean isQuickScaleEnabled()
Returns true if double tap &swipe to zoom is enabled.
isReady
Link copied to clipboard
public final boolean isReady()
Call to find whether the view is initialised, has dimensions, and will display an image on the next draw.
isZoomEnabled
Link copied to clipboard
public final boolean isZoomEnabled()
Returns true if zoom gesture detection is enabled.
onTouchEvent
Link copied to clipboard
public boolean onTouchEvent(MotionEvent event)
Handle touch events.
recycle
Link copied to clipboard
public void recycle()
Releases all resources the view is using and resets the state, nulling any fields that use significant memory.
resetScaleAndCenter
Link copied to clipboard
public final void resetScaleAndCenter()
Fully zoom out and return the image to the middle of the screen.
setBitmapAndFileUri
Link copied to clipboard
public final void setBitmapAndFileUri(Bitmap bitmap, Uri fileUri)
setBitmapDecoderClass
Link copied to clipboard
public final void setBitmapDecoderClass(Class<? extends ImageDecoder> bitmapDecoderClass)
Swap the default bitmap decoder implementation for one of your own.
setBitmapDecoderFactory
Link copied to clipboard
public final void setBitmapDecoderFactory(DecoderFactory<? extends ImageDecoder> bitmapDecoderFactory)
Swap the default bitmap decoder implementation for one of your own.
setBitmapFitX
Link copied to clipboard
public final void setBitmapFitX(Bitmap bitmap)
bitmap 展示以X轴为准,填充满X轴
setDebug
Link copied to clipboard
public final void setDebug(boolean debug)
Enables visual debugging, showing tile boundaries and sizes.
setDoubleTapZoomDpi
Link copied to clipboard
public final void setDoubleTapZoomDpi(int dpi)
A density aware alternative to setDoubleTapZoomScale; this allows you to express the scale the image will zoom in to when double tapped in terms of the image pixel density.
setDoubleTapZoomDuration
Link copied to clipboard
public final void setDoubleTapZoomDuration(int durationMs)
Set the duration of the double tap zoom animation.
setDoubleTapZoomScale
Link copied to clipboard
public final void setDoubleTapZoomScale(float doubleTapZoomScale)
Set the scale the image will zoom in to when double tapped.
setDoubleTapZoomStyle
Link copied to clipboard
public final void setDoubleTapZoomStyle(int doubleTapZoomStyle)
Set the type of zoom animation to be used for double taps.
setEagerLoadingEnabled
Link copied to clipboard
public void setEagerLoadingEnabled(boolean eagerLoadingEnabled)
Enable or disable eager loading of tiles that appear on screen during gestures or animations, while the gesture or animation is still in progress.
setExecutor
Link copied to clipboard
public void setExecutor(Executor executor)
Provide an Executor to be used for loading images.
setImage
Link copied to clipboard
public final void setImage(ImageSource imageSource)
Set the image source from a bitmap, resource, asset, file or other URI.
public final void setImage(ImageSource imageSource, ImageSource previewSource)
Set the image source from a bitmap, resource, asset, file or other URI, providing a preview image to be displayed until the full size image is loaded.
public final void setImage(ImageSource imageSource, ImageViewState state)
Set the image source from a bitmap, resource, asset, file or other URI, starting with a given orientation setting, scale and center.
public final void setImage(ImageSource imageSource, ImageSource previewSource, ImageViewState state)
Set the image source from a bitmap, resource, asset, file or other URI, providing a preview image to be displayed until the full size image is loaded, starting with a given orientation setting, scale and center.
setMaximumDpi
Link copied to clipboard
public final void setMaximumDpi(int dpi)
This is a screen density aware alternative to setMinScale; it allows you to express the minimum allowed scale in terms of the maximum pixel density.
setMaxScale
Link copied to clipboard
public final void setMaxScale(float maxScale)
Set the maximum scale allowed.
setMaxTileSize
Link copied to clipboard
public void setMaxTileSize(int maxPixels)
public void setMaxTileSize(int maxPixelsX, int maxPixelsY)
By default the View automatically calculates the optimal tile size.
setMinimumDpi
Link copied to clipboard
public final void setMinimumDpi(int dpi)
This is a screen density aware alternative to setMaxScale; it allows you to express the maximum allowed scale in terms of the minimum pixel density.
setMinimumScaleType
Link copied to clipboard
public final void setMinimumScaleType(int scaleType)
Set the minimum scale type.
setMinimumTileDpi
Link copied to clipboard
public void setMinimumTileDpi(int minimumTileDpi)
By default, image tiles are at least as high resolution as the screen.
setMinScale
Link copied to clipboard
public final void setMinScale(float minScale)
Set the minimum scale allowed.
setOnImageEventListener
Link copied to clipboard
public void setOnImageEventListener(SubsamplingScaleImageView.OnImageEventListener onImageEventListener)
Add a listener allowing notification of load and error events.
setOnLongClickListener
Link copied to clipboard
public void setOnLongClickListener(OnLongClickListener onLongClickListener)
setOnStateChangedListener
Link copied to clipboard
public void setOnStateChangedListener(SubsamplingScaleImageView.OnStateChangedListener onStateChangedListener)
Add a listener for pan and zoom events.
setOrientation
Link copied to clipboard
public final void setOrientation(int orientation)
Sets the image orientation.
setPanEnabled
Link copied to clipboard
public final void setPanEnabled(boolean panEnabled)
Enable or disable pan gesture detection.
setPanLimit
Link copied to clipboard
public final void setPanLimit(int panLimit)
Set the pan limiting style.
setPreferredBitmapConfig
Link copied to clipboard
public static void setPreferredBitmapConfig(Config preferredBitmapConfig)
Set a global preferred bitmap config shared by all view instances and applied to new instances initialised after the call is made.
setQuickScaleEnabled
Link copied to clipboard
public final void setQuickScaleEnabled(boolean quickScaleEnabled)
Enable or disable double tap &swipe to zoom.
setRegionDecoderClass
Link copied to clipboard
public final void setRegionDecoderClass(Class<? extends ImageRegionDecoder> regionDecoderClass)
Swap the default region decoder implementation for one of your own.
setRegionDecoderFactory
Link copied to clipboard
public final void setRegionDecoderFactory(DecoderFactory<? extends ImageRegionDecoder> regionDecoderFactory)
Swap the default region decoder implementation for one of your own.
setScaleAndCenter
Link copied to clipboard
public final void setScaleAndCenter(float scale, PointF sCenter)
Externally change the scale and translation of the source image.
setTileBackgroundColor
Link copied to clipboard
public final void setTileBackgroundColor(int tileBgColor)
Set a solid color to render behind tiles, useful for displaying transparent PNGs.
setZoomEnabled
Link copied to clipboard
public final void setZoomEnabled(boolean zoomEnabled)
Enable or disable zoom gesture detection.
sourceToViewCoord
Link copied to clipboard
public final PointF sourceToViewCoord(PointF sxy)
public final PointF sourceToViewCoord(PointF sxy, PointF vTarget)
public final PointF sourceToViewCoord(float sx, float sy)
public final PointF sourceToViewCoord(float sx, float sy, PointF vTarget)
Convert source coordinate to view coordinate.
viewToFileRect
Link copied to clipboard
public void viewToFileRect(Rect vRect, Rect fRect)
Converts a rectangle within the view to the corresponding rectangle from the source file, taking into account the current scale, translation, orientation and clipped region.
viewToSourceCoord
Link copied to clipboard
public final PointF viewToSourceCoord(PointF vxy)
public final PointF viewToSourceCoord(PointF vxy, PointF sTarget)
public final PointF viewToSourceCoord(float vx, float vy)
public final PointF viewToSourceCoord(float vx, float vy, PointF sTarget)
Convert screen coordinate to source coordinate.
visibleFileRect
Link copied to clipboard
public void visibleFileRect(Rect fRect)
Find the area of the source file that is currently visible on screen, taking into account the current scale, translation, orientation and clipped region.