Class ImageSource


  • public class ImageSource
    extends java.lang.Object
    Provides a mechanism for specifying images from a variety of sources. ImageSource retains the image source and its associated type on behalf of the caller, making this information available to WorldWind components that load images on the caller's behalf.
    ImageSource supports four source types:
    ImageSource instances are intended to be used as a key into a cache or other data structure that enables sharing of loaded images. Android bitmaps and WorldWind bitmap factories are compared by reference: two image sources are equivalent if they reference the same bitmap or the same bitmap factory. Android resource identifiers with equivalent IDs are considered equivalent, as are file paths and URLs with the same string representation.
    • Method Detail

      • fromBitmap

        public static ImageSource fromBitmap​(android.graphics.Bitmap bitmap)
        Constructs an image source with a bitmap. The bitmap's dimensions should be no greater than 2048 x 2048.
        Parameters:
        bitmap - the bitmap to use as an image source
        Returns:
        the new image source
        Throws:
        java.lang.IllegalArgumentException - If the bitmap is null or recycled
      • fromBitmapFactory

        public static ImageSource fromBitmapFactory​(ImageSource.BitmapFactory factory)
        Constructs an image source with a bitmap factory. WorldWind shapes configured with a bitmap factory image source construct their bitmaps lazily, typically when the shape becomes visible on screen. The factory must create images with dimensions to no greater than 2048 x 2048.
        Parameters:
        factory - the bitmap factory to use as an image source
        Returns:
        the new image source
        Throws:
        java.lang.IllegalArgumentException - If the factory is null
      • fromResource

        public static ImageSource fromResource​(@DrawableRes
                                               int id)
        Constructs an image source with an Android resource identifier. The resource must be accessible from the Android Context associated with the WorldWindow, and its dimensions should be no greater than 2048 x 2048.
        Parameters:
        id - the resource identifier, as generated by the aapt tool
        Returns:
        the new image source
      • fromFilePath

        public static ImageSource fromFilePath​(java.lang.String pathName)
        Constructs an image source with a file path.
        Parameters:
        pathName - complete path name to the file
        Returns:
        the new image source
        Throws:
        java.lang.IllegalArgumentException - If the path name is null
      • fromUrl

        public static ImageSource fromUrl​(java.lang.String urlString)
        Constructs an image source with a URL string. The image's dimensions should be no greater than 2048 x 2048. The application's manifest must include the permissions that allow network connections.
        Parameters:
        urlString - complete URL string
        Returns:
        the new image source
        Throws:
        java.lang.IllegalArgumentException - If the URL string is null
      • fromUrl

        public static ImageSource fromUrl​(java.lang.String urlString,
                                          ImageSource.Transformer transformer)
        Constructs an image source with a URL string. The image's dimensions should be no greater than 2048 x 2048. The application's manifest must include the permissions that allow network connections.
        Parameters:
        urlString - complete URL string
        transformer - implementation of image post-transformation routine
        Returns:
        the new image source
        Throws:
        java.lang.IllegalArgumentException - If the URL string is null
      • fromLineStipple

        public static ImageSource fromLineStipple​(int factor,
                                                  short pattern)
        Constructs a bitmap image source with a line stipple pattern. The result is a one-dimensional bitmap with pixels representing the specified stipple factor and stipple pattern. Line stipple images can be used for displaying dashed shape outlines. See ShapeAttributes.setOutlineImageSource(ImageSource).
        Parameters:
        factor - specifies the number of times each bit in the pattern is repeated before the next bit is used. For example, if the factor is 3, each bit is repeated three times before using the next bit. The specified factor must be either 0 or an integer greater than 0. A factor of 0 indicates no stippling.
        pattern - specifies a number whose lower 16 bits define a pattern of which pixels in the image are white and which are transparent. Each bit corresponds to a pixel, and the pattern repeats after every n*16 pixels, where n is the factor. For example, if the factor is 3, each bit in the pattern is repeated three times before using the next bit.
        Returns:
        the new image source
      • fromObject

        public static ImageSource fromObject​(java.lang.Object source)
        Constructs an image source with a generic Object instance. The source may be any non-null Object. This is equivalent to calling one of ImageSource's type-specific factory methods when the source is a recognized type: bitmap; bitmap factory; integer resource ID; file path; URL string.
        Parameters:
        source - the generic source
        Returns:
        the new image source
        Throws:
        java.lang.IllegalArgumentException - If the source is null
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        @NonNull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isBitmap

        public boolean isBitmap()
        Indicates whether this image source is a Bitmap.
        Returns:
        true if the source is a Bitmap, otherwise false
      • isBitmapFactory

        public boolean isBitmapFactory()
        Indicates whether this image source is a bitmap factory.
        Returns:
        true if the source is a bitmap factory, otherwise false
      • isResource

        public boolean isResource()
        Indicates whether this image source is an Android resource.
        Returns:
        true if the source is an Android resource, otherwise false
      • isFilePath

        public boolean isFilePath()
        Indicates whether this image source is a file path.
        Returns:
        true if the source is an file path, otherwise false
      • isUrl

        public boolean isUrl()
        Indicates whether this image source is a URL string.
        Returns:
        true if the source is a URL string, otherwise false
      • asBitmap

        public android.graphics.Bitmap asBitmap()
        Returns the source bitmap. Call isBitmap to determine whether or not the source is a bitmap.
        Returns:
        the bitmap, or null if the source is not a bitmap
      • asBitmapFactory

        public ImageSource.BitmapFactory asBitmapFactory()
        Returns the source bitmap factory. Call isBitmapFactory to determine whether or not the source is a bitmap factory.
        Returns:
        the bitmap factory, or null if the source is not a bitmap factory
      • asResource

        @DrawableRes
        public int asResource()
        Returns the source Android resource identifier. Call isResource to determine whether or not the source is an Android resource.
        Returns:
        the resource identifier as generated by the aapt tool, or null if the source is not an Android resource
      • asFilePath

        public java.lang.String asFilePath()
        Returns the source file path name. Call isFilePath to determine whether or not the source is a file path.
        Returns:
        the file path name, or null if the source is not a file path
      • asUrl

        public java.lang.String asUrl()
        Returns the source URL string. Call isUrl to determine whether or not the source is a URL string.
        Returns:
        the URL string, or null if the source is not a URL string
      • asObject

        public java.lang.Object asObject()
        Returns the image source associated with an unrecognized type.
        Returns:
        the source object