APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.graphics

public Class Pixmap

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.utils.Disposable
Imports
com.badlogic.gdx.Gdx, .Net, com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.graphics.g2d.Gdx2DPixmap, com.badlogic.gdx.utils.BufferUtils, .Disposable, .GdxRuntimeException, java.io.IOException, java.nio.ByteBuffer

A Pixmap represents an image in memory. It has a width and height expressed in pixels as well as a Format specifying the number and order of color components per pixel. Coordinates of pixels are specified with respect to the top left corner of the image, with the x-axis pointing to the right and the y-axis pointing downwards.

By default all methods use blending. You can disable blending with Pixmap#setBlending(Blending), which may reduce blitting time by ~30%. The Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int) method will scale and stretch the source image to a target image. There either nearest neighbour or bilinear filtering can be used.

A Pixmap stores its data in native heap memory. It is mandatory to call Pixmap#dispose() when the pixmap is no longer needed, otherwise memory leaks will result

Author
[email protected]

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Pixmap.Blending

Blending functions to be set with Pixmap#setBlending.

public static interface
public static enum
public static enum
Pixmap.Format

Different pixel formats.

Field Summary

Modifier and TypeField and Description
private Pixmap.Blending
pack-priv int
private boolean
private Pixmap.Filter
pack-priv final Gdx2DPixmap

Constructor Summary

AccessConstructor and Description
public
Pixmap(int
the width in pixels
width
,
int
the height in pixels
height
,
Pixmap.Format
the Format
format
)

Creates a new Pixmap instance with the given width, height and format.

public
Pixmap(byte[]
the encoded image data
encodedData
,
int
the offset
offset
,
int
the length
len
)

Creates a new Pixmap instance from the given encoded image data.

public
Pixmap(ByteBuffer
the encoded image data
encodedData
,
int
the offset relative to the base address of encodedData
offset
,
int
the length
len
)

Creates a new Pixmap instance from the given encoded image data.

public
Pixmap(ByteBuffer
the encoded image data
encodedData
)

Creates a new Pixmap instance from the given encoded image data.

public
Pixmap(FileHandle file)

Creates a new Pixmap instance from the given file.

public
Pixmap(Gdx2DPixmap pixmap)

Constructs a new Pixmap from a Gdx2DPixmap.

Method Summary

Modifier and TypeMethod and Description
public static Pixmap

Returns:

the pixmap
createFromFrameBuffer
(int
framebuffer region x
x
,
int
framebuffer region y
y
,
int
framebuffer region width
w
,
int
framebuffer region height
h
)

Creates a Pixmap from a part of the current framebuffer.

public void
dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources associated with this Pixmap.

public static void
downloadFromUrl(String
http url to download the image from
url
,
final Pixmap.DownloadPixmapResponseListener
the listener to call once the image is available as a Pixmap
responseListener
)

Downloads an image from http(s) url and passes it as a Pixmap to the specified DownloadPixmapResponseListener

public void
drawCircle(int
The x-coordinate of the center
x
,
int
The y-coordinate of the center
y
,
int
The radius in pixels
radius
)

Draws a circle outline with the center at x,y and a radius using the current color and stroke width.

public void
drawLine(int
The x-coodinate of the first point
x
,
int
The y-coordinate of the first point
y
,
int
The x-coordinate of the first point
x2
,
int
The y-coordinate of the first point
y2
)

Draws a line between the given coordinates using the currently set color.

public void
drawPixel(int
the x-coordinate
x
,
int
the y-coordinate
y
)

Draws a pixel at the given location with the current color.

public void
drawPixel(int
the x-coordinate
x
,
int
the y-coordinate
y
,
int
the color in RGBA8888 format.
color
)

Draws a pixel at the given location with the given color.

public void
drawPixmap(Pixmap
The other Pixmap
pixmap
,
int
The target x-coordinate (top left corner)
x
,
int
The target y-coordinate (top left corner)
y
)

Draws an area from another Pixmap to this Pixmap.

public void
drawPixmap(Pixmap
The other Pixmap
pixmap
,
int
The target x-coordinate (top left corner)
x
,
int
The target y-coordinate (top left corner)
y
,
int
The source x-coordinate (top left corner)
srcx
,
int
The source y-coordinate (top left corner);
srcy
,
int
The width of the area from the other Pixmap in pixels
srcWidth
,
int
The height of the area from the other Pixmap in pixels
srcHeight
)

