com.davemorrissey.labs.subscaleview

## Class ImageSource

- java.lang.Object
- - com.davemorrissey.labs.subscaleview.ImageSource

    public final class ImageSource
    extends Object

Helper class used to set the source and additional attributes from a variety of sources. Supports use of a bitmap, asset, resource, external file or any other URI. When you are using a preview image, you must set the dimensions of the full size image on the ImageSource object for the full size image using the `dimensions(int, int)` method.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static ImageSource` `asset(String assetName)` Create an instance from an asset name.
`static ImageSource` `bitmap(Bitmap bitmap)` Provide a loaded bitmap for display.
`static ImageSource` `cachedBitmap(Bitmap bitmap)` Provide a loaded and cached bitmap for display.
`ImageSource` `dimensions(int sWidth, int sHeight)` Declare the dimensions of the image.
`protected Bitmap` `getBitmap()`
`protected Integer` `getResource()`
`protected int` `getSHeight()`
`protected Rect` `getSRegion()`
`protected int` `getSWidth()`
`protected boolean` `getTile()`
`protected Uri` `getUri()`
`protected boolean` `isCached()`
`ImageSource` `region(Rect sRegion)` Use a region of the source image.
`static ImageSource` `resource(int resId)` Create an instance from a resource.
`ImageSource` `tiling(boolean tile)` Enable or disable tiling of the image.
`ImageSource` `tilingDisabled()` Disable tiling of the image.
`ImageSource` `tilingEnabled()` Enable tiling of the image.
`static ImageSource` `uri(String uri)` Create an instance from a URI.
`static ImageSource` `uri(Uri uri)` Create an instance from a URI.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### resource

    @NonNull
    public static ImageSource resource(int resId)

Create an instance from a resource. The correct resource for the device screen resolution will be used.

Parameters:
  `resId` - resource ID.
Returns:
  an `ImageSource` instance.

#### asset

    @NonNull
    public static ImageSource asset(@NonNull
                                             String assetName)

Create an instance from an asset name.

Parameters:
  `assetName` - asset name.
Returns:
  an `ImageSource` instance.

#### uri

    @NonNull
    public static ImageSource uri(@NonNull
                                           String uri)

Create an instance from a URI. If the URI does not start with a scheme, it's assumed to be the URI of a file.

Parameters:
  `uri` - image URI.
Returns:
  an `ImageSource` instance.

#### uri

    @NonNull
    public static ImageSource uri(@NonNull
                                           Uri uri)

Create an instance from a URI.

Parameters:
  `uri` - image URI.
Returns:
  an `ImageSource` instance.

#### bitmap

    @NonNull
    public static ImageSource bitmap(@NonNull
                                              Bitmap bitmap)

Provide a loaded bitmap for display.

Parameters:
  `bitmap` - bitmap to be displayed.
Returns:
  an `ImageSource` instance.

#### cachedBitmap

    @NonNull
    public static ImageSource cachedBitmap(@NonNull
                                                    Bitmap bitmap)

Provide a loaded and cached bitmap for display. This bitmap will not be recycled when it is no longer needed. Use this method if you loaded the bitmap with an image loader such as Picasso or Volley.

Parameters:
  `bitmap` - bitmap to be displayed.
Returns:
  an `ImageSource` instance.

#### tilingEnabled

    @NonNull
    public ImageSource tilingEnabled()

Enable tiling of the image. This does not apply to preview images which are always loaded as a single bitmap., and tiling cannot be disabled when displaying a region of the source image.

Returns:
  this instance for chaining.

#### tilingDisabled

    @NonNull
    public ImageSource tilingDisabled()

Disable tiling of the image. This does not apply to preview images which are always loaded as a single bitmap, and tiling cannot be disabled when displaying a region of the source image.

Returns:
  this instance for chaining.

#### tiling

    @NonNull
    public ImageSource tiling(boolean tile)

Enable or disable tiling of the image. This does not apply to preview images which are always loaded as a single bitmap, and tiling cannot be disabled when displaying a region of the source image.

Parameters:
  `tile` - whether tiling should be enabled.
Returns:
  this instance for chaining.

#### region

    @NonNull
    public ImageSource region(Rect sRegion)

Use a region of the source image. Region must be set independently for the full size image and the preview if you are using one.

Parameters:
  `sRegion` - the region of the source image to be displayed.
Returns:
  this instance for chaining.

#### dimensions

    @NonNull
    public ImageSource dimensions(int sWidth,
                                           int sHeight)

Declare the dimensions of the image. This is only required for a full size image, when you are specifying a URI and also a preview image. When displaying a bitmap object, or not using a preview, you do not need to declare the image dimensions. Note if the declared dimensions are found to be incorrect, the view will reset.

Parameters:
  `sWidth` - width of the source image.
  `sHeight` - height of the source image.
Returns:
  this instance for chaining.

#### getUri

    protected final Uri getUri()

#### getBitmap

    protected final Bitmap getBitmap()

#### getResource

    protected final Integer getResource()

#### getTile

    protected final boolean getTile()

#### getSWidth

    protected final int getSWidth()

#### getSHeight

    protected final int getSHeight()

#### getSRegion

    protected final Rect getSRegion()

#### isCached

    protected final boolean isCached()