Package playn.core
Class Image
java.lang.Object
playn.core.TileSource
playn.core.Image
- All Implemented Interfaces:
AutoCloseable,Canvas.Drawable,Closeable
- Direct Known Subclasses:
ImageImpl
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic classNested classes/interfaces inherited from interface react.Closeable
Closeable.Set, Closeable.Util -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Disposes this image's default texture, if it has been already created.abstract PatterncreatePattern(boolean repeatX, boolean repeatY) Creates a pattern from this image which can be used to fill a canvas.createTexture(Texture.Config config) Creates a texture with this image's bitmap data usingconfig.abstract voidgetRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) Extracts pixel data from a rectangular area of this image.floatheight()This image's height in display units.booleanisLoaded()Returns whether this image is successfully loaded.abstract intReturns the height of this image in physical pixels.abstract intReturns 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 Scalescale()Returns the scale of resolution independent pixels to actual pixels for this image.setConfig(Texture.Config config) Sets the texture config used when creating this image's default texture.abstract voidsetRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) Sets pixel data for a rectangular area of this image.texture()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.tile()Returns the tile provided by this source.Delivers the tile provided by this source once the source is loaded.abstract Imagetransform(Image.BitmapTransformer xform) 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.floatwidth()This image's width in display units.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface playn.core.Canvas.Drawable
draw, draw
-
Field Details
-
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,falsewill be returned. In general you'll want to react tostate, but this method is useful when you need to assert that something is only allowed on a fully loaded image.- Specified by:
isLoadedin classTileSource
-
scale
Returns the scale of resolution independent pixels to actual pixels for this image. This will beScale.ONEunless 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. Seestate.- Specified by:
widthin interfaceCanvas.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. Seestate.- Specified by:
heightin interfaceCanvas.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. Seestate. -
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. Seestate. -
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 areaoffset- 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 viaGraphics.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 areaoffset- fill start offset in rgbArray.scanSize- number of pixels in a row in rgbArray.
-
createPattern
Creates a pattern from this image which can be used to fill a canvas. -
setConfig
Sets the texture config used when creating this image's default texture. Note: this must be called before the first call totextureso that it is configured before the default texture is created and cached. -
texture
Returns, creating if necessary, this image's default texture. When the texture is created, it will use theTexture.Configset viasetConfig(playn.core.Texture.Config). If an image's default texture isTexture.close()d, a subsequent call to this method will create a new default 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 aCanvas, or if you have usedsetRgb(int, int, int, int, int[], int, int)to change the contents of this image. -
textureAsync
Returns a future which will deliver the default texture for this image once its loading has completed. Usestextureto create the texture. -
createTexture
Creates a texture with this image's bitmap data usingconfig. 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 usetextureto 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
region
Returns a region of this image which can be drawn independently. -
transform
Generates a new image from this image's bitmap, using a transformer created for the platform in use. SeeJavaBitmapTransformerfor example. -
tile
Description copied from class:TileSourceReturns the tile provided by this source.- Specified by:
tilein classTileSource
-
tileAsync
Description copied from class:TileSourceDelivers the tile provided by this source once the source is loaded.- Specified by:
tileAsyncin classTileSource
-