Convert non-py5 image objects into Py5Image objects.
1from PIL import Image 2 3 4def setup(): 5 pil_image = Image.open('data/apples.jpg') 6 py5_image = py5.convert_image(pil_image) 7 py5.image(py5_image, 0, 0)
Convert non-py5 image objects into Py5Image objects. This facilitates py5 compatability with other commonly used Python libraries.
This method is comparable to load_image(), except instead of reading image files from disk, it reads image data from other Python objects.
Passed image object types must be known to py5’s image conversion tools. New object types and functions to effect conversions can be registered with register_image_conversion().
convert_image() method has builtin support for conversion of
PIL.Image objects. This will allow users to use image formats that load_image() cannot read. To convert a numpy array into a Py5Image, use create_image_from_numpy().
The caller can optionally pass an existing Py5Image object to put the converted image into using the
dst parameter. This can have performance benefits in code that would otherwise continuously create new Py5Image objects. The converted image width and height must match that of the recycled Py5Image object.
convert_image(obj: Any, *, dst: Py5Image = None) -> Py5Image
dst: Py5Image = None - existing Py5Image object to put the converted image into
obj: Any - object to convert into a Py5Image object
Updated on September 11, 2021 16:51:34pm UTC