Draws an area from another Pixmap to this Pixmap.

public void
drawPixmap(Pixmap
The other Pixmap
pixmap
,
int
The source x-coordinate (top left corner)
srcx
,
int
The source y-coordinate (top left corner);
srcy
,
int
The width of the area from the other Pixmap in pixels
srcWidth
,
int
The height of the area from the other Pixmap in pixels
srcHeight
,
int
The target x-coordinate (top left corner)
dstx
,
int
The target y-coordinate (top left corner)
dsty
,
int
The target width
dstWidth
,
int
the target height
dstHeight
)

Draws an area from another Pixmap to this Pixmap.

public void
drawRectangle(int
The x coordinate
x
,
int
The y coordinate
y
,
int
The width in pixels
width
,
int
The height in pixels
height
)

Draws a rectangle outline starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using the current color.

public void
fill()

Fills the complete bitmap with the currently set color.

public void
fillCircle(int
The x-coordinate of the center
x
,
int
The y-coordinate of the center
y
,
int
The radius in pixels
radius
)

Fills a circle with the center at x,y and a radius using the current color.

public void
fillRectangle(int
The x coordinate
x
,
int
The y coordinate
y
,
int
The width in pixels
width
,
int
The height in pixels
height
)

Fills a rectangle starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using the current color.

public void
fillTriangle(int
The x-coordinate of vertex 1
x1
,
int
The y-coordinate of vertex 1
y1
,
int
The x-coordinate of vertex 2
x2
,
int
The y-coordinate of vertex 2
y2
,
int
The x-coordinate of vertex 3
x3
,
int
The y-coordinate of vertex 3
y3
)

Fills a triangle with vertices at x1,y1 and x2,y2 and x3,y3 using the current color.

public Pixmap.Blending
getBlending()

Returns: the currently set Blending

public Pixmap.Filter
getFilter()

Returns: the currently set Filter

public Pixmap.Format
getFormat()

Returns: the Format of this Pixmap.

public int

Returns:

one of GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, or GL_LUMINANCE_ALPHA.
getGLFormat
()

Returns the OpenGL ES format of this Pixmap.

public int

Returns:

one of GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, or GL_LUMINANCE_ALPHA.
getGLInternalFormat
()

Returns the OpenGL ES format of this Pixmap.

public int

Returns:

one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4
getGLType
()

Returns the OpenGL ES type of this Pixmap.

public int
getHeight()

Returns: The height of the Pixmap in pixels.

public int

Returns:

The pixel color in RGBA8888 format.
getPixel
(int
The x-coordinate
x
,
int
The y-coordinate
y
)

Returns the 32-bit RGBA8888 value of the pixel at x, y.

public ByteBuffer

Returns:

the direct ByteBuffer holding the pixel data.
getPixels
()

Returns the direct ByteBuffer holding the pixel data.

public int
getWidth()

Returns: The width of the Pixmap in pixels.

public boolean
public void
setBlending(Pixmap.Blending
the blending type
blending
)

Sets the type of Blending to be used for all operations.

public void
setColor(int
the color, encoded as RGBA8888
color
)

Sets the color for the following drawing operations

public void
setColor(float
The red component.
r
,
float
The green component.
g
,
float
The blue component.
b
,
float
The alpha component.
a
)

Sets the color for the following drawing operations.

public void
setColor(Color
The color.
color
)

Sets the color for the following drawing operations.

public void
setFilter(Pixmap.Filter
the filter.
filter
)

Sets the type of interpolation Filter to be used in conjunction with Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int).

public void
setPixels(ByteBuffer
Pixels to copy from, should be a direct ByteBuffer and match Pixmap data size (see getPixels()).
pixels
)

Sets pixels from a provided direct byte buffer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blendingback to summary
private Pixmap.Blending blending
colorback to summary
pack-priv int color
disposedback to summary
private boolean disposed
filterback to summary
private Pixmap.Filter filter
pixmapback to summary
pack-priv final Gdx2DPixmap pixmap

Constructor Detail

Pixmapback to summary
public Pixmap(int width, int height, Pixmap.Format format)

Creates a new Pixmap instance with the given width, height and format.

Parameters
width:int

the width in pixels

height:int

the height in pixels

format:Pixmap.Format

the Format

Pixmapback to summary
public Pixmap(byte[] encodedData, int offset, int len)

