PySide6.QtGui.QImage¶
- class QImage¶
- The - QImageclass provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device. More…- Synopsis¶- Methods¶- def - __init__()
- def - allGray()
- def - bitPlaneCount()
- def - bytesPerLine()
- def - cacheKey()
- def - color()
- def - colorSpace()
- def - colorTable()
- def - constBits()
- def - constScanLine()
- def - convertTo()
- def - convertedTo()
- def - copy()
- def - detachMetadata()
- def - dotsPerMeterX()
- def - dotsPerMeterY()
- def - fill()
- def - format()
- def - invertPixels()
- def - isGrayscale()
- def - isNull()
- def - load()
- def - loadFromData()
- def - mirror()
- def - mirrored()
- def - offset()
- def - __ne__()
- def - __eq__()
- def - pixel()
- def - pixelColor()
- def - pixelFormat()
- def - pixelIndex()
- def - rect()
- def - rgbSwap()
- def - rgbSwapped()
- def - save()
- def - scaled()
- def - scaledToHeight()
- def - scaledToWidth()
- def - setColor()
- def - setColorCount()
- def - setColorSpace()
- def - setColorTable()
- def - setOffset()
- def - setPixel()
- def - setPixelColor()
- def - setText()
- def - size()
- def - sizeInBytes()
- def - smoothScaled()
- def - swap()
- def - text()
- def - textKeys()
- def - transformed()
- def - valid()
 - Static functions¶- def - fromData()
