Datatype for storing images.
1 2 3 4 5 6 7
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 Java 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(): Reads the color of any pixel or grabs a section of an image.
height: The height of the image in units of pixels.
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.
width: The width of the image in units of pixels.
Updated on September 16, 2021 14:31:43pm UTC