/** * 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. * * @param id the resource identifier, as generated by the aapt tool * * @return the new image source */ public static ImageSource fromResource(@DrawableRes int id) { ImageSource imageSource = new ImageSource(); imageSource.type = TYPE_RESOURCE; imageSource.source = id; return imageSource; }
/** * Constructs an image source with a file path. * * @param pathName complete path name to the file * * @return the new image source * * @throws IllegalArgumentException If the path name is null */ public static ImageSource fromFilePath(String pathName) { if (pathName == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "ImageSource", "fromFilePath", "missingPathName")); } ImageSource imageSource = new ImageSource(); imageSource.type = TYPE_FILE_PATH; imageSource.source = pathName; return imageSource; }
/** * Constructs an image source with a bitmap. The bitmap's dimensions should be no greater than 2048 x 2048. * * @param bitmap the bitmap to use as an image source * * @return the new image source * * @throws IllegalArgumentException If the bitmap is null or recycled */ public static ImageSource fromBitmap(Bitmap bitmap) { if (bitmap == null || bitmap.isRecycled()) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "ImageSource", "fromBitmap", (bitmap == null) ? "missingBitmap" : "invalidBitmap")); } ImageSource imageSource = new ImageSource(); imageSource.type = TYPE_BITMAP; imageSource.source = bitmap; return imageSource; }
/** * 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. * * @param factory the bitmap factory to use as an image source * * @return the new image source * * @throws IllegalArgumentException If the factory is null */ public static ImageSource fromBitmapFactory(ImageSource.BitmapFactory factory) { if (factory == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "ImageSource", "fromBitmapFactory", "missingFactory")); } ImageSource imageSource = new ImageSource(); imageSource.type = TYPE_BITMAP_FACTORY; imageSource.source = factory; return imageSource; }
/** * 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. * * @param urlString complete URL string * * @return the new image source * * @throws IllegalArgumentException If the URL string is null */ public static ImageSource fromUrl(String urlString) { if (urlString == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "ImageSource", "fromUrl", "missingUrl")); } ImageSource imageSource = new ImageSource(); imageSource.type = TYPE_URL; imageSource.source = urlString; return imageSource; }
/** * 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 {@link gov.nasa.worldwind.shape.ShapeAttributes#setOutlineImageSource(ImageSource)}. * * @param 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. * @param 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. * * @return the new image source */ public static ImageSource fromLineStipple(int factor, short pattern) { long lfactor = (factor & 0xFFFFFFFFL); long lpattern = (pattern & 0xFFFFL); long key = (lfactor << 32) | lpattern; BitmapFactory factory = lineStippleFactories.get(key); if (factory == null) { factory = new LineStippleBitmapFactory(factor, pattern); lineStippleFactories.put(key, factory); } ImageSource imageSource = new ImageSource(); imageSource.type = TYPE_BITMAP_FACTORY; imageSource.source = factory; return imageSource; }
return fromFilePath((String) source); } else { ImageSource imageSource = new ImageSource(); imageSource.type = TYPE_UNRECOGNIZED; imageSource.source = source;