- def - toImageFormat()
- def - toPixelFormat()
- def - trueMatrix()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Qt provides four classes for handling image data: - QImage,- QPixmap,- QBitmapand- QPicture.- QImageis designed and optimized for I/O, and for direct pixel access and manipulation, while- QPixmapis designed and optimized for showing images on screen.- QBitmapis only a convenience class that inherits- QPixmap, ensuring a depth of 1. Finally, the- QPictureclass is a paint device that records and replays- QPaintercommands.- Because - QImageis a- QPaintDevicesubclass,- QPaintercan be used to draw directly onto images. When using- QPainteron a- QImage, the painting can be performed in another thread than the current GUI thread.- The - QImageclass supports several image formats described by the- Formatenum. These include monochrome, 8-bit, 32-bit and alpha-blended images which are available in all versions of Qt 4.x.- QImageprovides a collection of functions that can be used to obtain a variety of information about the image. There are also several functions that enables transformation of the image.- QImageobjects can be passed around by value since the- QImageclass uses implicit data sharing.- QImageobjects can also be streamed and compared.- Note - If you would like to load - QImageobjects in a static build of Qt, refer to the Plugin HowTo.- Warning - Painting on a - QImagewith the format- Format_Indexed8or- Format_CMYK8888is not supported.- Reading and Writing Image Files¶- QImageprovides several ways of loading an image file: The file can be loaded when constructing the- QImageobject, or by using the load() or loadFromData() functions later on.- QImagealso provides the static fromData() function, constructing a- QImagefrom the given data. When loading an image, the file name can either refer to an actual file on disk or to one of the application’s embedded resources. See The Qt Resource System overview for details on how to embed images and other resource files in the application’s executable.- Simply call the save() function to save a - QImageobject.- The complete list of supported file formats are available through the - supportedImageFormats()and- supportedImageFormats()functions. New file formats can be added as plugins. By default, Qt supports the following formats:- Format - Description - Qt’s support - BMP - Windows Bitmap - Read/write - GIF - Graphic Interchange Format (optional) - Read - JPG - Joint Photographic Experts Group - Read/write - JPEG - Joint Photographic Experts Group - Read/write - PNG - Portable Network Graphics - Read/write - PBM - Portable Bitmap - Read - PGM - Portable Graymap - Read - PPM - Portable Pixmap - Read/write - XBM - X11 Bitmap - Read/write - XPM - X11 Pixmap - Read/write - Image Information¶- QImageprovides a collection of functions that can be used to obtain a variety of information about the image:- Available Functions - Geometry - The - size(),- width(),- height(), dotsPerMeterX(), and dotsPerMeterY() functions provide information about the image size and aspect ratio.- The - rect()function returns the image’s enclosing rectangle. The- valid()function tells if a given pair of coordinates is within this rectangle. The- offset()function returns the number of pixels by which the image is intended to be offset by when positioned relative to other images, which also can be manipulated using the- setOffset()function.- Colors - The color of a pixel can be retrieved by passing its coordinates to the - pixel()function. The- pixel()function returns the color as a- QRgbvalue independent of the image’s format.- In case of monochrome and 8-bit images, the - colorCount()and colorTable() functions provide information about the color components used to store the image data: The colorTable() function returns the image’s entire color table. To obtain a single entry, use the- pixelIndex()function to retrieve the pixel index for a given pair of coordinates, then use the color() function to retrieve the color. Note that if you create an 8-bit image manually, you have to set a valid color table on the image as well.- The hasAlphaChannel() function tells if the image’s format respects the alpha channel, or not. The allGray() and isGrayscale() functions tell whether an image’s colors are all shades of gray. - See also the - Pixel Manipulationand- Image Transformationssections.- Text - The text() function returns the image text associated with the given text key. An image’s text keys can be retrieved using the textKeys() function. Use the - setText()function to alter an image’s text.- Low-level information - The - depth()function returns the depth of the image. The supported depths are 1 (monochrome), 8, 16, 24 and 32 bits. The bitPlaneCount() function tells how many of those bits that are used. For more information see the- Image Formatssection.- The format(), bytesPerLine(), and sizeInBytes() functions provide low-level information about the data stored in the image. - The cacheKey() function returns a number that uniquely identifies the contents of this - QImageobject.- Pixel Manipulation¶- The functions used to manipulate an image’s pixels depend on the image format. The reason is that monochrome and 8-bit images are index-based and use a color lookup table, while 32-bit images store ARGB values directly. For more information on image formats, see the - Image Formatssection.- In case of a 32-bit image, the - setPixel()function can be used to alter the color of the pixel at the given coordinates to any other color specified as an ARGB quadruplet. To make a suitable- QRgbvalue, use the- qRgb()(adding a default alpha component to the given RGB values, i.e. creating an opaque color) or- qRgba()function. For example:- 32-bit  - image = QImage(3, 3, QImage.Format_RGB32) value = QRgb() value = qRgb(189, 149, 39) # 0xffbd9527 image.setPixel(1, 1, value) value = qRgb(122, 163, 39) # 0xff7aa327 image.setPixel(0, 1, value) image.setPixel(1, 0, value) value = qRgb(237, 187, 51) # 0xffedba31 image.setPixel(2, 1, value) - In case of a 8-bit and monchrome images, the pixel value is only an index from the image’s color table. So the - setPixel()function can only be used to alter the color of the pixel at the given coordinates to a predefined color from the image’s color table, i.e. it can only change the pixel’s index value. To alter or add a color to an image’s color table, use the- setColor()function.- An entry in the color table is an ARGB quadruplet encoded as an - QRgbvalue. Use the- qRgb()and- qRgba()functions to make a suitable- QRgbvalue for use with the- setColor()function. For example:- 8-bit  - image = QImage(3, 3, QImage.Format_Indexed8) value = QRgb() value = qRgb(122, 163, 39) # 0xff7aa327 image.setColor(0, value) value = qRgb(237, 187, 51) # 0xffedba31 image.setColor(1, value) value = qRgb(189, 149, 39) # 0xffbd9527 image.setColor(2, value) image.setPixel(0, 1, 0) image.setPixel(1, 0, 0) image.setPixel(1, 1, 2) image.setPixel(2, 1, 1) - For images with more than 8-bit per color-channel. The methods - setPixelColor()and- pixelColor()can be used to set and get with- QColorvalues.- QImagealso provide the scanLine() function which returns a pointer to the pixel data at the scanline with the given index, and the bits() function which returns a pointer to the first pixel data (this is equivalent to- scanLine(0)).- Image Formats¶- Each pixel stored in a - QImageis represented by an integer. The size of the integer varies depending on the format.- QImagesupports several image formats described by the- Formatenum.- Monochrome images are stored using 1-bit indexes into a color table with at most two colors. There are two different types of monochrome images: big endian (MSB first) or little endian (LSB first) bit order. - 8-bit images are stored using 8-bit indexes into a color table, i.e. they have a single byte per pixel. The color table is a QList< - QRgb>, and the- QRgbtypedef is equivalent to an unsigned int containing an ARGB quadruplet on the format 0xAARRGGBB.- 32-bit images have no color table; instead, each pixel contains an - QRgbvalue. There are three different types of 32-bit images storing RGB (i.e. 0xffRRGGBB), ARGB and premultiplied ARGB values respectively. In the premultiplied format the red, green, and blue channels are multiplied by the alpha component divided by 255.- An image’s format can be retrieved using the format() function. Use the - convertToFormat()functions to convert an image into another format. The allGray() and isGrayscale() functions tell whether a color image can safely be converted to a grayscale image.- Image Transformations¶- QImagesupports a number of functions for creating a new image that is a transformed version of the original: The createAlphaMask() function builds and returns a 1-bpp mask from the alpha buffer in this image, and the createHeuristicMask() function creates and returns a 1-bpp heuristic mask for this image. The latter function works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges.- The - mirrored()function returns a mirror of the image in the desired direction, the- scaled()returns a copy of the image scaled to a rectangle of the desired measures, and the- rgbSwapped()function constructs a BGR image from a RGB image.- The - scaledToWidth()and- scaledToHeight()functions return scaled copies of the image.- The transformed() function returns a copy of the image that is transformed with the given transformation matrix and transformation mode: Internally, the transformation matrix is adjusted to compensate for unwanted translation, i.e. transformed() returns the smallest image containing all transformed points of the original image. The static - trueMatrix()function returns the actual matrix used for transforming the image.- There are also functions for changing attributes of an image in-place: - Function - Description - setDotsPerMeterX() - Defines the aspect ratio by setting the number of pixels that fit horizontally in a physical meter. - setDotsPerMeterY() - Defines the aspect ratio by setting the number of pixels that fit vertically in a physical meter. - Fills the entire image with the given pixel value. - invertPixels() - Inverts all pixel values in the image using the given - InvertModevalue.- setColorTable() - Sets the color table used to translate color indexes. Only monochrome and 8-bit formats. - setColorCount() - Resizes the color table. Only monochrome and 8-bit formats. - See also - QImageReader- QImageWriter- QPixmap- QSvgRendererImage Composition ExampleScribble Example- class InvertMode¶
- This enum type is used to describe how pixel values should be inverted in the invertPixels() function. - Constant - Description - QImage.InvertRgb - Invert only the RGB values and leave the alpha channel unchanged. - QImage.InvertRgba - Invert all channels, including the alpha channel. - See also 
 - class Format¶
