Table Of Contents
Image¶
The Image widget is used to display an image:
wimg = Image(source='mylogo.png')
Asynchronous Loading¶
To load an image asynchronously (for example from an external webserver), use the AsyncImage subclass:
aimg = AsyncImage(source='http://mywebsite.com/logo.png')
Alignment¶
By default, the image is centered and fits inside the widget bounding box. If you don’t want that, you can inherit from Image and create your own style.
For example, if you want your image to be the same size as your widget, you could do:
class FullImage(Image):
pass
And in your kivy language file:
<FullImage>:
canvas:
Color:
rgb: (1, 1, 1)
Rectangle:
texture: self.texture
size: self.size
pos: self.pos
- class kivy.uix.image.Image(**kwargs)[source]¶
Bases: kivy.uix.widget.Widget
Image class, see module documentation for more information.
- allow_stretch¶
If True, the normalized image size will be maximized to fit in the image box. Otherwise, if the box is too tall, the image will not be stretched more than 1:1 pixels.
New in version 1.0.7.
allow_stretch is a BooleanProperty and defaults to False.
- anim_delay¶
Delay the animation if the image is sequenced (like an animated gif). If anim_delay is set to -1, the animation will be stopped.
New in version 1.0.8.
anim_delay is a NumericProperty and defaults to 0.25 (4 FPS).
- color¶
Image color, in the format (r, g, b, a). This attribute can be used to ‘tint’ an image. Be careful: if the source image is not gray/white, the color will not really work as expected.
New in version 1.0.6.
color is a ListProperty and defaults to [1, 1, 1, 1].
- image_ratio¶
Ratio of the image (width / float(height).
image_ratio is a AliasProperty and is read-only.
- keep_data¶
If True, the underlaying _coreimage will store the raw image data. This is useful when performing pixel based collision detection.
New in version 1.3.0.
keep_data is a BooleanProperty and defaults to False.
- keep_ratio¶
If False along with allow_stretch being True, the normalized image size will be maximized to fit in the image box and ignores the aspect ratio of the image. Otherwise, if the box is too tall, the image will not be stretched more than 1:1 pixels.
New in version 1.0.8.
keep_ratio is a BooleanProperty and defaults to True.
- mipmap¶
Indicate if you want OpenGL mipmapping to be applied to the texture. Read Mipmapping for more information.
New in version 1.0.7.
mipmap is a BooleanProperty and defaults to False.
- nocache¶
If this property is set True, the image will not be added to the internal cache. The cache will simply ignore any calls trying to append the core image.
New in version 1.6.0.
nocache is a BooleanProperty and defaults to False.
- norm_image_size¶
Normalized image size within the widget box.
This size will always fit the widget size and will preserve the image ratio.
norm_image_size is a AliasProperty and is read-only.
- reload()[source]¶
Reload image from disk. This facilitates re-loading of images from disk in case the image content changes.
New in version 1.3.0.
Usage:
im = Image(source = '1.jpg') # -- do something -- im.reload() # image will be re-loaded from disk
- source¶
Filename / source of your image.
source is a StringProperty and defaults to None.
- texture¶
Texture object of the image.
Depending of the texture creation, the value will be a Texture or a TextureRegion object.
texture is a ObjectProperty and defaults to None.
- class kivy.uix.image.AsyncImage(**kwargs)[source]¶
Bases: kivy.uix.image.Image
Asynchronous Image class. See the module documentation for more information.
Note
The AsyncImage is a specialized form of the Image class. You may want to refer to the loader documentation and in particular, the ProxyImage for more detail on how to handle events around asynchronous image loading.