java.lang.Object | |
↳ | sofia.graphics.Image |
Known Direct Subclasses |
Represents a single bitmapped image, such as one loaded from a file.
Images retrieved by name or class are searched for using a robust and flexible search scheme.
This class cannot be a subclass of Bitmap
, since Bitmap is
a final class.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Image(Bitmap bitmap)
Create an image from a bitmap.
| |||||||||||
Image(int bitmapId)
Create an image from a bitmap by specifying a resource id.
| |||||||||||
Image(Class<?> klass)
Create an image from a class.
| |||||||||||
Image(String fileName)
Create an image from a file.
| |||||||||||
Image(Image other)
Create an image that is a duplicate of another image
(a copy constructor).
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Bitmap |
asBitmap()
Access the contents of this image in the form of an Android
Bitmap . | ||||||||||
static Image |
getDefault()
Get a new Image object that renders as the default Sofia
image.
| ||||||||||
int |
getHeight()
Return the height of this bitmap.
| ||||||||||
Color |
getPixel(int x, int y)
Returns the Color at the specified location.
| ||||||||||
Color[] |
getPixels()
Returns an array containing all of the Color of each pixel in the
image, arranged in row-major order.
| ||||||||||
boolean |
getScaleForDpi()
Get whether this image will be automatically scaled up or down
based on the current device's pixel density when it is loaded.
| ||||||||||
int |
getWidth()
Return the width of this bitmap.
| ||||||||||
void |
resolveAgainstContext(Context context)
Provide an Android resource context to use for loading this
image (this must be called before any class/id/file name image
will be available).
| ||||||||||
void |
setPixel(int x, int y, Color color)
Write the specified Color into the bitmap at the x,y coordinate.
| ||||||||||
void |
setPixels(Color[] pixels)
Replace pixels in the bitmap with the colors in the array.
| ||||||||||
void |
setScaleForDpi(boolean willScaleForDpi)
Determine whether this image will be automatically scaled up or down
based on the current device's pixel density when it is loaded.
| ||||||||||
void |
setUseDefaultIfNotFound(boolean useDefault)
Determine whether this image should use the default Sofia
image/icon, if no image corresponding to the search criteria
(e.g., a class name, or a file name) is found.
| ||||||||||
boolean |
useDefaultIfNotFound()
Says whether this object will use the default Sofia
image/icon, if no image corresponding to the search criteria
specified in its constructor call (e.g., a class name, or a
file name) is found.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Create an image from a bitmap.
bitmap | The bitmap forming this image's contents. |
---|
Create an image from a bitmap by specifying a resource id.
bitmapId | The id of the bitmap resource for this image. |
---|
Create an image from a class. The image used will be found based on the name of the class.
klass | The Java class after which the file is named. |
---|
Create an image from a file. The image will be found by searching for an appropriate match.
fileName | The name of the image file, optionally including an extension. |
---|
Create an image that is a duplicate of another image (a copy constructor).
other | The image to copy. |
---|
Access the contents of this image in the form of an Android
Bitmap
.
Get a new Image object that renders as the default Sofia image.
Return the height of this bitmap.
Before calling this method, the bitmap must be resolved (that is, loaded from a resource).
IllegalStateException | If the bitmap has not yet been resolved. |
---|
Returns the Color at the specified location. Throws an exception if x or y are out of bounds (negative or >= to the width or height respectively).
x | The x coordinate (0...width-1) of the pixel to return. |
---|---|
y | The y coordinate (0...height-1) of the pixel to return. |
IllegalArgumentException | If x or y exceed the bitmap's bounds. |
---|---|
IllegalStateException | If the bitmap has not yet been resolved. |
Returns an array containing all of the Color of each pixel in the image, arranged in row-major order. All of the pixels in row 0 appear in the array first, followed by the pixels in row 1, row 2, and so on. The array is Width x Height in size.
IllegalStateException | If the bitmap has not yet been resolved. |
---|
Get whether this image will be automatically scaled up or down based on the current device's pixel density when it is loaded. The default is true. This setting is only useful before the image is resolved (loaded), since scaling happens at that time.
Return the width of this bitmap.
Before calling this method, the bitmap must be resolved (that is, loaded from a resource).
IllegalStateException | If the bitmap has not yet been resolved. |
---|
Provide an Android resource context to use for loading this image (this must be called before any class/id/file name image will be available).
context | The context to resolve this image against. |
---|
Write the specified Color into the bitmap at the x,y coordinate.
x | The x coordinate of the pixel to replace (0...width-1). |
---|---|
y | The y coordinate of the pixel to replace (0...height-1). |
color | The Color to write into the bitmap. |
IllegalArgumentException | If x, y are outside of the bitmap's bounds. |
---|---|
IllegalStateException | If the bitmap has not yet been resolved. |
Replace pixels in the bitmap with the colors in the array.
pixels | The colors to write to the bitmap. |
---|
IllegalStateException | If the bitmap has not yet been resolved. |
---|---|
IllegalArgumentException | If the pixels array is the wrong size, or null. |
Determine whether this image will be automatically scaled up or down based on the current device's pixel density when it is loaded. The default is true. This setting is only useful before the image is resolved (loaded), since scaling happens at that time.
willScaleForDpi | True if this image should be scaled for the current device's pixel density. |
---|
Determine whether this image should use the default Sofia image/icon, if no image corresponding to the search criteria (e.g., a class name, or a file name) is found. The default is true.
useDefault | True if this image should render as the Sofia default image if no corresponding resource is found. If false, and no image is found, then asBitmap() will return null. |
---|
Says whether this object will use the default Sofia
image/icon, if no image corresponding to the search criteria
specified in its constructor call (e.g., a class name, or a
file name) is found. If it returns false, and no image file is
found, then asBitmap()
will return null. The default
is true.