- The following image formats are available in Qt. See the notes after the table. - Constant - Description - QImage.Format_Invalid - The image is invalid. - QImage.Format_Mono - The image is stored using 1-bit per pixel. Bytes are packed with the most significant bit (MSB) first. - QImage.Format_MonoLSB - The image is stored using 1-bit per pixel. Bytes are packed with the less significant bit (LSB) first. - QImage.Format_Indexed8 - The image is stored using 8-bit indexes into a colormap. - QImage.Format_RGB32 - The image is stored using a 32-bit RGB format (0xffRRGGBB). - QImage.Format_ARGB32 - The image is stored using a 32-bit ARGB format (0xAARRGGBB). - QImage.Format_ARGB32_Premultiplied - The image is stored using a premultiplied 32-bit ARGB format (0xAARRGGBB), i.e. the red, green, and blue channels are multiplied by the alpha component divided by 255. (If RR, GG, or BB has a higher value than the alpha channel, the results are undefined.) Certain operations (such as image composition using alpha blending) are faster using premultiplied ARGB32 than with plain ARGB32. - QImage.Format_RGB16 - The image is stored using a 16-bit RGB format (5-6-5). - QImage.Format_ARGB8565_Premultiplied - The image is stored using a premultiplied 24-bit ARGB format (8-5-6-5). - QImage.Format_RGB666 - The image is stored using a 24-bit RGB format (6-6-6). The unused most significant bits is always zero. - QImage.Format_ARGB6666_Premultiplied - The image is stored using a premultiplied 24-bit ARGB format (6-6-6-6). - QImage.Format_RGB555 - The image is stored using a 16-bit RGB format (5-5-5). The unused most significant bit is always zero. - QImage.Format_ARGB8555_Premultiplied - The image is stored using a premultiplied 24-bit ARGB format (8-5-5-5). - QImage.Format_RGB888 - The image is stored using a 24-bit RGB format (8-8-8). - QImage.Format_RGB444 - The image is stored using a 16-bit RGB format (4-4-4). The unused bits are always zero. - QImage.Format_ARGB4444_Premultiplied - The image is stored using a premultiplied 16-bit ARGB format (4-4-4-4). - QImage.Format_RGBX8888 - The image is stored using a 32-bit byte-ordered RGB(x) format (8-8-8-8). This is the same as the Format_RGBA8888 except alpha must always be 255. - QImage.Format_RGBA8888 - The image is stored using a 32-bit byte-ordered RGBA format (8-8-8-8). Unlike ARGB32 this is a byte-ordered format, which means the 32bit encoding differs between big endian and little endian architectures, being respectively (0xRRGGBBAA) and (0xAABBGGRR). The order of the colors is the same on any architecture if read as bytes 0xRR,0xGG,0xBB,0xAA. - QImage.Format_RGBA8888_Premultiplied - The image is stored using a premultiplied 32-bit byte-ordered RGBA format (8-8-8-8). - QImage.Format_BGR30 - The image is stored using a 32-bit BGR format (x-10-10-10). - QImage.Format_A2BGR30_Premultiplied - The image is stored using a 32-bit premultiplied ABGR format (2-10-10-10). - QImage.Format_RGB30 - The image is stored using a 32-bit RGB format (x-10-10-10). - QImage.Format_A2RGB30_Premultiplied - The image is stored using a 32-bit premultiplied ARGB format (2-10-10-10). - QImage.Format_Alpha8 - The image is stored using an 8-bit alpha only format. - QImage.Format_Grayscale8 - The image is stored using an 8-bit grayscale format. - QImage.Format_Grayscale16 - The image is stored using an 16-bit grayscale format. - QImage.Format_RGBX64 - The image is stored using a 64-bit halfword-ordered RGB(x) format (16-16-16-16). This is the same as the Format_RGBA64 except alpha must always be 65535. - QImage.Format_RGBA64 - The image is stored using a 64-bit halfword-ordered RGBA format (16-16-16-16). - QImage.Format_RGBA64_Premultiplied - The image is stored using a premultiplied 64-bit halfword-ordered RGBA format (16-16-16-16). - QImage.Format_BGR888 - The image is stored using a 24-bit BGR format. - QImage.Format_RGBX16FPx4 - The image is stored using a four 16-bit halfword floating point RGBx format (16FP-16FP-16FP-16FP). This is the same as the Format_RGBA16FPx4 except alpha must always be 1.0. - QImage.Format_RGBA16FPx4 - The image is stored using a four 16-bit halfword floating point RGBA format (16FP-16FP-16FP-16FP). - QImage.Format_RGBA16FPx4_Premultiplied - The image is stored using a premultiplied four 16-bit halfword floating point RGBA format (16FP-16FP-16FP-16FP). - QImage.Format_RGBX32FPx4 - The image is stored using a four 32-bit floating point RGBx format (32FP-32FP-32FP-32FP). This is the same as the Format_RGBA32FPx4 except alpha must always be 1.0. - QImage.Format_RGBA32FPx4 - The image is stored using a four 32-bit floating point RGBA format (32FP-32FP-32FP-32FP). - QImage.Format_RGBA32FPx4_Premultiplied - The image is stored using a premultiplied four 32-bit floating point RGBA format (32FP-32FP-32FP-32FP). - QImage.Format_CMYK8888 - The image is stored using a 32-bit byte-ordered CMYK format. - Note - Drawing into a - QImagewith format QImage::Format_Indexed8 or QImage::Format_CMYK8888 is not supported.- Note - Avoid most rendering directly to most of these formats using - QPainter. Rendering is best optimized to the- Format_RGB32and- Format_ARGB32_Premultipliedformats, and secondarily for rendering to the- Format_RGB16,- Format_RGBX8888,- Format_RGBA8888_Premultiplied,- Format_RGBX64and- Format_RGBA64_Premultipliedformats- See also 
 - __init__()¶
 - __init__(image)
