AbstractImage Class

Inheritance diagram of AbstractImage

class AbstractImage(width, height)

Abstract class representing an image.

Variables:
  • width – Width of image
  • height – Height of image
  • anchor_x – X coordinate of anchor, relative to left edge of image data
  • anchor_y – Y coordinate of anchor, relative to bottom edge of image data

Constructor:

__init__(width, height)

Methods:

blit(x, y[, z]) Draw this image to the active framebuffers.
blit_into(source, x, y, z) Draw source on this image.
blit_to_texture(target, level, x, y[, z]) Draw this image on the currently bound texture at target.
get_image_data() Get an ImageData view of this image.
get_mipmapped_texture() Retrieve a Texture instance with all mipmap levels filled in.
get_region(x, y, width, height) Retrieve a rectangular region of this image.
get_texture([rectangle, force_rectangle]) A Texture view of this image.
save([filename, file, encoder]) Save this image to a file.

Attributes:

anchor_x Type: int
anchor_y Type: int
image_data An ImageData view of this image.
mipmapped_texture A Texture view of this image.
texture Get a Texture view of this image.

Methods

AbstractImage.blit(x, y, z=0)

Draw this image to the active framebuffers.

The image will be drawn with the lower-left corner at (x - anchor_x, y - anchor_y, z).

AbstractImage.blit_into(source, x, y, z)

Draw source on this image.

source will be copied into this image such that its anchor point is aligned with the x and y parameters. If this image is a 3D texture, the z coordinate gives the image slice to copy into.

Note that if source is larger than this image (or the positioning would cause the copy to go out of bounds) then you must pass a region of source to this method, typically using get_region().

AbstractImage.blit_to_texture(target, level, x, y, z=0)

Draw this image on the currently bound texture at target.

This image is copied into the texture such that this image’s anchor point is aligned with the given x and y coordinates of the destination texture. If the currently bound texture is a 3D texture, the z coordinate gives the image slice to blit into.

AbstractImage.get_image_data()

Get an ImageData view of this image.

Changes to the returned instance may or may not be reflected in this image.

Return type:ImageData

Note

Since pyglet 1.1

AbstractImage.get_mipmapped_texture()

Retrieve a Texture instance with all mipmap levels filled in.

Requires that image dimensions be powers of 2.

Return type:Texture

Note

Since pyglet 1.1

AbstractImage.get_region(x, y, width, height)

Retrieve a rectangular region of this image.

Parameters:
  • x (int) – Left edge of region.
  • y (int) – Bottom edge of region.
  • width (int) – Width of region.
  • height (int) – Height of region.
Return type:

AbstractImage

AbstractImage.get_texture(rectangle=False, force_rectangle=False)

A Texture view of this image.

By default, textures are created with dimensions that are powers of two. Smaller images will return a TextureRegion that covers just the image portion of the larger texture. This restriction is required on older video cards, and for compressed textures, or where texture repeat modes will be used, or where mipmapping is desired.

If the rectangle parameter is True, this restriction is ignored and a texture the size of the image may be created if the driver supports the GL_ARB_texture_rectangle or GL_NV_texture_rectangle extensions. If the extensions are not present, the image already is a texture, or the image has power 2 dimensions, the rectangle parameter is ignored.

Examine Texture.target to determine if the returned texture is a rectangle (GL_TEXTURE_RECTANGLE_ARB or GL_TEXTURE_RECTANGLE_NV) or not (GL_TEXTURE_2D).

If the force_rectangle parameter is True, one of these extensions must be present, and the returned texture always has target GL_TEXTURE_RECTANGLE_ARB or GL_TEXTURE_RECTANGLE_NV.

Changes to the returned instance may or may not be reflected in this image.

Parameters:
  • rectangle (bool) – True if the texture can be created as a rectangle.
  • force_rectangle (bool) – True if the texture must be created as a rectangle. Since: pyglet 1.1.4.
Return type:

Texture

Note

Since pyglet 1.1

AbstractImage.save(filename=None, file=None, encoder=None)

Save this image to a file.

Parameters:
  • filename (str) – Used to set the image file format, and to open the output file if file is unspecified.
  • file (file-like object or None) – File to write image data to.
  • encoder (ImageEncoder or None) – If unspecified, all encoders matching the filename extension are tried. If all fail, the exception from the first one attempted is raised.

Attributes

AbstractImage.anchor_x = 0
AbstractImage.anchor_y = 0
AbstractImage.image_data

An ImageData view of this image.

Changes to the returned instance may or may not be reflected in this image. Read-only.

Warning

Deprecated. Use get_image_data.

Type:ImageData
AbstractImage.mipmapped_texture

A Texture view of this image.

The returned Texture will have mipmaps filled in for all levels. Requires that image dimensions be powers of 2. Read-only.

Warning

Deprecated. Use get_mipmapped_texture.

Type:Texture
AbstractImage.texture

Get a Texture view of this image.

Changes to the returned instance may or may not be reflected in this image.

Warning

Deprecated. Use get_texture.

Type:Texture

Table Of Contents

Previous topic

get_encoders Function

Next topic

AbstractImageSequence Class