from PySide2.QtGui import QImage, QColor # Create a 100x100 QImage image = QImage(100, 100, QImage.Format_RGB32) # Set each pixel to red for x in range(100): for y in range(100): image.setPixelColor(x, y, QColor(255, 0, 0)) # Save the image image.save("red_image.png")
from PySide2.QtGui import QImage # Load an image file image = QImage("image.png") # Check if the image loaded successfully if not image.isNull(): print("Image loaded successfully!") else: print("Failed to load image.")In this example, we load an existing image from a file called "image.png" using the QImage constructor. We then check if the image loaded successfully by using the isNull() method of the QImage object. Overall, PySide2.QtGui is a powerful and versatile package library for GUI development in Python, and the QImage class provides a simple and intuitive way to work with image files.