- Parameters:
- image – - QImage
 
 - Constructs a shallow copy of the given - image.- For more information about shallow copies, see the Implicit Data Sharing documentation. - See also - __init__(xpm)
- Parameters:
- xpm – - char[]
 
 - __init__(fileName[, format=None])
- Parameters:
- fileName – str 
- format – str 
 
 
 - __init__(width, height, format)
- Parameters:
- width – int 
- height – int 
- format – - Format
 
 
 - __init__(arg__1, width, height, format)
- Parameters:
- arg__1 – str 
- width – int 
- height – int 
- format – - Format
 
 
 - __init__(arg__1, width, height, bytes_per_line, format)
- Parameters:
- arg__1 – str 
- width – int 
- height – int 
- bytes_per_line – int 
- format – - Format
 
 
 - __init__(data, width, height, format[, cleanupFunction=None[, cleanupInfo=None]])
- Parameters:
- data – str 
- width – int 
- height – int 
- format – - Format
- cleanupFunction – - QImageCleanupFunction
- cleanupInfo – - void
 
 
 - __init__(data, width, height, bytesPerLine, format[, cleanupFunction=None[, cleanupInfo=None]])
- Parameters:
- data – str 
- width – int 
- height – int 
- bytesPerLine – int 
- format – - Format
- cleanupFunction – - QImageCleanupFunction
- cleanupInfo – - void
 
 
 - allGray()¶
