Datatype for storing images.
def setup(): global photo photo = py5.load_image("laDefense.jpg") def draw(): py5.image(photo, 0, 0)
Datatype for storing images. Py5 can load
.png images using the load_image() function. Py5 can also convert common Python image objects using the convert_image() function. Images may be displayed in 2D and 3D space. The
Py5Image class contains fields for the Py5Image.width and Py5Image.height of the image, as well as arrays called Py5Image.pixels and Py5Image.np_pixels that contain the values for every pixel in the image. The methods described below allow easy access to the image’s pixels and alpha channel and simplify the process of compositing.
Before using the Py5Image.pixels array, be sure to use the Py5Image.load_pixels() method on the image to make sure that the pixel data is properly loaded. Similarly, be sure to use the Py5Image.load_np_pixels() method on the image before using the Py5Image.np_pixels array.
To create a new image, use the create_image() function. Do not use the syntax
Underlying Processing class: PImage
The following methods and fields are provided:
apply_filter(): Apply an image filter.
blend(): Blends a region of pixels into the image specified by the
copy(): Copies a region of pixels from one image into another.
get_pixels(): Reads the color of any pixel or grabs a section of an image.
height: The height of the image in units of pixels.
load_np_pixels(): Loads the pixel data of the image into the Py5Image.np_pixels array.
load_pixels(): Loads the pixel data for the image into its Py5Image.pixels array.
mask(): Masks part of an image from displaying by loading another image and using it as an alpha channel.
np_pixelsarray contains the values for all the pixels in the image.
pixel_density: Pixel density of the Py5Image object.
pixel_height: Height of the Py5Image object in pixels.
pixel_width: Width of the Py5Image object in pixels.
pixels: The pixels array contains the values for all the pixels in the image.
save(): Save the Py5Image object to an image file.
set_np_pixels(): Set the entire contents of Py5Image.np_pixels to the contents of another properly sized and typed numpy array.
set_pixels(): Changes the color of any pixel or writes an image directly into the Py5Image object.
update_np_pixels(): Updates the image with the data in the Py5Image.np_pixels array.
update_pixels(): Updates the image with the data in its Py5Image.pixels array.
width: The width of the image in units of pixels.
Updated on March 06, 2023 02:49:26am UTC