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

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

Types

Link copied to clipboard
public final class AnimationBuilder
Builder class used to set additional options for a scale animation.
Link copied to clipboard
Link copied to clipboard
Default implementation of OnImageEventListener for extension.
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.
Link copied to clipboard
public interface OnImageEventListener
An event listener, allowing subclasses and activities to be notified of significant events.
Link copied to clipboard
public interface OnStateChangedListener
An event listener, allowing activities to be notified of pan and zoom events.

Properties

Link copied to clipboard
public final static int EASE_IN_OUT_QUAD
Quadratic ease in and out.
Link copied to clipboard
public final static int EASE_OUT_QUAD
Quadratic ease out.
Link copied to clipboard
public float maxScale
Link copied to clipboard
public float minScale
Link copied to clipboard
public int orientation
Link copied to clipboard
public final static int ORIENTATION_0
Display the image file in its native orientation.
Link copied to clipboard
public final static int ORIENTATION_180
Rotate the image 180 degrees.
Link copied to clipboard
public final static int ORIENTATION_270
Rotate the image 270 degrees clockwise.
Link copied to clipboard
public final static int ORIENTATION_90
Rotate the image 90 degrees clockwise.
Link copied to clipboard
public final static int ORIENTATION_USE_EXIF
Attempt to use EXIF information on the image to rotate it.
Link copied to clipboard
public final static int ORIGIN_ANIM
State change originated from animation.
Link copied to clipboard
public final static int ORIGIN_DOUBLE_TAP_ZOOM
State change originated from a double tap zoom anim.
Link copied to clipboard
public final static int ORIGIN_FLING
State change originated from a fling momentum anim.
Link copied to clipboard
public final static int ORIGIN_TOUCH
State change originated from touch gesture.
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.
Link copied to clipboard
public final static int PAN_LIMIT_INSIDE
Don't allow the image to be panned off screen.
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.
Link copied to clipboard
public static Config preferredBitmapConfig
Link copied to clipboard
public float scale
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.
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.
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.
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.
Link copied to clipboard
public int sHeight
Link copied to clipboard
public int sWidth
Link copied to clipboard
public final static int TILE_SIZE_AUTO
Link copied to clipboard
public Uri uri
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.
Link copied to clipboard
public final static int ZOOM_FOCUS_CENTER_IMMEDIATE
Zoom in to and center the tapped point immediately without animating.
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