- Return type:
- bool 
 
 - applyColorTransform(transform)¶
- Parameters:
- transform – - QColorTransform
 
 - applyColorTransform(transform, format[, flags=Qt.AutoColor])
- Parameters:
- transform – - QColorTransform
- format – - Format
- flags – Combination of - ImageConversionFlag
 
 
 - bitPlaneCount()¶
- Return type:
- int 
 
 - bytesPerLine()¶
- Return type:
- int 
 
 - cacheKey()¶
- Return type:
- int 
 
 - color(i)¶
- Parameters:
- i – int 
- Return type:
- int 
 
 - colorSpace()¶
- Return type:
 
 - colorTable()¶
- Return type:
- .list of unsigned int 
 
 - colorTransformed(transform)¶
- Parameters:
- transform – - QColorTransform
- Return type:
 
 - colorTransformed(transform, format[, flags=Qt.AutoColor])
- Parameters:
- transform – - QColorTransform
- format – - Format
- flags – Combination of - ImageConversionFlag
 
- Return type:
 
 - constBits()¶
- Return type:
- str 
 
 - constScanLine(arg__1)¶
- Parameters:
- arg__1 – int 
- Return type:
- PyObject 
 
 - convertTo(f[, flags=Qt.AutoColor])¶
- Parameters:
- f – - Format
- flags – Combination of - ImageConversionFlag
 
 
 - convertToColorSpace(colorSpace)¶
- Parameters:
- colorSpace – - QColorSpace
 
 - convertToColorSpace(colorSpace, format[, flags=Qt.AutoColor])
- Parameters:
- colorSpace – - QColorSpace
- format – - Format
- flags – Combination of - ImageConversionFlag
 
 
 - convertToFormat(f[, flags=Qt.AutoColor])¶
- Parameters:
- f – - Format
- flags – Combination of - ImageConversionFlag
 
- Return type:
 
 - convertToFormat(f, colorTable[, flags=Qt.AutoColor])
- Parameters:
- f – - Format
- colorTable – .list of unsigned int 
- flags – Combination of - ImageConversionFlag
 
- Return type:
 
 - convertToFormat_helper(format, flags)¶
- Parameters:
- format – - Format
- flags – Combination of - ImageConversionFlag
 
- Return type:
 
 - convertToFormat_inplace(format, flags)¶
- Parameters:
- format – - Format
- flags – Combination of - ImageConversionFlag
 
- Return type:
- bool 
 
 - convertedTo(f[, flags=Qt.AutoColor])¶
- Parameters:
- f – - Format
- flags – Combination of - ImageConversionFlag
 
- Return type:
 
 - convertedToColorSpace(colorSpace)¶
- Parameters:
- colorSpace – - QColorSpace
- Return type:
 
 - convertedToColorSpace(colorSpace, format[, flags=Qt.AutoColor])
- Parameters:
- colorSpace – - QColorSpace
- format – - Format
- flags – Combination of - ImageConversionFlag
 
- Return type:
 
 - Returns a sub-area of the image as a new image. - The returned image is copied from the position ( - rectangle.x(),- rectangle.y()) in this image, and will always have the size of the given- rectangle.- In areas beyond this image, pixels are set to 0. For 32-bit RGB images, this means black; for 32-bit ARGB images, this means transparent black; for 8-bit images, this means the color with index 0 in the color table which can be anything; for 1-bit images, this means Qt::color0. - If the given - rectangleis a null rectangle the entire image is copied.- See also - QImage()- copy(x, y, w, h)