Creates a new Pixmap instance from the given encoded image data. The image can be encoded as JPEG, PNG or BMP. Not available on GWT backend.

Parameters
encodedData:byte[]

the encoded image data

offset:int

the offset

len:int

the length

Pixmapback to summary
public Pixmap(ByteBuffer encodedData, int offset, int len)

Creates a new Pixmap instance from the given encoded image data. The image can be encoded as JPEG, PNG or BMP. Not available on GWT backend.

Parameters
encodedData:ByteBuffer

the encoded image data

offset:int

the offset relative to the base address of encodedData

len:int

the length

Pixmapback to summary
public Pixmap(ByteBuffer encodedData)

Creates a new Pixmap instance from the given encoded image data. The image can be encoded as JPEG, PNG or BMP. Not available on GWT backend. Offset is based on the position of the buffer. Length is based on the remaining bytes of the buffer.

Parameters
encodedData:ByteBuffer

the encoded image data

Pixmapback to summary
public Pixmap(FileHandle file)

Creates a new Pixmap instance from the given file. The file must be a Png, Jpeg or Bitmap. Paletted formats are not supported.

Parameters
file:FileHandle

the FileHandle

Pixmapback to summary
public Pixmap(Gdx2DPixmap pixmap)

Constructs a new Pixmap from a Gdx2DPixmap.

Method Detail

createFromFrameBufferback to summary
public static Pixmap createFromFrameBuffer(int x, int y, int w, int h)

Creates a Pixmap from a part of the current framebuffer.

Parameters
x:int

framebuffer region x

y:int

framebuffer region y

w:int

framebuffer region width

h:int

framebuffer region height

Returns:Pixmap

the pixmap

disposeback to summary
public void dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources associated with this Pixmap.

downloadFromUrlback to summary
public static void downloadFromUrl(String url, final Pixmap.DownloadPixmapResponseListener responseListener)

Downloads an image from http(s) url and passes it as a Pixmap to the specified DownloadPixmapResponseListener

Parameters
url:String

http url to download the image from

responseListener:Pixmap.DownloadPixmapResponseListener

the listener to call once the image is available as a Pixmap

drawCircleback to summary
public void drawCircle(int x, int y, int radius)

Draws a circle outline with the center at x,y and a radius using the current color and stroke width.

Parameters
x:int

The x-coordinate of the center

y:int

The y-coordinate of the center

radius:int

The radius in pixels

drawLineback to summary
public void drawLine(int x, int y, int x2, int y2)

Draws a line between the given coordinates using the currently set color.

Parameters
x:int

The x-coodinate of the first point

y:int

The y-coordinate of the first point

x2:int

The x-coordinate of the first point

y2:int

The y-coordinate of the first point

drawPixelback to summary
public void drawPixel(int x, int y)

Draws a pixel at the given location with the current color.

Parameters
x:int

the x-coordinate

y:int

the y-coordinate

drawPixelback to summary
public void drawPixel(int x, int y, int color)

Draws a pixel at the given location with the given color.

Parameters
x:int

the x-coordinate

y:int

the y-coordinate

color:int

the color in RGBA8888 format.

drawPixmapback to summary
public void drawPixmap(Pixmap pixmap, int x, int y)

Draws an area from another Pixmap to this Pixmap.

Parameters
pixmap:Pixmap

The other Pixmap

x:int

The target x-coordinate (top left corner)

y:int

The target y-coordinate (top left corner)

drawPixmapback to summary
public void drawPixmap(Pixmap pixmap, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight)

Draws an area from another Pixmap to this Pixmap.

Parameters
pixmap:Pixmap

The other Pixmap

x:int

The target x-coordinate (top left corner)

y:int

The target y-coordinate (top left corner)

srcx:int

The source x-coordinate (top left corner)

srcy:int

The source y-coordinate (top left corner);

srcWidth:int

The width of the area from the other Pixmap in pixels

srcHeight:int

The height of the area from the other Pixmap in pixels

drawPixmapback to summary
public void drawPixmap(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth, int dstHeight)

Draws an area from another Pixmap to this Pixmap. This will automatically scale and stretch the source image to the specified target rectangle. Use Pixmap#setFilter(Filter) to specify the type of filtering to be used (nearest neighbour or bilinear).

Parameters
pixmap:Pixmap

The other Pixmap

srcx:int

The source x-coordinate (top left corner)

srcy:int

The source y-coordinate (top left corner);

