Table Of Contents
Image¶
Core classes for loading images and converting them to a Texture. The raw image data can be keep in memory for further access.
- class kivy.core.image.Image(arg, **kwargs)[source]¶
Bases: kivy.event.EventDispatcher
Load an image and store the size and texture.
New in version In: 1.0.7, the mipmap attribute has been added. The texture_mipmap and texture_rectangle have been deleted.
New in version In: 1.0.8, an Image widget can change its texture. A new event ‘on_texture’ has been introduced. New methods for handling sequenced animation have been added.
Parameters: - arg : can be a string (str), Texture or Image object.
A string is interpreted as a path to the image to be loaded. You can also provide a texture object or an already existing image object. In the latter case, a real copy of the given image object will be returned.
- keep_data : bool, defaults to False.
Keep the image data when the texture is created.
- scale : float, defaults to 1.0
Scale of the image.
- mipmap : bool, defaults to False
Create mipmap for the texture.
- anim_delay: float, defaults to .25
Delay in seconds between each animation frame. Lower values means faster animation.
- anim_available[source]¶
Return True if this Image instance has animation available.
New in version 1.0.8.
- anim_delay¶
Delay between each animation frame. A lower value means faster animation.
New in version 1.0.8.
- anim_index[source]¶
Return the index number of the image currently in the texture.
New in version 1.0.8.
- anim_reset(allow_anim)[source]¶
Reset an animation if available.
New in version 1.0.8.
Parameters: - allow_anim: bool
Indicate whether the animation should restart playing or not.
Usage:
# start/reset animation image.anim_reset(True) # or stop the animation image.anim_reset(False)
You can change the animation speed whilst it is playing:
# Set to 20 FPS image.anim_delay = 1 / 20.
- filename¶
Get/set the filename of image
- image¶
Get/set the data image object
- static load(filename, **kwargs)[source]¶
Load an image
Parameters: - filename : str
Filename of the image.
- keep_data : bool, defaults to False
Keep the image data when the texture is created.
- nocache[source]¶
Indicate whether the texture will not be stored in the cache or not.
New in version 1.6.0.
- on_texture(*largs)[source]¶
- This event is fired when the texture reference or content has
- changed. It is normally used for sequenced images.
New in version 1.0.8.
- read_pixel(x, y)[source]¶
For a given local x/y position, return the pixel color at that position.
Warning
This function can only be used with images loaded with the keep_data=True keyword. For example:
m = Image.load('image.png', keep_data=True) color = m.read_pixel(150, 150)
Parameters: - x : int
Local x coordinate of the pixel in question.
- y : int
Local y coordinate of the pixel in question.
- remove_from_cache()[source]¶
Remove the Image from cache. This facilitates re-loading of images from disk in case the image content has changed.
New in version 1.3.0.
Usage:
im = CoreImage('1.jpg') # -- do something -- im.remove_from_cache() im = CoreImage('1.jpg') # this time image will be re-loaded from disk
- save(filename, flipped=False)[source]¶
Save image texture to file.
The filename should have the ‘.png’ extension because the texture data read from the GPU is in the RGBA format. ‘.jpg’ might work but has not been heavilly tested so some providers might break when using it. Any other extensions are not officially supported.
Example:
# Save an core image object from kivy.core.image import Image img = Image('hello.png') img.save('hello2.png') # Save a texture texture = Texture.create(...) img = Image(texture) img.save('hello3.png')
New in version 1.7.0.
Changed in version 1.8.0: Parameter flipped added to flip the image before saving, default to False.
- class kivy.core.image.ImageData(width, height, fmt, data, source=None, flip_vertical=True)[source]¶
Bases: object
Container for images and mipmap images. The container will always have at least the mipmap level 0.
- add_mipmap(level, width, height, data)[source]¶
Add a image for a specific mipmap level.
New in version 1.0.7.
- flip_vertical¶
Indicate if the texture will need to be vertically flipped
- fmt¶
Decoded image format, one of a available texture format
- get_mipmap(level)[source]¶
Get the mipmap image at a specific level if it exists
New in version 1.0.7.
- mipmaps¶
Data for each mipmap.
- source¶
Image source, if available