- Parameters:
- x – int 
- y – int 
- w – int 
- h – int 
 
- Return type:
 
 - This is an overloaded function. - The returned image is copied from the position ( - x,- y) in this image, and will always have the given- widthand- height. In areas beyond this image, pixels are set to 0.- createAlphaMask([flags=Qt.AutoColor])¶
- Parameters:
- flags – Combination of - ImageConversionFlag
- Return type:
 
 - createMaskFromColor(color[, mode=Qt.MaskInColor])¶
 - detachMetadata([invalidateCache=false])¶
- Parameters:
- invalidateCache – bool 
 
 - dotsPerMeterX()¶
- Return type:
- int 
 
 - dotsPerMeterY()¶
- Return type:
- int 
 
 - fill(color)¶
- Parameters:
- color – - GlobalColor
 
 - This is an overloaded function. - Fills the image with the given - color, described as a standard global color.- fill(color)
- Parameters:
- color – - QColor
 
 - This is an overloaded function. - Fills the entire image with the given - color.- If the depth of the image is 1, the image will be filled with 1 if - colorequals Qt::color1; it will otherwise be filled with 0.- If the depth of the image is 8, the image will be filled with the index corresponding the - colorin the color table if present; it will otherwise be filled with 0.- fill(pixel)
- Parameters:
- pixel – int 
 
 - Fills the entire image with the given - pixelValue.- If the depth of this image is 1, only the lowest bit is used. If you say fill(0), fill(2), etc., the image is filled with 0s. If you say fill(1), fill(3), etc., the image is filled with 1s. If the depth is 8, the lowest 8 bits are used and if the depth is 16 the lowest 16 bits are used. - If the image depth is higher than 32bit the result is undefined. - Note - There are no corresponding value getter, though - pixelIndex()will return the same value for indexed formats, and- pixel()for RGB32, ARGB32, and ARGB32PM formats.- See also - depth()- Image Transformations- static fromData(data[, format=None])¶
- Parameters:
- data – - QByteArrayView
- format – str 
 
- Return type:
 
 - This is an overloaded function. - Constructs a - QImagefrom the given QByteArray- data.- static fromData(data[, format=None])
- Parameters:
- data – - QByteArray
- format – str 
 
- Return type:
 
 - This is an overloaded function. - Constructs a - QImagefrom the given QByteArray- data.- hasAlphaChannel()¶
- Return type:
- bool 
 
 - invertPixels([mode=QImage.InvertMode.InvertRgb])¶
- Parameters:
- mode – - InvertMode
 
 - isGrayscale()¶
- Return type:
- bool 
 
 - isNull()¶
- Return type:
- bool 
 
 - Returns - trueif it is a null image, otherwise returns- false.- A null image has all parameters set to zero and no allocated data. - load(fileName[, format=None])
- Parameters:
- fileName – str 
- format – str 
 
- Return type:
- bool 
 
 - loadFromData(data[, format=None])¶
- Parameters:
- data – - QByteArrayView
- format – str 
 
- Return type:
- bool 
 
 - This is an overloaded function. - Loads an image from the given QByteArray - data.- loadFromData(data[, format=None])
- Parameters:
- data – - QByteArray
- format – str 
 
- Return type:
- bool 
 
 - This is an overloaded function. - Loads an image from the given QByteArray - data.- mirror([horizontally=false[, vertically=true]])¶
- Parameters:
- horizontally – bool 
- vertically – bool 
 
 
 - Mirrors of the image in the horizontal and/or the vertical direction depending on whether - horizontaland- verticalare set to true or false.- See also - mirrored()- Image Transformations- mirrored([horizontally=false[, vertically=true]])¶
- Parameters:
- horizontally – bool 
- vertically – bool 
 
- Return type:
 
 - mirrored_helper(horizontal, vertical)¶
- Parameters:
- horizontal – bool 
- vertical – bool 
 
- Return type:
 
 - mirrored_inplace(horizontal, vertical)¶