srcWidth:int

The width of the area from the other Pixmap in pixels

srcHeight:int

The height of the area from the other Pixmap in pixels

dstx:int

The target x-coordinate (top left corner)

dsty:int

The target y-coordinate (top left corner)

dstWidth:int

The target width

dstHeight:int

the target height

drawRectangleback to summary
public void drawRectangle(int x, int y, int width, int height)

Draws a rectangle outline starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using the current color.

Parameters
x:int

The x coordinate

y:int

The y coordinate

width:int

The width in pixels

height:int

The height in pixels

fillback to summary
public void fill()

Fills the complete bitmap with the currently set color.

fillCircleback to summary
public void fillCircle(int x, int y, int radius)

Fills a circle with the center at x,y and a radius using the current color.

Parameters
x:int

The x-coordinate of the center

y:int

The y-coordinate of the center

radius:int

The radius in pixels

fillRectangleback to summary
public void fillRectangle(int x, int y, int width, int height)

Fills a rectangle starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using the current color.

Parameters
x:int

The x coordinate

y:int

The y coordinate

width:int

The width in pixels

height:int

The height in pixels

fillTriangleback to summary
public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3)

Fills a triangle with vertices at x1,y1 and x2,y2 and x3,y3 using the current color.

Parameters
x1:int

The x-coordinate of vertex 1

y1:int

The y-coordinate of vertex 1

x2:int

The x-coordinate of vertex 2

y2:int

The y-coordinate of vertex 2

x3:int

The x-coordinate of vertex 3

y3:int

The y-coordinate of vertex 3

getBlendingback to summary
public Pixmap.Blending getBlending()
Returns:Pixmap.Blending

the currently set Blending

getFilterback to summary
public Pixmap.Filter getFilter()
Returns:Pixmap.Filter

the currently set Filter

getFormatback to summary
public Pixmap.Format getFormat()
Returns:Pixmap.Format

the Format of this Pixmap.

getGLFormatback to summary
public int getGLFormat()

Returns the OpenGL ES format of this Pixmap. Used as the seventh parameter to GL20#glTexImage2D(int, int, int, int, int, int, int, int, java.nio.Buffer).

Returns:int

one of GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, or GL_LUMINANCE_ALPHA.

getGLInternalFormatback to summary
public int getGLInternalFormat()

Returns the OpenGL ES format of this Pixmap. Used as the third parameter to GL20#glTexImage2D(int, int, int, int, int, int, int, int, java.nio.Buffer).

Returns:int

one of GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, or GL_LUMINANCE_ALPHA.

getGLTypeback to summary
public int getGLType()

Returns the OpenGL ES type of this Pixmap. Used as the eighth parameter to GL20#glTexImage2D(int, int, int, int, int, int, int, int, java.nio.Buffer).

Returns:int

one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4

getHeightback to summary
public int getHeight()
Returns:int

The height of the Pixmap in pixels.

getPixelback to summary
public int getPixel(int x, int y)

Returns the 32-bit RGBA8888 value of the pixel at x, y. For Alpha formats the RGB components will be one.

Parameters
x:int

The x-coordinate

y:int

The y-coordinate

Returns:int

The pixel color in RGBA8888 format.

getPixelsback to summary
public ByteBuffer getPixels()

Returns the direct ByteBuffer holding the pixel data. For the format Alpha each value is encoded as a byte. For the format LuminanceAlpha the luminance is the first byte and the alpha is the second byte of the pixel. For the formats RGB888 and RGBA8888 the color components are stored in a single byte each in the order red, green, blue (alpha). For the formats RGB565 and RGBA4444 the pixel colors are stored in shorts in machine dependent order.

Returns:ByteBuffer

the direct ByteBuffer holding the pixel data.

getWidthback to summary
public int getWidth()
Returns:int

The width of the Pixmap in pixels.

isDisposedback to summary
public boolean isDisposed()
setBlendingback to summary
public void setBlending(Pixmap.Blending blending)

Sets the type of Blending to be used for all operations. Default is Blending#SourceOver.

Parameters
blending:Pixmap.Blending

the blending type

setColorback to summary
public void setColor(int color)

Sets the color for the following drawing operations

Parameters
color:int

the color, encoded as RGBA8888

setColorback to summary
public void setColor(float r, float g, float b, float a)

Sets the color for the following drawing operations.

Parameters
r:float

The red component.

g:float

The green component.

b:float

