PySide.QtGui.QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.
Qt 为处理图像数据提供了 4 个类: PySide.QtGui.QImage , PySide.QtGui.QPixmap , PySide.QtGui.QBitmap and PySide.QtGui.QPicture . PySide.QtGui.QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while PySide.QtGui.QPixmap 为在屏幕上展示图像而设计 优化的。 PySide.QtGui.QBitmap 只是方便类,继承 PySide.QtGui.QPixmap ,确保 1 深度。最后, PySide.QtGui.QPicture 类是描绘设备,它记录并重演 PySide.QtGui.QPainter 命令。
因为 PySide.QtGui.QImage 是 PySide.QtGui.QPaintDevice 子类, PySide.QtGui.QPainter 可用于在图像上直接绘制。当使用 PySide.QtGui.QPainter 在 PySide.QtGui.QImage , the painting can be performed in another thread than the current GUI thread.
PySide.QtGui.QImage class supports several image formats described by the QImage.Format 枚举。这些包括单色、8 位、32 位且 Alpha 融合图像 (可用于所有 Qt 4.x 版本)。
PySide.QtGui.QImage provides 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.
PySide.QtGui.QImage objects can be passed around by value since the PySide.QtGui.QImage class uses 隐式数据共享 . PySide.QtGui.QImage objects can also be streamed and compared.
注意
If you would like to load PySide.QtGui.QImage objects in a static build of Qt, refer to the 插件 HowTo .
警告
Painting on a PySide.QtGui.QImage with the format QImage.Format_Indexed8 不被支持。
PySide.QtGui.QImage provides several ways of loading an image file: The file can be loaded when constructing the PySide.QtGui.QImage object, or by using the PySide.QtGui.QImage.load() or PySide.QtGui.QImage.loadFromData() functions later on. PySide.QtGui.QImage also provides the static PySide.QtGui.QImage.fromData() function, constructing a PySide.QtGui.QImage from 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 Qt 资源系统 概述,了解如何在应用程序可执行文件中嵌入图像及其它资源文件的细节。
只需调用 PySide.QtGui.QImage.save() function to save a PySide.QtGui.QImage 对象。
可获得支持的文件格式的完整列表,透过 QImageReader.supportedImageFormats() and QImageWriter.supportedImageFormats() functions. New file formats can be added as plugins. By default, Qt supports the following formats:
| 格式 | 描述 | Qt 支持 |
| BMP | Windows 位图 | 读/写 |
| GIF | Graphic Interchange Format (图形互换格式) 可选 | Read |
| JPG | Joint Photographic Experts Group (联合摄影专家组) | 读/写 |
| JPEG | Joint Photographic Experts Group (联合摄影专家组) | 读/写 |
| PNG | Portable Network Graphics (便携式网络图形) | 读/写 |
| PBM | Portable Bitmap (便携式位图) | Read |
| PGM | Portable Graymap (便携式灰度图) | Read |
| PPM | Portable Pixmap (便携式像素图) | 读/写 |
| TIFF | 标签化图像文件格式 | 读/写 |
| XBM | X11 Bitmap (X11 位图) | 读/写 |
| XPM | X11 Pixmap (X11 像素图) | 读/写 |
PySide.QtGui.QImage provides a collection of functions that can be used to obtain a variety of information about the image:
| 可用函数 | |
| 几何体 |
PySide.QtGui.QImage.size() , PySide.QtGui.QImage.width() , PySide.QtGui.QImage.height() , PySide.QtGui.QImage.dotsPerMeterX() ,和 PySide.QtGui.QImage.dotsPerMeterY() functions provide information about the image size and aspect ratio.
PySide.QtGui.QImage.rect()
function returns the image's enclosing rectangle. The
PySide.QtGui.QImage.valid()
function tells if a given pair of coordinates is within this rectangle. The
PySide.QtGui.QImage.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
PySide.QtGui.QImage.setOffset()
函数。
|
| Colors |
The color of a pixel can be retrieved by passing its coordinates to the PySide.QtGui.QImage.pixel() function. The PySide.QtGui.QImage.pixel() function returns the color as a QRgb value indepedent of the image's format. In case of monochrome and 8-bit images, the PySide.QtGui.QImage.colorCount() and PySide.QtGui.QImage.colorTable() functions provide information about the color components used to store the image data: The PySide.QtGui.QImage.colorTable() function returns the image's entire color table. To obtain a single entry, use the PySide.QtGui.QImage.pixelIndex() function to retrieve the pixel index for a given pair of coordinates, then use the PySide.QtGui.QImage.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. PySide.QtGui.QImage.hasAlphaChannel() function tells if the image's format respects the alpha channel, or not. The PySide.QtGui.QImage.allGray() and PySide.QtGui.QImage.isGrayscale() functions tell whether an image's colors are all shades of gray. 另请参阅 Pixel 操纵 and 图像 变换 sections. |
| 文本 | PySide.QtGui.QImage.text() function returns the image text associated with the given text key. An image's text keys can be retrieved using the PySide.QtGui.QImage.textKeys() function. Use the PySide.QtGui.QImage.setText() function to alter an image's text. |
| 低级信息 |
PySide.QtGui.QImage.depth() function returns the depth of the image. The supported depths are 1 (monochrome), 8, 16, 24 and 32 bits. The PySide.QtGui.QImage.bitPlaneCount() function tells how many of those bits that are used. For more information see the 图像 格式 章节。 PySide.QtGui.QImage.format() , PySide.QtGui.QImage.bytesPerLine() ,和 PySide.QtGui.QImage.byteCount() functions provide low-level information about the data stored in the image. PySide.QtGui.QImage.cacheKey() function returns a number that uniquely identifies the contents of this PySide.QtGui.QImage 对象。 |
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 图像 格式 章节。
若是 32 位图像, PySide.QtGui.QImage.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 QRgb value, 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 位 | |
image = QImage(3, 3, QImage.Format_RGB32)
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 PySide.QtGui.QImage.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 PySide.QtGui.QImage.setColor() 函数。
An entry in the color table is an ARGB quadruplet encoded as an QRgb 值。使用 qRgb() and qRgba() functions to make a suitable QRgb value for use with the PySide.QtGui.QImage.setColor() function. For example:
| 8 位 | |
image = QImage(3, 3, QImage.Format_Indexed8)
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)
|
|
PySide.QtGui.QImage also provide the PySide.QtGui.QImage.scanLine() function which returns a pointer to the pixel data at the scanline with the given index, and the PySide.QtGui.QImage.bits() function which returns a pointer to the first pixel data (this is equivalent to scanLine(0) ).
Each pixel stored in a PySide.QtGui.QImage is represented by an integer. The size of the integer varies depending on the format. PySide.QtGui.QImage supports several image formats described by the QImage.Format 枚举。
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 QVector < QRgb >, and the QRgb typedef 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 QRgb value. 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 PySide.QtGui.QImage.format() function. Use the PySide.QtGui.QImage.convertToFormat() functions to convert an image into another format. The PySide.QtGui.QImage.allGray() and PySide.QtGui.QImage.isGrayscale() functions tell whether a color image can safely be converted to a grayscale image.
PySide.QtGui.QImage supports a number of functions for creating a new image that is a transformed version of the original: The PySide.QtGui.QImage.createAlphaMask() function builds and returns a 1-bpp mask from the alpha buffer in this image, and the PySide.QtGui.QImage.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.
PySide.QtGui.QImage.mirrored() function returns a mirror of the image in the desired direction, the PySide.QtGui.QImage.scaled() returns a copy of the image scaled to a rectangle of the desired measures, and the PySide.QtGui.QImage.rgbSwapped() function constructs a BGR image from a RGB image.
PySide.QtGui.QImage.scaledToWidth() and PySide.QtGui.QImage.scaledToHeight() functions return scaled copies of the image.
PySide.QtGui.QImage.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. PySide.QtGui.QImage.transformed() returns the smallest image containing all transformed points of the original image. The static PySide.QtGui.QImage.trueMatrix() function returns the actual matrix used for transforming the image.
There are also functions for changing attributes of an image in-place:
| 函数 | 描述 |
| PySide.QtGui.QImage.setDotsPerMeterX() | Defines the aspect ratio by setting the number of pixels that fit horizontally in a physical meter. |
| PySide.QtGui.QImage.setDotsPerMeterY() | Defines the aspect ratio by setting the number of pixels that fit vertically in a physical meter. |
| PySide.QtGui.QImage.fill() | Fills the entire image with the given pixel value. |
| PySide.QtGui.QImage.invertPixels() | Inverts all pixel values in the image using the given QImage.InvertMode 值。 |
| PySide.QtGui.QImage.setColorTable() | Sets the color table used to translate color indexes. Only monochrome and 8-bit formats. |
| PySide.QtGui.QImage.setColorCount() | Resizes the color table. Only monochrome and 8-bit formats. |
For smooth scaling, the PySide.QtGui.QImage.transformed() functions use code based on smooth scaling algorithm by Daniel M. Duley.
Copyright (C) 2004, 2005 Daniel M. Duley
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
另请参阅
PySide.QtGui.QImageReader PySide.QtGui.QImageWriter PySide.QtGui.QPixmap PySide.QtSvg.QSvgRenderer 图像合成范例 图像查看器范例 涂鸦范例 像素器范例
| 参数: |
|
|---|
构造空图像。
构造浅拷贝为给定 image .
有关浅拷贝的更多信息,见 隐式数据共享 文档编制。
构造图像采用给定 size and format .
A null 图像被返回,若无法分配内存。
警告
This will create a PySide.QtGui.QImage with uninitialized data. Call PySide.QtGui.QImage.fill() to fill the image with an appropriate pixel value before drawing onto it with PySide.QtGui.QPainter .
构造图像并试着从文件加载图像,采用给定 fileName .
加载器试图读取图像使用指定 format 。若 format is not specified (which is the default), the loader probes the file for a header to guess the file format.
若图像加载失败,此对象为 null 图像。
The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the 资源系统 概述,了解如何在应用程序可执行文件中嵌入图像及其它资源文件的细节。
另请参阅
PySide.QtGui.QImage.isNull() Reading and Writing 图像 文件
构造图像采用给定 width , height and format .
A null image will be returned if memory cannot be allocated.
警告
This will create a PySide.QtGui.QImage with uninitialized data. Call PySide.QtGui.QImage.fill() to fill the image with an appropriate pixel value before drawing onto it with PySide.QtGui.QPainter .
构造图像采用给定 width , height and format , that uses an existing memory buffer, data 。 width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.
The buffer must remain valid throughout the life of the PySide.QtGui.QImage . The image does not delete the buffer at destruction.
若 format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with PySide.QtGui.QImage.setColorCount() or PySide.QtGui.QImage.setColorTable() before the image is used.
构造图像采用给定 width , height and format , that uses an existing memory buffer, data 。 width and height must be specified in pixels. bytesPerLine specifies the number of bytes per line (stride).
The buffer must remain valid throughout the life of the PySide.QtGui.QImage . The image does not delete the buffer at destruction.
若 format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with PySide.QtGui.QImage.setColorCount() or PySide.QtGui.QImage.setColorTable() before the image is used.
This enum type is used to describe how pixel values should be inverted in the PySide.QtGui.QImage.invertPixels() 函数。
| 常量 | 描述 |
|---|---|
| QImage.InvertRgb | Invert only the RGB values and leave the alpha channel unchanged. |
| QImage.InvertRgba | 反转所有通道,包括 Alpha 通道。 |
The following image formats are available in Qt. Values greater than QImage.Format_RGB16 were added in Qt 4.4. See the notes after the table.
| 常量 | 描述 |
|---|---|
| QImage.Format_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 | 图像使用 8 位索引存储到颜色图。 |
| QImage.Format_RGB32 | 图像使用 32 位 RGB 格式 (0xffRRGGBB) 存储。 |
| QImage.Format_ARGB32 | 图像使用 32 位 ARGB 格式 (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 | 图像使用 16 位 RGB 格式 (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 | 图像使用 24 位 RGB 格式 (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). |
注意
绘制进 PySide.QtGui.QImage with QImage.Format_Indexed8 不被支持。
注意
Do not render into ARGB32 images using PySide.QtGui.QPainter . Using QImage.Format_ARGB32_Premultiplied is significantly faster.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if all the colors in the image are shades of gray (i.e. their red, green and blue components are equal); otherwise false.
Note that this function is slow for images without color table.
| 返回类型: | PySide.QtGui.QImage |
|---|
Returns the alpha channel of the image as a new grayscale PySide.QtGui.QImage in which each pixel's red, green, and blue values are given the alpha value of the original image. The color depth of the returned image is 8-bit.
You can see an example of use of this function in PySide.QtGui.QPixmap ‘s PySide.QtGui.QPixmap.alphaChannel() , which works in the same way as this function on QPixmaps.
Most usecases for this function can be replaced with PySide.QtGui.QPainter and using composition modes.
警告
This is an expensive function.
另请参阅
PySide.QtGui.QImage.setAlphaChannel() PySide.QtGui.QImage.hasAlphaChannel() Pixmap 图像 变换
| 返回类型: | PySide.QtCore.int |
|---|
返回图像位平面数。
The number of bit planes is the number of bits of color and transparency information for each pixel. This is different from (i.e. smaller than) the depth when the image format contains unused bits.
另请参阅
PySide.QtGui.QImage.depth() PySide.QtGui.QImage.format() 图像 格式
| 返回类型: | PySide.QtCore.int |
|---|
Returns the number of bytes occupied by the image data.
另请参阅
PySide.QtGui.QImage.bytesPerLine() PySide.QtGui.QImage.bits() 图像 Information
| 返回类型: | PySide.QtCore.int |
|---|
返回每图像扫描线的字节数。
这相当于 PySide.QtGui.QImage.byteCount() / PySide.QtGui.QImage.height() .
另请参阅
PySide.QtGui.QImage.scanLine()
| 返回类型: | PySide.QtCore.qint64 |
|---|
Returns a number that identifies the contents of this PySide.QtGui.QImage object. Distinct PySide.QtGui.QImage objects can only have the same key if they refer to the same contents.
键将改变当变更图像时。
| 参数: | i – PySide.QtCore.int |
|---|---|
| 返回类型: | long |
Returns the color in the color table at index i . The first color is at index 0.
The colors in an image's color table are specified as ARGB quadruplets ( QRgb ). Use the qAlpha() , qRed() , qGreen() ,和 qBlue() functions to get the color value components.
| 返回类型: |
|---|
Returns a list of the colors contained in the image's color table, or an empty list if the image does not have a color table
另请参阅
PySide.QtGui.QImage.setColorTable() PySide.QtGui.QImage.colorCount() PySide.QtGui.QImage.color()
| 返回类型: | PySide.QtCore.uchar |
|---|
返回第一像素数据指针。
注意: PySide.QtGui.QImage 使用 隐式数据共享 , but this function does not perform a deep copy of the shared pixel data, because the returned data is const.
另请参阅
PySide.QtGui.QImage.bits() PySide.QtGui.QImage.constScanLine()
| 参数: | arg__1 – PySide.QtCore.int |
|---|---|
| 返回类型: | PyObject |
Returns a pointer to the pixel data at the scanline with index i . The first scanline is at index 0.
The scanline data is aligned on a 32-bit boundary.
注意: PySide.QtGui.QImage 使用 隐式数据共享 , but this function does not perform a deep copy of the shared pixel data, because the returned data is const.
另请参阅
PySide.QtGui.QImage.scanLine() PySide.QtGui.QImage.constBits()
| 参数: |
|
|---|---|
| 返回类型: |
| 参数: |
|
|---|---|
| 返回类型: |
| 参数: | rect – PySide.QtCore.QRect |
|---|---|
| 返回类型: | PySide.QtGui.QImage |
将图像的子区域作为新图像返回。
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 .
若给定 rectangle is a null rectangle the entire image is copied.
另请参阅
PySide.QtGui.QImage.QImage()
| 参数: |
|
|---|---|
| 返回类型: |
这是重载函数。
The returned image is copied from the position ( x , y ) in this image, and will always have the given width and height . In areas beyond this image, pixels are set to 0.
| 参数: | flags – PySide.QtCore.Qt.ImageConversionFlags |
|---|---|
| 返回类型: | PySide.QtGui.QImage |
| 参数: | clipTight – PySide.QtCore.bool |
|---|---|
| 返回类型: | PySide.QtGui.QImage |
Creates and returns a 1-bpp heuristic mask for this image.
The function works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges. The four corners vote for which color is to be masked away. In case of a draw (this generally means that this function is not applicable to the image), the result is arbitrary.
The returned image has little-endian bit order (i.e. the image's format is QImage.Format_MonoLSB ), which you can convert to big-endian ( QImage.Format_Mono ) using the PySide.QtGui.QImage.convertToFormat() 函数。
若 clipTight is true (the default) the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels.
Note that this function disregards the alpha buffer.
另请参阅
| 参数: |
|
|---|---|
| 返回类型: |
| 返回类型: | PySide.QtCore.int |
|---|
Returns the number of pixels that fit horizontally in a physical meter. Together with PySide.QtGui.QImage.dotsPerMeterY() , this number defines the intended scale and aspect ratio of the image.
另请参阅
PySide.QtGui.QImage.setDotsPerMeterX() 图像 Information
| 返回类型: | PySide.QtCore.int |
|---|
Returns the number of pixels that fit vertically in a physical meter. Together with PySide.QtGui.QImage.dotsPerMeterX() , this number defines the intended scale and aspect ratio of the image.
另请参阅
PySide.QtGui.QImage.setDotsPerMeterY() 图像 Information
| 参数: | color – PySide.QtGui.QColor |
|---|
这是重载函数。
填充整个图像采用给定 color .
若图像深度为 1,图像将被填充采用 1 若 color 等于 Qt.color1 ;否则将被填充采用 0。
If the depth of the image is 8, the image will be filled with the index corresponding the color in the color table if present; it will otherwise be filled with 0.
| 参数: | color – PySide.QtCore.Qt.GlobalColor |
|---|
| 参数: | pixel – PySide.QtCore.uint |
|---|
填充整个图像采用给定 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.
注意: QImage.pixel() returns the color of the pixel at the given coordinates while QColor.pixel() returns the pixel value of the underlying window system (essentially an index value), so normally you will want to use QImage.pixel() to use a color from an existing image or QColor.rgb() to use a specific color.
另请参阅
PySide.QtGui.QImage.depth() 图像 变换
| 返回类型: | PySide.QtGui.QImage.Format |
|---|
返回图像格式。
另请参阅
图像 格式
| 参数: |
|
|---|---|
| 返回类型: |
这是重载函数。
加载图像从给定 PySide.QtCore.QByteArray data .
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the image has a format that respects the alpha channel, otherwise returns false.
另请参阅
图像 Information
| 参数: | mode – PySide.QtGui.QImage.InvertMode |
|---|
反转图像所有像素值。
The given invert mode only have a meaning when the image's depth is 32. The default mode is InvertRgb , which leaves the alpha channel unchanged. If the mode is InvertRgba , the alpha bits are also inverted.
Inverting an 8-bit image means to replace all pixels using color index i with a pixel using color index 255 minus i . The same is the case for a 1-bit image. Note that the color table is not 改变。
另请参阅
图像 变换
| 返回类型: | PySide.QtCore.bool |
|---|
对于 32 位图像,此函数相当于 PySide.QtGui.QImage.allGray() .
For 8-bpp images, this function returns true if color(i) is QRgb (i, i, i) for all indexes of the color table; otherwise returns false.
另请参阅
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if it is a null image, otherwise returns false.
null 图像的所有参数都设置为零,并且没有分配的数据。
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
从文件加载图像采用给定 fileName . Returns true if the image was successfully loaded; otherwise returns false.
加载器试图读取图像使用指定 format , e.g., PNG or JPG. If format is not specified (which is the default), the loader probes the file for a header to guess the file format.
The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the 资源系统 概述,了解如何在应用程序可执行文件中嵌入图像及其它资源文件的细节。
另请参阅
Reading and Writing 图像 文件
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
这是重载函数。
此函数读取 PySide.QtGui.QImage from the given device . This can, for example, be used to load an image directly into a PySide.QtCore.QByteArray .
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
这是重载函数。
加载图像从给定 PySide.QtCore.QByteArray data .
| 参数: |
|
|---|---|
| 返回类型: |
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false.
注意:原始图像无变化。
另请参阅
图像 变换
| 返回类型: | PySide.QtCore.int |
|---|
Returns the number of bytes occupied by the image data.
| 返回类型: | PySide.QtCore.QPoint |
|---|
Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images.
另请参阅
PySide.QtGui.QImage.setOffset() 图像 Information
| 参数: | arg__1 – PySide.QtGui.QImage |
|---|---|
| 返回类型: | PySide.QtCore.bool |
Returns true if this image and the given image have different contents; otherwise returns false.
比较可能很慢,除非有一些明显差异 (譬如:不同宽度),在这种情况下函数会快速返回。
另请参阅
PySide.QtGui.QImage.operator=()
| 参数: | arg__1 – PySide.QtGui.QImage |
|---|---|
| 返回类型: | PySide.QtCore.bool |
Returns true if this image and the given image have the same contents; otherwise returns false.
比较可能很慢,除非有一些明显差异 (如:不同大小或格式),在这种情况下函数会快速返回。
另请参阅
PySide.QtGui.QImage.operator=()
| 参数: |
|
|---|---|
| 返回类型: |
long |
这是重载函数。
返回像素的颜色在坐标 ( x , y ).
| 参数: | pt – PySide.QtCore.QPoint |
|---|---|
| 返回类型: | long |
返回像素的颜色在给定 position .
若 position 无效,结果未定义。
警告
This function is expensive when used for massive pixel manipulations.
另请参阅
PySide.QtGui.QImage.setPixel() PySide.QtGui.QImage.valid() Pixel 操纵
| 参数: | pt – PySide.QtCore.QPoint |
|---|---|
| 返回类型: | PySide.QtCore.int |
返回像素索引在给定 position .
若 position 无效,或图像不是调色板图像 ( PySide.QtGui.QImage.depth() > 8), the results are undefined.
另请参阅
PySide.QtGui.QImage.valid() PySide.QtGui.QImage.depth() Pixel 操纵
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.int |
这是重载函数。
返回像素索引在 ( x , y ).
| 返回类型: | PySide.QtCore.QRect |
|---|
返回封闭矩形 (0, 0, PySide.QtGui.QImage.width() , PySide.QtGui.QImage.height() ) of the image.
另请参阅
图像 Information
| 返回类型: | PySide.QtGui.QImage |
|---|
返回 PySide.QtGui.QImage in which the values of the red and blue components of all pixels have been swapped, effectively converting an RGB image to an BGR image.
原始 PySide.QtGui.QImage 无变化。
另请参阅
图像 变换
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
这是重载函数。
此函数写入 PySide.QtGui.QImage 到给定 device .
例如,这可以用于将图像直接保存到 PySide.QtCore.QByteArray :
image = QImage()
ba = QByteArray()
buffer(ba)
buffer.open(QIODevice.WriteOnly)
image.save(buffer, "PNG") # writes image into ba in PNG format
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
保存图像到文件采用给定 fileName ,使用给定图像文件 format and quality 因子。若 format is 0, PySide.QtGui.QImage 将试图猜测格式通过查看 fileName ‘s suffix.
quality 因子必须在 0 到 100 范围内或为 -1。指定 0 以获得小压缩文件,100 为大的未压缩文件,和 -1 (默认) 使用默认设置。
Returns true if the image was successfully saved; otherwise returns false.
另请参阅
Reading and Writing 图像 文件
| 参数: |
|
|---|---|
| 返回类型: |
| 参数: |
|
|---|---|
| 返回类型: |
| 参数: |
|
|---|---|
| 返回类型: |
| 参数: |
|
|---|---|
| 返回类型: |
| 参数: | alphaChannel – PySide.QtGui.QImage |
|---|
将此图像的 Alpha 通道设为给定 alphaChannel .
若 alphaChannel is an 8 bit grayscale image, the intensity values are written into this buffer directly. Otherwise, alphaChannel is converted to 32 bit and the intensity of the RGB pixel values is used.
Note that the image will be converted to the Format_ARGB32_Premultiplied format if the function succeeds.
Use one of the composition modes in QPainter.CompositionMode 代替。
警告
This function is expensive.
另请参阅
PySide.QtGui.QImage.alphaChannel() 图像 变换 图像 格式
| 参数: |
|
|---|
| 参数: | arg__1 – PySide.QtCore.int |
|---|
重置颜色表大小以包含 colorCount 条目。
If the color table is expanded, all the extra colors will be set to transparent (i.e qRgba(0, 0, 0, 0)).
When the image is used, the color table must be large enough to have entries for all the pixel/index values present in the image, otherwise the results are undefined.
另请参阅
PySide.QtGui.QImage.colorCount() PySide.QtGui.QImage.colorTable() PySide.QtGui.QImage.setColor() 图像 变换
| 参数: | colors – |
|---|
| 参数: | arg__1 – PySide.QtCore.int |
|---|
Sets the number of pixels that fit horizontally in a physical meter, to x .
Together with PySide.QtGui.QImage.dotsPerMeterY() , this number defines the intended scale and aspect ratio of the image, and determines the scale at which PySide.QtGui.QPainter will draw graphics on the image. It does not change the scale or aspect ratio of the image when it is rendered on other paint devices.
另请参阅
PySide.QtGui.QImage.dotsPerMeterX() 图像 Information
| 参数: | arg__1 – PySide.QtCore.int |
|---|
Sets the number of pixels that fit vertically in a physical meter, to y .
Together with PySide.QtGui.QImage.dotsPerMeterX() , this number defines the intended scale and aspect ratio of the image, and determines the scale at which PySide.QtGui.QPainter will draw graphics on the image. It does not change the scale or aspect ratio of the image when it is rendered on other paint devices.
另请参阅
PySide.QtGui.QImage.dotsPerMeterY() 图像 Information
| 参数: | arg__1 – PySide.QtCore.int |
|---|
重置颜色表大小以包含 numColors 条目。
另请参阅
PySide.QtGui.QImage.numColors() PySide.QtGui.QImage.setColorCount()
| 参数: | arg__1 – PySide.QtCore.QPoint |
|---|
Sets the number of pixels by which the image is intended to be offset by when positioning relative to other images, to offset .
另请参阅
PySide.QtGui.QImage.offset() 图像 Information
| 参数: |
|
|---|
这是重载函数。
设置像素索引或颜色在 ( x , y ) 到 index_or_rgb .
| 参数: |
|
|---|
设置像素索引或颜色在给定 position to index_or_rgb .
If the image's format is either monochrome or 8-bit, the given index_or_rgb value must be an index in the image's color table, otherwise the parameter must be a QRgb 值。
若 position is not a valid coordinate pair in the image, or if index_or_rgb >= PySide.QtGui.QImage.colorCount() in the case of monochrome and 8-bit images, the result is undefined.
警告
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 PySide.QtGui.QImage.scanLine() to access pixel data directly.
另请参阅
PySide.QtGui.QImage.pixel() Pixel 操纵
| 参数: |
|
|---|
将图像文本设为给定 text 并将其关联到给定 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”.
图像文本被嵌入图像数据当调用 PySide.QtGui.QImage.save() or QImageWriter.write() .
并非所有图像格式都支持嵌入文本。可以找出哪些特定图像或格式支持嵌入文本通过使用 QImageWriter.supportsOption() . We give an example:
writer = QImageWriter()
writer.setFormat("png")
if writer.supportsOption(QImageIOHandler.Description):
print "Png supports embedded text"
可以使用 QImageWriter.supportedImageFormats() to find out which image formats are available to you.
| 返回类型: | PySide.QtCore.QSize |
|---|
返回图片大小,即其 PySide.QtGui.QImage.width() and PySide.QtGui.QImage.height() .
另请参阅
图像 Information
| 参数: | other – PySide.QtGui.QImage |
|---|
交换图像 other 与此图像。此操作非常快且从不失败。
| 参数: | key – unicode |
|---|---|
| 返回类型: | unicode |
返回的图像文本关联给定 key 。若指定 key 是空字符串,返回整个图像文本,每个键文本对由换行符分隔。
| 返回类型: | 字符串列表 |
|---|
返回此图像的文本键。
You can use these keys with PySide.QtGui.QImage.text() to list the image text for a certain key.
| 参数: |
|
|---|---|
| 返回类型: |
| 参数: |
|
|---|---|
| 返回类型: |
| 参数: |
|
|---|---|
| 返回类型: |
返回用于变换图像的实际矩阵采用给定 width , height and matrix .
When transforming an image using the PySide.QtGui.QImage.transformed() function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. PySide.QtGui.QImage.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.
另请参阅
| 参数: |
|
|---|---|
| 返回类型: |
返回用于变换图像的实际矩阵采用给定 width , height and matrix .
When transforming an image using the PySide.QtGui.QImage.transformed() function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. PySide.QtGui.QImage.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.
另请参阅
| 参数: | pt – PySide.QtCore.QPoint |
|---|---|
| 返回类型: | PySide.QtCore.bool |
返回 true 若 pos is a valid coordinate pair within the image; otherwise returns false.
另请参阅
PySide.QtGui.QImage.rect() QRect.contains()
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
这是重载函数。
返回 true 若 PySide.QtCore.QPoint ( x , y ) is a valid coordinate pair within the image; otherwise returns false.