- Parameters:
- horizontal – bool 
- vertical – bool 
 
 
 - Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images. - See also - setOffset()- Image Information- Returns - trueif this image and the given- imagehave different contents; otherwise returns- false.- The comparison can be slow, unless there is some obvious difference, such as different widths, in which case the function will return quickly. - See also - operator=()- Returns - trueif this image and the given- imagehave the same contents; otherwise returns- false.- The comparison can be slow, unless there is some obvious difference (e.g. different size or format), in which case the function will return quickly. - See also - operator=()- Returns the color of the pixel at the given - position.- If the - positionis not valid, the results are undefined.- Warning - This function is expensive when used for massive pixel manipulations. Use constBits() or constScanLine() when many pixels needs to be read. - See also - setPixel()- valid()- Pixel Manipulation- pixel(x, y)
- Parameters:
- x – int 
- y – int 
 
- Return type:
- int 
 
 - Returns the color of the pixel at the given - positionas a- QColor.- If the - positionis not valid, an invalid- QColoris returned.- Warning - This function is expensive when used for massive pixel manipulations. Use constBits() or constScanLine() when many pixels needs to be read. - See also - setPixelColor()- setPixel()- valid()- Pixel Manipulation- pixelColor(x, y)
- Parameters:
- x – int 
- y – int 
 
- Return type:
 
 - pixelFormat()¶
- Return type:
 
 - Returns the - Formatas a- QPixelFormat- Returns the pixel index at the given - position.- If - positionis not valid, or if the image is not a paletted image (- depth()> 8), the results are undefined.- See also - valid()- depth()- Pixel Manipulation- pixelIndex(x, y)
- Parameters:
- x – int 
- y – int 
 
- Return type:
- int 
 
 - Returns the enclosing rectangle (0, 0, - width(),- height()) of the image.- See also - Image Information- rgbSwap()¶
 - Swaps the values of the red and blue components of all pixels, effectively converting an RGB image to an BGR image. - See also - rgbSwapped()- Image Transformations- rgbSwapped_inplace()¶
 - save(device[, format=None[, quality=-1]])¶
- Parameters:
- device – - QIODevice
- format – str 
- quality – int 
 
- Return type:
- bool 
 
 - save(fileName[, format=None[, quality=-1]])
- Parameters:
- fileName – str 
- format – str 
- quality – int 
 
- Return type:
- bool 
 
 - scaled(s[, aspectMode=Qt.IgnoreAspectRatio[, mode=Qt.FastTransformation]])¶
- Parameters:
- s – - QSize
- aspectMode – - AspectRatioMode
- mode – - TransformationMode
 
- Return type:
 
 - Returns a copy of the image scaled to a rectangle defined by the given - sizeaccording to the given- aspectRatioModeand- transformMode.  - If - aspectRatioModeis Qt::IgnoreAspectRatio, the image is scaled to- size.
- If - aspectRatioModeis Qt::KeepAspectRatio, the image is scaled to a rectangle as large as possible inside- size, preserving the aspect ratio.
- If - aspectRatioModeis Qt::KeepAspectRatioByExpanding, the image is scaled to a rectangle as small as possible outside- size, preserving the aspect ratio.
 - If the given - sizeis empty, this function returns a null image.- See also - isNull()- Image Transformations- scaled(w, h[, aspectMode=Qt.IgnoreAspectRatio[, mode=Qt.FastTransformation]])
- Parameters:
- w – int 
- h – int 
- aspectMode – - AspectRatioMode
- mode – - TransformationMode
 
- Return type:
 
 - This is an overloaded function. - Returns a copy of the image scaled to a rectangle with the given - widthand- heightaccording to the given- aspectRatioModeand- transformMode.- If either the - widthor the- heightis zero or negative, this function returns a null image.- scaledToHeight(h[, mode=Qt.FastTransformation])¶
- Parameters:
- h – int 
- mode – - TransformationMode
 
- Return type:
 
 - Returns a scaled copy of the image. The returned image is scaled to the given - heightusing the specified transformation- mode.- This function automatically calculates the width of the image so that the ratio of the image is preserved. - If the given - heightis 0 or negative, a null image is returned.- See also - Image Transformations- scaledToWidth(w[, mode=Qt.FastTransformation])¶
- Parameters:
- w – int 
- mode – - TransformationMode
 
- Return type:
 
 - Returns a scaled copy of the image. The returned image is scaled to the given - widthusing the specified transformation- mode.- This function automatically calculates the height of the image so that its aspect ratio is preserved. - If the given - widthis 0 or negative, a null image is returned.- See also - Image Transformations- setColor(i, c)¶
