Sofia API Reference

  • Package Index
  • Class Index
  • Packages
  • sofia.app
  • sofia.content
  • sofia.data
  • sofia.graphics
    • Interfaces
    • Joint
    • PropertyTransformer
    • Classes
    • AbstractJoint
    • Anchor
    • Color
    • CoordinateSystem
    • DirectionalPad
    • DistanceJoint
    • ElasticInInterpolator
    • ElasticInOutInterpolator
    • ElasticOutInterpolator
    • FillableShape
    • FillableShape.Animator
    • Geometry
    • Image
    • LineShape
    • MotionStep
    • OvalShape
    • PointAndAnchor
    • Polygon
    • PolygonShape
    • Predicate
    • RectangleShape
    • RevoluteJoint
    • Shape
    • Shape.Animator
    • Shape.Filter
    • ShapeField
    • ShapeFilter
    • ShapeSet
    • ShapeView
    • SizeF
    • StrokedShape
    • StrokedShape.Animator
    • TextShape
    • TextShape.Animator
    • Timings
    • ViewEdges
    • ZIndexComparator
    • Enums
    • RepeatMode
    • ShapeMotion
  • sofia.util
  • sofia.view
  • sofia.widget

public class
Image

extends Object

Inheritance

  • java.lang.Object
    • sofia.graphics.Image

Class Overview

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.


Summary

Public Constructors
Image(Bitmap bitmap)
Create an image from a bitmap.
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.
Methods inherited from class java.lang.Object
Object clone()
boolean equals(Object arg0)
void finalize()
final Class<?> getClass()
int hashCode()
final void notify()
final void notifyAll()
String toString()
final void wait()
final void wait(long arg0, int arg1)
final void wait(long arg0)

Public Constructors

public Image (Bitmap bitmap)

Create an image from a bitmap.

Parameters
bitmap
The bitmap forming this image's contents.

Public Methods

public Bitmap asBitmap ()

Access the contents of this image in the form of an Android Bitmap.

Returns

A Bitmap with this image's contents.

public static Image getDefault ()

Get a new Image object that renders as the default Sofia image.

Returns

a new Image object that renders as the default image.

public int getHeight ()

Return the height of this bitmap.

Before calling this method, the bitmap must be resolved (that is, loaded from a resource).

Returns

The height of this bitmap, in pixels.

Throws
IllegalStateException
If the bitmap has not yet been resolved.
public Color getPixel (int x, int y)

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).

Parameters
x
The x coordinate (0...width-1) of the pixel to return.
y
The y coordinate (0...height-1) of the pixel to return.
Returns

The Color at the specified coordinate

Throws
IllegalArgumentException
If x or y exceed the bitmap's bounds.
IllegalStateException
If the bitmap has not yet been resolved.
public Color[] getPixels ()

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.

Returns

An array representing all of the pixels in the image.

Throws
IllegalStateException
If the bitmap has not yet been resolved.
public 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. The default is true. This setting is only useful before the image is resolved (loaded), since scaling happens at that time.

Returns

True if this image will be scaled for the current device's pixel density when it is loaded.

See Also
  • resolveAgainstContext(Context)
public int getWidth ()

Return the width of this bitmap.

Before calling this method, the bitmap must be resolved (that is, loaded from a resource).

Returns

The width of this bitmap, in pixels.

Throws
IllegalStateException
If the bitmap has not yet been resolved.
public 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).

Parameters
context
The context to resolve this image against.
public void setPixel (int x, int y, Color color)

Write the specified Color into the bitmap at the x,y coordinate.

Parameters
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.
Throws
IllegalArgumentException
If x, y are outside of the bitmap's bounds.
IllegalStateException
If the bitmap has not yet been resolved.
public void setPixels (Color[] pixels)

Replace pixels in the bitmap with the colors in the array.

Parameters
pixels
The colors to write to the bitmap.
Throws
IllegalStateException
If the bitmap has not yet been resolved.
IllegalArgumentException
If the pixels array is the wrong size, or null.
public 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. The default is true. This setting is only useful before the image is resolved (loaded), since scaling happens at that time.

Parameters
willScaleForDpi
True if this image should be scaled for the current device's pixel density.
See Also
  • resolveAgainstContext(Context)
public 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. The default is true.

Parameters
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.
public 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. If it returns false, and no image file is found, then asBitmap() will return null. The default is true.

Returns

True if this image should render as the Sofia default image when no corresponding resource is found.