Package playn.core

Class Image

All Implemented Interfaces:
AutoCloseable, Canvas.Drawable, Closeable
Direct Known Subclasses:
ImageImpl

public abstract class Image extends TileSource implements Canvas.Drawable, Closeable
Bitmapped image data. May be loaded via Assets or created dynamically as in the backing image for a Canvas.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    static class 
    A region of an image which can be rendered to Canvases and turned into a texture (which is a Tile of the original image's texture).

    Nested classes/interfaces inherited from interface react.Closeable

    Closeable.Set, Closeable.Util
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final RFuture<Image>
    Reports the asynchronous loading of this image.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Disposes this image's default texture, if it has been already created.
    abstract Pattern
    createPattern(boolean repeatX, boolean repeatY)
    Creates a pattern from this image which can be used to fill a canvas.
    Creates a texture with this image's bitmap data using config.
    abstract void
    getRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize)
    Extracts pixel data from a rectangular area of this image.
    float
    This image's height in display units.
    boolean
    Returns whether this image is successfully loaded.
    abstract int
    Returns the height of this image in physical pixels.
    abstract int
    Returns the width of this image in physical pixels.
    region(float rx, float ry, float rwidth, float rheight)
    Returns a region of this image which can be drawn independently.
    abstract Scale
    Returns the scale of resolution independent pixels to actual pixels for this image.
    Sets the texture config used when creating this image's default texture.
    abstract void
    setRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize)
    Sets pixel data for a rectangular area of this image.
    Returns, creating if necessary, this image's default texture.
    Returns a future which will deliver the default texture for this image once its loading has completed.
    Returns the tile provided by this source.
    Delivers the tile provided by this source once the source is loaded.
    abstract Image
    Generates a new image from this image's bitmap, using a transformer created for the platform in use.
    Updates this image's default texture with the current contents of the image, and returns the texture.
    float
    This image's width in display units.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface playn.core.Canvas.Drawable

    draw, draw
  • Field Details

    • state

      public final RFuture<Image> state
      Reports the asynchronous loading of this image. This will be completed with success or failure when the image's asynchronous load completes.
  • Method Details

    • isLoaded

      public boolean isLoaded()
      Returns whether this image is successfully loaded. If it is still loading, or loading failed, false will be returned. In general you'll want to react to state, but this method is useful when you need to assert that something is only allowed on a fully loaded image.
      Specified by:
      isLoaded in class TileSource
    • scale

      public abstract Scale scale()
      Returns the scale of resolution independent pixels to actual pixels for this image. This will be Scale.ONE unless HiDPI images are being used.
    • width

      public float width()
      This image's width in display units. If this image is loaded asynchrously, this will return 0 until loading is complete. See state.
      Specified by:
      width in interface Canvas.Drawable
    • height

      public float height()
      This image's height in display units. If this image is loaded asynchrously, this will return 0 until loading is complete. See state.
      Specified by:
      height in interface Canvas.Drawable
    • pixelWidth

      public abstract int pixelWidth()
      Returns the width of this image in physical pixels. If this image is loaded asynchrously, this will return 0 until loading is complete. See state.
    • pixelHeight

      public abstract int pixelHeight()
      Returns the height of this image in physical pixels. If this image is loaded asynchrously, this will return 0 until loading is complete. See state.
    • getRgb

      public abstract void getRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize)
      Extracts pixel data from a rectangular area of this image. This method may perform poorly, in particular on the HTML platform. The returned pixel format is (alpha << 24 | red << 16 | green << 8 | blue), where alpha, red, green and blue are the corresponding channel values, ranging from 0 to 255 inclusive.
      Parameters:
      startX - x-coordinate of the upper left corner of the area.
      startY - y-coordinate of the upper left corner of the area.
      width - width of the area.
      height - height of the area.
      rgbArray - will be filled with the pixel data from the area
      offset - fill start offset in rgbArray.
      scanSize - number of pixels in a row in rgbArray.
    • setRgb

      public abstract void setRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize)
      Sets pixel data for a rectangular area of this image. This method may perform poorly, in particular on the HTML platform. On the HTML platform, due to brower security limitations, this method is only allowed on images created via Graphics.createCanvas(float, float). The pixel format is (alpha << 24 | red << 16 | green << 8 | blue), where alpha, red, green and blue are the corresponding channel values, ranging from 0 to 255 inclusive.
      Parameters:
      startX - x-coordinate of the upper left corner of the area.
      startY - y-coordinate of the upper left corner of the area.
      width - width of the area.
      height - height of the area.
      rgbArray - will be filled with the pixel data from the area
      offset - fill start offset in rgbArray.
      scanSize - number of pixels in a row in rgbArray.
    • createPattern

      public abstract Pattern createPattern(boolean repeatX, boolean repeatY)
      Creates a pattern from this image which can be used to fill a canvas.
    • setConfig

      public Image setConfig(Texture.Config config)
      Sets the texture config used when creating this image's default texture. Note: this must be called before the first call to texture so that it is configured before the default texture is created and cached.
    • texture

      public Texture texture()
      Returns, creating if necessary, this image's default texture. When the texture is created, it will use the Texture.Config set via setConfig(playn.core.Texture.Config). If an image's default texture is Texture.close()d, a subsequent call to this method will create a new default texture.
    • updateTexture

      public Texture updateTexture()
      Updates this image's default texture with the current contents of the image, and returns the texture. If the texture has not yet been created, then this simply creates it. This is only necessary if you want to update the default texture for an image associated with a Canvas, or if you have used setRgb(int, int, int, int, int[], int, int) to change the contents of this image.
    • textureAsync

      public RFuture<Texture> textureAsync()
      Returns a future which will deliver the default texture for this image once its loading has completed. Uses texture to create the texture.
    • createTexture

      public Texture createTexture(Texture.Config config)
      Creates a texture with this image's bitmap data using config. NOTE: this creates a new texture with every call. This is generally only needed if you plan to create multiple textures from the same bitmap, with different configurations. Otherwise just use texture to create the image's "default" texture which will be shared by all callers.
    • close

      public void close()
      Disposes this image's default texture, if it has been already created.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • region

      public Image.Region region(float rx, float ry, float rwidth, float rheight)
      Returns a region of this image which can be drawn independently.
    • transform

      public abstract Image transform(Image.BitmapTransformer xform)
      Generates a new image from this image's bitmap, using a transformer created for the platform in use. See JavaBitmapTransformer for example.
    • tile

      public Tile tile()
      Description copied from class: TileSource
      Returns the tile provided by this source.
      Specified by:
      tile in class TileSource
    • tileAsync

      public RFuture<Tile> tileAsync()
      Description copied from class: TileSource
      Delivers the tile provided by this source once the source is loaded.
      Specified by:
      tileAsync in class TileSource