- Parameters:
- i – int 
- c – int 
 
 
 - Sets the color at the given - indexin the color table, to the given to- colorValue. The color value is an ARGB quadruplet.- If - indexis outside the current size of the color table, it is expanded with setColorCount().- See also - colorCount()- Pixel Manipulation- setColorCount(arg__1)¶
- Parameters:
- arg__1 – int 
 
 - setColorSpace(colorSpace)¶
- Parameters:
- colorSpace – - QColorSpace
 
 - setColorTable(colors)¶
- Parameters:
- colors – .list of unsigned int 
 
 - setDevicePixelRatio(scaleFactor)¶
- Parameters:
- scaleFactor – float 
 
 - setDotsPerMeterX(arg__1)¶
- Parameters:
- arg__1 – int 
 
 - setDotsPerMeterY(arg__1)¶
- Parameters:
- arg__1 – int 
 
 - Sets the number of pixels by which the image is intended to be offset by when positioning relative to other images, to - offset.- See also - offset()- Image Information- Sets the pixel index or color at the given - positionto- index_or_rgb.- If the image’s format is either monochrome or paletted, the given - index_or_rgbvalue must be an index in the image’s color table, otherwise the parameter must be a- QRgbvalue.- If - positionis not a valid coordinate pair in the image, or if- index_or_rgb>=- colorCount()in the case of monochrome and paletted images, the result is undefined.- Warning - This function is expensive due to the call of the internal - detach()function called within; if performance is a concern, we recommend the use of scanLine() or bits() to access pixel data directly.- See also - pixel()- Pixel Manipulation- setPixel(x, y, index_or_rgb)
- Parameters:
- x – int 
- y – int 
- index_or_rgb – int 
 
 
 - Sets the color at the given - positionto- color.- If - positionis not a valid coordinate pair in the image, or the image’s format is either monochrome or paletted, the result is undefined.- Warning - This function is expensive due to the call of the internal - detach()function called within; if performance is a concern, we recommend the use of scanLine() or bits() to access pixel data directly.- See also - pixelColor()- pixel()- Pixel Manipulation- setPixelColor(x, y, c)
- Parameters:
- x – int 
- y – int 
- c – - QColor
 
 
 - setText(key, value)¶
- Parameters:
- key – str 
- value – str 
 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Sets the image text to the given - textand associate it with the given- key.- If you just want to store a single text block (i.e., a “comment” or just a description), you can either pass an empty key, or use a generic key like “Description”. - The image text is embedded into the image data when you call save() or - write().- Not all image formats support embedded text. You can find out if a specific image or format supports embedding text by using - supportsOption(). We give an example:- writer = QImageWriter() writer.setFormat("png") if writer.supportsOption(QImageIOHandler.Description): print("Png supports embedded text") - You can use - supportedImageFormats()to find out which image formats are available to you.- See also - text()textKeys()- Returns the size of the image, i.e. its - width()and- height().- See also - Image Information- deviceIndependentSize()- sizeInBytes()¶
- Return type:
- int 
 
 - Swaps this image with - other. This operation is very fast and never fails.- text([key=""])¶
- Parameters:
- key – str 
- Return type:
- str 
 
 - textKeys()¶
- Return type:
- list of strings 
 
 - static toImageFormat(format)¶
- Parameters:
- format – - QPixelFormat
- Return type:
 
 - Converts - formatinto a- Format- Converts - formatinto a- QPixelFormat- transformed(matrix[, mode=Qt.FastTransformation])¶
- Parameters:
- matrix – - QTransform
- mode – - TransformationMode
 
- Return type:
 
 - static trueMatrix(matrix, w, h)¶
- Parameters:
- matrix – - QTransform
- w – int 
- h – int 
 
- Return type:
 
 - Returns the actual matrix used for transforming an image with the given - width,- heightand- matrix.- When transforming an image using the transformed() function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. transformed() returns the smallest image containing all transformed points of the original image. This function returns the modified matrix, which maps points correctly from the original image into the new image. - Unlike the other overload, this function creates transformation matrices that can be used to perform perspective transformations on images. - See also - Image Transformations- Returns - trueif- posis a valid coordinate pair within the image; otherwise returns- false.- See also - valid(x, y)
- Parameters:
- x – int 
- y – int 
 
- Return type:
- bool