The blue component.

a:float

The alpha component.

setColorback to summary
public void setColor(Color color)

Sets the color for the following drawing operations.

Parameters
color:Color

The color.

setFilterback to summary
public void setFilter(Pixmap.Filter filter)

Sets the type of interpolation Filter to be used in conjunction with Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int).

Parameters
filter:Pixmap.Filter

the filter.

setPixelsback to summary
public void setPixels(ByteBuffer pixels)

Sets pixels from a provided direct byte buffer.

Parameters
pixels:ByteBuffer

Pixels to copy from, should be a direct ByteBuffer and match Pixmap data size (see getPixels()).

com.badlogic.gdx.graphics back to summary

public final Enum Pixmap.Blending

extends Enum<Pixmap.Blending>
Class Inheritance

Blending functions to be set with Pixmap#setBlending.
Author
mzechner

Field Summary

Modifier and TypeField and Description
public static final Pixmap.Blending
public static final Pixmap.Blending

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Pixmap.Blending
public static Pixmap.Blending[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

Noneback to summary
public static final Pixmap.Blending None
SourceOverback to summary
public static final Pixmap.Blending SourceOver

Constructor Detail

Blendingback to summary
private Blending()

Method Detail

valueOfback to summary
public static Pixmap.Blending valueOf(String name)
valuesback to summary
public static Pixmap.Blending[] values()
com.badlogic.gdx.graphics back to summary

public Interface Pixmap.DownloadPixmapResponseListener


Response listener for downloadFromUrl(String, DownloadPixmapResponseListener)

Method Summary

Modifier and TypeMethod and Description
public void
downloadComplete(Pixmap pixmap)

Called on the render thread when image was downloaded successfully.

public void
downloadFailed(Throwable t)

Called when image download failed.

Method Detail

downloadCompleteback to summary
public void downloadComplete(Pixmap pixmap)

Called on the render thread when image was downloaded successfully.

downloadFailedback to summary
public void downloadFailed(Throwable t)

Called when image download failed. This might get called on a background thread.

com.badlogic.gdx.graphics back to summary

public final Enum Pixmap.Filter

extends Enum<Pixmap.Filter>
Class Inheritance

Filters to be used with Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int).
Author
mzechner

Field Summary

Modifier and TypeField and Description
public static final Pixmap.Filter
public static final Pixmap.Filter

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Pixmap.Filter
public static Pixmap.Filter[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BiLinearback to summary
public static final Pixmap.Filter BiLinear
NearestNeighbourback to summary
public static final Pixmap.Filter NearestNeighbour

Constructor Detail

Filterback to summary
private Filter()

Method Detail

valueOfback to summary
public static Pixmap.Filter valueOf(String name)
valuesback to summary
public static Pixmap.Filter[] values()
com.badlogic.gdx.graphics back to summary

public final Enum Pixmap.Format

extends Enum<Pixmap.Format>
Class Inheritance

Different pixel formats.
Author
mzechner

Field Summary

Modifier and TypeField and Description
public static final Pixmap.Format
public static final Pixmap.Format
public static final Pixmap.Format
public static final Pixmap.Format
public static final Pixmap.Format
public static final Pixmap.Format
public static final Pixmap.Format

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Pixmap.Format
public static int
public static int
public static int
public static Pixmap.Format
public static Pixmap.Format[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

Alphaback to summary
public static final Pixmap.Format Alpha
Intensityback to summary
public static final Pixmap.Format Intensity
LuminanceAlphaback to summary
public static final Pixmap.Format LuminanceAlpha
RGB565back to summary
public static final Pixmap.Format RGB565
RGB888back to summary
public static final Pixmap.Format RGB888
RGBA4444back to summary
public static final Pixmap.Format RGBA4444
RGBA8888back to summary
public static final Pixmap.Format RGBA8888

Constructor Detail

Formatback to summary
private Format()

Method Detail

fromGdx2DPixmapFormatback to summary
public static Pixmap.Format fromGdx2DPixmapFormat(int format)
toGdx2DPixmapFormatback to summary
public static int toGdx2DPixmapFormat(Pixmap.Format format)
toGlFormatback to summary
public static int toGlFormat(Pixmap.Format format)
toGlTypeback to summary
public static int toGlType(Pixmap.Format format)
valueOfback to summary
public static Pixmap.Format valueOf(String name)
valuesback to summary
public static Pixmap.Format[] values()