Link copied to clipboard
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.
Link copied to clipboard
Creates a scale animation builder, that when started will animate a zoom in or out.
Link copied to clipboard
Creates a scale animation builder, that when started will animate a zoom in or out.
Link copied to clipboard
public final int getAppliedOrientation()
Returns the actual orientation of the image relative to the source file.
Link copied to clipboard
public final PointF getCenter()
Returns the source point at the center of the view.
Link copied to clipboard
public float getMaxScale()
Returns the maximum allowed scale.
Link copied to clipboard
public final float getMinScale()
Returns the minimum allowed scale.
Link copied to clipboard
public final int getOrientation()
Returns the orientation setting.
Link copied to clipboard
public final void getPanRemaining(RectF vTarget)
Calculate how much further the image can be panned in each direction.
Link copied to clipboard
public static Config getPreferredBitmapConfig()
Get the current preferred configuration for decoding bitmaps.
Link copied to clipboard
public final float getScale()
Returns the current scale value.
Link copied to clipboard
public final int getSHeight()
Get source height, ignoring orientation.
Link copied to clipboard
public final ImageViewState getState()
Get the current state of the view (scale, center, orientation) for restoration after rotate.
Link copied to clipboard
public final int getSWidth()
Get source width, ignoring orientation.
Link copied to clipboard
public Uri getUri()
Return the uri that has been set.
Link copied to clipboard
public boolean hasImage()
Check if an image has been set.
Link copied to clipboard
public final boolean isImageLoaded()
Call to find whether the main image (base layer tiles where relevant) have been loaded.
Link copied to clipboard
public final boolean isPanEnabled()
Returns true if pan gesture detection is enabled.
Link copied to clipboard
public final boolean isQuickScaleEnabled()
Returns true if double tap &swipe to zoom is enabled.
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.
Link copied to clipboard
public final boolean isZoomEnabled()
Returns true if zoom gesture detection is enabled.
Link copied to clipboard
public boolean onTouchEvent(MotionEvent event)
Handle touch events.
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.
Link copied to clipboard
public final void resetScaleAndCenter()
Fully zoom out and return the image to the middle of the screen.
Link copied to clipboard
public final void setBitmapAndFileUri(Bitmap bitmap, Uri fileUri)
Link copied to clipboard
public final void setBitmapDecoderClass(Class<? extends ImageDecoder> bitmapDecoderClass)
Swap the default bitmap decoder implementation for one of your own.
Link copied to clipboard
public final void setBitmapDecoderFactory(DecoderFactory<? extends ImageDecoder> bitmapDecoderFactory)
Swap the default bitmap decoder implementation for one of your own.
Link copied to clipboard
public final void setBitmapFitX(Bitmap bitmap)
bitmap 展示以X轴为准,填充满X轴
Link copied to clipboard
public final void setDebug(boolean debug)
Enables visual debugging, showing tile boundaries and sizes.
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.
Link copied to clipboard
public final void setDoubleTapZoomDuration(int durationMs)
Set the duration of the double tap zoom animation.
Link copied to clipboard
public final void setDoubleTapZoomScale(float doubleTapZoomScale)
Set the scale the image will zoom in to when double tapped.
Link copied to clipboard
public final void setDoubleTapZoomStyle(int doubleTapZoomStyle)
Set the type of zoom animation to be used for double taps.
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.
Link copied to clipboard
public void setExecutor(Executor executor)
Provide an Executor to be used for loading images.
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.
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.
Link copied to clipboard
public final void setMaxScale(float maxScale)
Set the maximum scale allowed.
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.
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.
Link copied to clipboard
public final void setMinimumScaleType(int scaleType)
Set the minimum scale type.
Link copied to clipboard
public void setMinimumTileDpi(int minimumTileDpi)
By default, image tiles are at least as high resolution as the screen.
Link copied to clipboard
public final void setMinScale(float minScale)
Set the minimum scale allowed.
Link copied to clipboard
Add a listener allowing notification of load and error events.
Link copied to clipboard
public void setOnLongClickListener(OnLongClickListener onLongClickListener)
Link copied to clipboard
Add a listener for pan and zoom events.
Link copied to clipboard
public final void setOrientation(int orientation)
Sets the image orientation.
Link copied to clipboard
public final void setPanEnabled(boolean panEnabled)
Enable or disable pan gesture detection.
Link copied to clipboard
public final void setPanLimit(int panLimit)
Set the pan limiting style.
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.
Link copied to clipboard
public final void setQuickScaleEnabled(boolean quickScaleEnabled)
Enable or disable double tap &swipe to zoom.
Link copied to clipboard
public final void setRegionDecoderClass(Class<? extends ImageRegionDecoder> regionDecoderClass)
Swap the default region decoder implementation for one of your own.
Link copied to clipboard
public final void setRegionDecoderFactory(DecoderFactory<? extends ImageRegionDecoder> regionDecoderFactory)
Swap the default region decoder implementation for one of your own.
Link copied to clipboard
public final void setScaleAndCenter(float scale, PointF sCenter)
Externally change the scale and translation of the source image.
Link copied to clipboard
public final void setTileBackgroundColor(int tileBgColor)
Set a solid color to render behind tiles, useful for displaying transparent PNGs.
Link copied to clipboard
public final void setZoomEnabled(boolean zoomEnabled)
Enable or disable zoom gesture detection.
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.
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.
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.
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.