def
__eq__
(arg__1)
def
__ne__
(arg__1)
def
allGray
()
def
alphaChannel
()
def
bitPlaneCount
()
def
byteCount
()
def
bytesPerLine
()
def
cacheKey
()
def
color
(i)
def
colorSpace
()
def
colorTable
()
def
constBits
()
def
constScanLine
(arg__1)
def
convertTo
(f[, flags=Qt.AutoColor])
def
convertToColorSpace
(arg__1)
def
convertToFormat
(f, colorTable[, flags=Qt.AutoColor])
def
convertToFormat
(f[, flags=Qt.AutoColor])
def
convertToFormat_helper
(format, flags)
def
convertToFormat_inplace
(format, flags)
def
convertedToColorSpace
(arg__1)
def
copy
([rect=QRect()])
def
copy
(x, y, w, h)
def
createAlphaMask
([flags=Qt.AutoColor])
def
createHeuristicMask
([clipTight=true])
def
createMaskFromColor
(color[, mode=Qt.MaskInColor])
def
dotsPerMeterX
()
def
dotsPerMeterY
()
def
fill
(color)
def
fill
(color)
def
fill
(pixel)
def
format
()
def
hasAlphaChannel
()
def
invertPixels
([mode=InvertRgb])
def
isGrayscale
()
def
isNull
()
def
load
(device, format)
def
load
(fileName[, format=None])
def
loadFromData
(data[, aformat=None])
def
mirrored
([horizontally=false[, vertically=true]])
def
mirrored_helper
(horizontal, vertical)
def
mirrored_inplace
(horizontal, vertical)
def
offset
()
def
pixel
(pt)
def
pixel
(x, y)
def
pixelColor
(pt)
def
pixelColor
(x, y)
def
pixelFormat
()
def
pixelIndex
(pt)
def
pixelIndex
(x, y)
def
rect
()
def
reinterpretAsFormat
(f)
def
rgbSwapped
()
def
rgbSwapped_helper
()
def
rgbSwapped_inplace
()
def
save
(device[, format=None[, quality=-1]])
def
save
(fileName[, format=None[, quality=-1]])
def
scaled
(s[, aspectMode=Qt.IgnoreAspectRatio[, mode=Qt.FastTransformation]])
def
scaled
(w, h[, aspectMode=Qt.IgnoreAspectRatio[, mode=Qt.FastTransformation]])
def
scaledToHeight
(h[, mode=Qt.FastTransformation])
def
scaledToWidth
(w[, mode=Qt.FastTransformation])
def
setAlphaChannel
(alphaChannel)
def
setColor
(i, c)
def
setColorCount
(arg__1)
def
setColorSpace
(arg__1)
def
setColorTable
(colors)
def
setDevicePixelRatio
(scaleFactor)
def
setDotsPerMeterX
(arg__1)
def
setDotsPerMeterY
(arg__1)
def
setOffset
(arg__1)
def
setPixel
(pt, index_or_rgb)
def
setPixel
(x, y, index_or_rgb)
def
setPixelColor
(pt, c)
def
setPixelColor
(x, y, c)
def
setText
(key, value)
def
size
()
def
sizeInBytes
()
def
smoothScaled
(w, h)
def
swap
(other)
def
text
([key=””])
def
textKeys
()
def
transformed
(matrix[, mode=Qt.FastTransformation])
def
transformed
(matrix[, mode=Qt.FastTransformation])
def
valid
(pt)
def
valid
(x, y)
def
fromData
(data[, format=None])
def
toImageFormat
(format)
def
toPixelFormat
(format)
def
trueMatrix
(arg__1, w, h)
def
trueMatrix
(arg__1, w, h)
Qt 为处理图像数据提供了 4 个类:
QImage,QPixmap,QBitmapandQPicture.QImageis designed and optimized for I/O, and for direct pixel access and manipulation, whileQPixmap为在屏幕上展示图像而设计 优化的。QBitmap只是方便类,继承QPixmap,确保 1 深度。最后,QPicture类是描绘设备,它记录并重演QPainter命令。因为
QImage是QPaintDevice子类,QPainter可用于在图像上直接绘制。当使用QPainter在QImage, the painting can be performed in another thread than the current GUI thread.
QImageclass supports several image formats described by the格式枚举。这些包括单色、8 位、32 位且 Alpha 融合图像 (可用于所有 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 theQImageclass uses 隐式数据共享 .QImageobjects can also be streamed and compared.注意
If you would like to load
QImageobjects in a static build of Qt, refer to the Plugin HowTo.警告
Painting on a
QImagewith the formatFormat_Indexed8不被支持。
QImageprovides several ways of loading an image file: The file can be loaded when constructing theQImageobject, or by using theload()orloadFromData()functions later on.QImagealso provides the staticfromData()function, constructing aQImagefrom 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 资源系统 overview for details on how to embed images and other resource files in the application’s executable.只需调用
save()function to save aQImage对象。可获得支持的文件格式的完整列表,透过
supportedImageFormats()andsupportedImageFormats()functions. New file formats can be added as plugins. By default, Qt supports the following formats:
格式
描述
Qt’s support
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 (便携式像素图)
读/写
XBM
X11 Bitmap (X11 位图)
读/写
XPM
X11 Pixmap (X11 像素图)
读/写
QImageprovides a collection of functions that can be used to obtain a variety of information about the image:
可用函数
几何体
size(),width(),height(),dotsPerMeterX(),和dotsPerMeterY()functions provide information about the image size and aspect ratio.
rect()function returns the image’s enclosing rectangle. Thevalid()function tells if a given pair of coordinates is within this rectangle. Theoffset()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 thesetOffset()函数。Colors
The color of a pixel can be retrieved by passing its coordinates to the
pixel()function. Thepixel()function returns the color as aQRgbvalue indepedent of the image’s format.In case of monochrome and 8-bit images, the
colorCount()andcolorTable()functions provide information about the color components used to store the image data: ThecolorTable()function returns the image’s entire color table. To obtain a single entry, use thepixelIndex()function to retrieve the pixel index for a given pair of coordinates, then use thecolor()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.
hasAlphaChannel()function tells if the image’s format respects the alpha channel, or not. TheallGray()andisGrayscale()functions tell whether an image’s colors are all shades of gray.另请参阅
Pixel 操纵and图像 变换sections.文本
text()function returns the image text associated with the given text key. An image’s text keys can be retrieved using thetextKeys()function. Use thesetText()function to alter an image’s text.低级信息
depth()function returns the depth of the image. The supported depths are 1 (monochrome), 8, 16, 24 and 32 bits. ThebitPlaneCount()function tells how many of those bits that are used. For more information see the图像 格式章节。
format(),bytesPerLine(),和sizeInBytes()functions provide low-level information about the data stored in the image.
cacheKey()function returns a number that uniquely identifies the contents of thisQImage对象。
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 位图像,
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 suitableQRgbvalue, use theqRgb()(adding a default alpha component to the given RGB values, i.e. creating an opaque color) orqRgba()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
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 thesetColor()函数。An entry in the color table is an ARGB quadruplet encoded as an
QRgb值。使用qRgb()andqRgba()functions to make a suitableQRgbvalue for use with thesetColor()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)For images with more than 8-bit per color-channel. The methods
setPixelColor()andpixelColor()can be used to set and get withQColor值。
QImagealso provide thescanLine()function which returns a pointer to the pixel data at the scanline with the given index, and thebits()function which returns a pointer to the first pixel data (this is equivalent toscanLine(0)).
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格式枚举。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 theQRgbtypedef 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 theconvertToFormat()functions to convert an image into another format. TheallGray()andisGrayscale()functions tell whether a color image can safely be converted to a grayscale image.
QImagesupports a number of functions for creating a new image that is a transformed version of the original: ThecreateAlphaMask()function builds and returns a 1-bpp mask from the alpha buffer in this image, and thecreateHeuristicMask()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.
mirrored()function returns a mirror of the image in the desired direction, thescaled()returns a copy of the image scaled to a rectangle of the desired measures, and thergbSwapped()function constructs a BGR image from a RGB image.
scaledToWidth()andscaledToHeight()functions return scaled copies of the image.
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 statictrueMatrix()function returns the actual matrix used for transforming the image.There are also functions for changing attributes of an image in-place:
函数
描述
Defines the aspect ratio by setting the number of pixels that fit horizontally in a physical meter.
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.
Inverts all pixel values in the image using the given
InvertMode值。Sets the color table used to translate color indexes. Only monochrome and 8-bit formats.
Resizes the color table. Only monochrome and 8-bit formats.
QImage
¶
QImage(arg__1, arg__2, arg__3, arg__4)
QImage(arg__1, arg__2, arg__3, arg__4, arg__5)
QImage(arg__1)
QImage(size, format)
QImage(fileName[, format=None])
QImage(xpm)
QImage(width, height, format)
QImage(data, width, height, format[, cleanupFunction=None[, cleanupInfo=None]])
QImage(data, width, height, bytesPerLine, format[, cleanupFunction=None[, cleanupInfo=None]])
- param cleanupInfo
void- param xpm
char[]- param cleanupFunction
QImageCleanupFunction- param format
格式- param bytesPerLine
int- param size
QSize- param arg__1
unicode
- param arg__2
int- param arg__3
int- param fileName
unicode
- param arg__4
格式- param arg__5
格式- param data
uchar- param width
int- param height
int
构造空图像。
另请参阅
构造图像采用给定
width
,
height
and
format
.
A
null
image will be returned if memory cannot be allocated.
警告
This will create a
QImage
with uninitialized data. Call
fill()
to fill the image with an appropriate pixel value before drawing onto it with
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
QImage
and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer
cleanupFunction
along with an extra pointer
cleanupInfo
that will be called when the last copy is destroyed.
若
format
is an indexed color format, the image color table is initially empty and must be sufficiently expanded with
setColorCount()
or
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
QImage
and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer
cleanupFunction
along with an extra pointer
cleanupInfo
that will be called when the last copy is destroyed.
若
format
is an indexed color format, the image color table is initially empty and must be sufficiently expanded with
setColorCount()
or
setColorTable()
before the image is used.
PySide2.QtGui.QImage.
InvertMode
¶
This enum type is used to describe how pixel values should be inverted in the
invertPixels()
函数。
|
常量 |
描述 |
|---|---|
|
QImage.InvertRgb |
Invert only the RGB values and leave the alpha channel unchanged. |
|
QImage.InvertRgba |
反转所有通道,包括 Alpha 通道。 |
另请参阅
PySide2.QtGui.QImage.
格式
¶
以下图像格式可用于 Qt。见表格后注意事项。
|
常量 |
描述 |
|---|---|
|
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). |
|
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 except alpha must always be 255. (added in Qt 5.2) |
|
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. (added in Qt 5.2) |
|
QImage.Format_RGBA8888_Premultiplied |
The image is stored using a premultiplied 32-bit byte-ordered RGBA format (8-8-8-8). (added in Qt 5.2) |
|
QImage.Format_BGR30 |
The image is stored using a 32-bit BGR format (x-10-10-10). (added in Qt 5.4) |
|
QImage.Format_A2BGR30_Premultiplied |
The image is stored using a 32-bit premultiplied ABGR format (2-10-10-10). (added in Qt 5.4) |
|
QImage.Format_RGB30 |
图像使用 32 位 RGB 格式 (x-10-10-10) 存储。(在 Qt 5.4 添加) |
|
QImage.Format_A2RGB30_Premultiplied |
The image is stored using a 32-bit premultiplied ARGB format (2-10-10-10). (added in Qt 5.4) |
|
QImage.Format_Alpha8 |
图像使用 8 位仅 alpha 格式存储。(在 Qt 5.5 添加) |
|
QImage.Format_Grayscale8 |
图像使用 8 位灰度格式存储。(在 Qt 5.5 添加) |
|
QImage.Format_Grayscale16 |
图像使用 16 位灰度格式存储。(在 Qt 5.13 添加) |
|
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 except alpha must always be 65535. (added in Qt 5.12) |
|
QImage.Format_RGBA64 |
图像使用 64 位半字有序 RGBA 格式 (16-16-16-16) 存储。(在 Qt 5.12 添加) |
|
QImage.Format_RGBA64_Premultiplied |
The image is stored using a premultiplied 64-bit halfword-ordered RGBA format (16-16-16-16). (added in Qt 5.12) |
|
QImage.Format_BGR888 |
图像使用 24 位 BGR 格式存储。(在 Qt 5.14 添加) |
注意
绘制进
QImage
with is not supported.
注意
避免大多数直接渲染到大多数这些格式使用
QPainter
。最好优化渲染针对
Format_RGB32
and
Format_ARGB32_Premultiplied
格式,和其次是渲染到
Format_RGB16
,
Format_RGBX8888
,
Format_RGBA8888_Premultiplied
,
Format_RGBX64
and
Format_RGBA64_Premultiplied
formats
PySide2.QtGui.QImage.
allGray
(
)
¶
bool
返回
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.
另请参阅
PySide2.QtGui.QImage.
alphaChannel
(
)
¶
注意
此函数被弃用。
Returns the alpha channel of the image as a new grayscale
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
QPixmap
‘s
alphaChannel()
, which works in the same way as this function on QPixmaps.
Most usecases for this function can be replaced with
QPainter
and using composition modes.
Note this returns a color-indexed image if you want the alpha channel in the alpha8 format instead use
convertToFormat
(
Format_Alpha8
) on the source image.
警告
This is an expensive function.
另请参阅
setAlphaChannel()
hasAlphaChannel()
convertToFormat()
Pixmap
图像
变换
PySide2.QtGui.QImage.
bitPlaneCount
(
)
¶
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.
另请参阅
depth()
format()
图像
格式
PySide2.QtGui.QImage.
byteCount
(
)
¶
int
注意
此函数被弃用。
Returns the number of bytes occupied by the image data.
Note this method should never be called on an image larger than 2 gigabytes. Instead use
sizeInBytes()
.
另请参阅
sizeInBytes()
bytesPerLine()
bits()
图像
Information
PySide2.QtGui.QImage.
bytesPerLine
(
)
¶
int
返回每图像扫描线的字节数。
这相当于
sizeInBytes()
/
height()
if
height()
is non-zero.
另请参阅
scanLine()
PySide2.QtGui.QImage.
cacheKey
(
)
¶
qint64
Returns a number that identifies the contents of this
QImage
object. Distinct
QImage
objects can only have the same key if they refer to the same contents.
键将改变当变更图像时。
PySide2.QtGui.QImage.
color
(
i
)
¶
i
–
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.
另请参阅
setColor()
pixelIndex()
Pixel
操纵
PySide2.QtGui.QImage.
colorSpace
(
)
¶
返回图像的色彩空间,若有定义色彩空间。
另请参阅
PySide2.QtGui.QImage.
colorTable
(
)
¶
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
另请参阅
setColorTable()
colorCount()
color()
PySide2.QtGui.QImage.
constBits
(
)
¶
uchar
返回第一像素数据指针。
注意:
QImage
使用
隐式数据共享
, but this function does
not
perform a deep copy of the shared pixel data, because the returned data is const.
另请参阅
bits()
constScanLine()
PySide2.QtGui.QImage.
constScanLine
(
arg__1
)
¶
arg__1
–
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 as minimum 32-bit aligned. For 64-bit formats it follows the native alignment of 64-bit integers (64-bit for most platforms, but notably 32-bit on i386).
注意:
QImage
使用
隐式数据共享
, but this function does
not
perform a deep copy of the shared pixel data, because the returned data is const.
另请参阅
scanLine()
constBits()
PySide2.QtGui.QImage.
convertTo
(
f
[
,
flags=Qt.AutoColor
]
)
¶
f
–
格式
flags
–
ImageConversionFlags
分离图像并将其转换成给定
format
原位。
指定图像转换
flags
控制转换过程中如何处理图像数据。
另请参阅
PySide2.QtGui.QImage.
convertToColorSpace
(
arg__1
)
¶
arg__1
–
QColorSpace
将图像转换成
colorSpace
.
若图像没有有效色彩空间,方法什么都不做。
PySide2.QtGui.QImage.
convertToFormat
(
f
[
,
flags=Qt.AutoColor
]
)
¶
PySide2.QtGui.QImage.
convertToFormat
(
f
,
colorTable
[
,
flags=Qt.AutoColor
]
)
¶
这是重载函数。
Returns a copy of the image converted to the given
format
, using the specified
colorTable
.
Conversion from RGB formats to indexed formats is a slow operation and will use a straightforward nearest color approach, with no dithering.
PySide2.QtGui.QImage.
convertToFormat_helper
(
format
,
flags
)
¶
PySide2.QtGui.QImage.
convertToFormat_inplace
(
format
,
flags
)
¶
format
–
格式
flags
–
ImageConversionFlags
bool
PySide2.QtGui.QImage.
convertedToColorSpace
(
arg__1
)
¶
arg__1
–
QColorSpace
返回图像转换到
colorSpace
.
若图像没有有效色彩空间,null
QImage
被返回。
PySide2.QtGui.QImage.
copy
(
[
rect=QRect()
]
)
¶
rect
–
QRect
将图像的子区域作为新图像返回。
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
color0
.
若给定
rectangle
is a null rectangle the entire image is copied.
另请参阅
QImage()
PySide2.QtGui.QImage.
copy
(
x
,
y
,
w
,
h
)
¶
x
–
int
y
–
int
w
–
int
h
–
int
这是重载函数。
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.
PySide2.QtGui.QImage.
createAlphaMask
(
[
flags=Qt.AutoColor
]
)
¶
flags
–
ImageConversionFlags
Builds and returns a 1-bpp mask from the alpha buffer in this image. Returns a null image if the image’s format is
Format_RGB32
.
flags
自变量是按位 OR 的
ImageConversionFlags
, and controls the conversion process. Passing 0 for flags sets all the default options.
The returned image has little-endian bit order (i.e. the image’s format is
Format_MonoLSB
), which you can convert to big-endian (
Format_Mono
) using the
convertToFormat()
函数。
另请参阅
createHeuristicMask()
图像
变换
PySide2.QtGui.QImage.
createHeuristicMask
(
[
clipTight=true
]
)
¶
clipTight
–
bool
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
Format_MonoLSB
), which you can convert to big-endian (
Format_Mono
) using the
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.
另请参阅
createAlphaMask()
图像
变换
PySide2.QtGui.QImage.
createMaskFromColor
(
color
[
,
mode=Qt.MaskInColor
]
)
¶
color – long
mode
–
MaskMode
Creates and returns a mask for this image based on the given
color
value. If the
mode
is MaskInColor (the default value), all pixels matching
color
will be opaque pixels in the mask. If
mode
is MaskOutColor, all pixels matching the given color will be transparent.
PySide2.QtGui.QImage.
dotsPerMeterX
(
)
¶
int
Returns the number of pixels that fit horizontally in a physical meter. Together with
dotsPerMeterY()
, this number defines the intended scale and aspect ratio of the image.
另请参阅
setDotsPerMeterX()
图像
Information
PySide2.QtGui.QImage.
dotsPerMeterY
(
)
¶
int
Returns the number of pixels that fit vertically in a physical meter. Together with
dotsPerMeterX()
, this number defines the intended scale and aspect ratio of the image.
另请参阅
setDotsPerMeterY()
图像
Information
PySide2.QtGui.QImage.
fill
(
color
)
¶
color
–
GlobalColor
这是重载函数。
填充图像采用给定
color
,描述为标准全局颜色。
PySide2.QtGui.QImage.
fill
(
pixel
)
¶
pixel
–
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.
注意:
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
pixel()
to use a color from an existing image or
rgb()
to use a specific color.
另请参阅
depth()
图像
变换
PySide2.QtGui.QImage.
fromData
(
data
[
,
format=None
]
)
¶
data
–
QByteArray
format – str
这是重载函数。
加载图像从给定
QByteArray
data
.
PySide2.QtGui.QImage.
hasAlphaChannel
(
)
¶
bool
返回
true
若图像拥有的格式遵守 Alpha 通道,否则返回
false
.
另请参阅
图像
Information
PySide2.QtGui.QImage.
invertPixels
(
[
mode=InvertRgb
]
)
¶
mode
–
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 改变。
If the image has a premultiplied alpha channel, the image is first converted to an unpremultiplied image format to be inverted and then converted back.
另请参阅
图像
变换
PySide2.QtGui.QImage.
isGrayscale
(
)
¶
bool
对于 32 位图像,此函数相当于
allGray()
.
对于颜色索引图像,此函数返回
true
若 color(i) 为
QRgb
(i, i, i) 对于颜色表所有索引而言;否则返回
false
.
另请参阅
allGray()
图像
格式
PySide2.QtGui.QImage.
isNull
(
)
¶
bool
返回
true
若它是 null 图像,否则返回
false
.
null 图像的所有参数都设置为零,并且没有分配的数据。
PySide2.QtGui.QImage.
load
(
device
,
format
)
¶
device
–
QIODevice
format – str
bool
这是重载函数。
此函数读取
QImage
from the given
device
. This can, for example, be used to load an image directly into a
QByteArray
.
PySide2.QtGui.QImage.
load
(
fileName
[
,
format=None
]
)
¶
fileName – unicode
format – str
bool
PySide2.QtGui.QImage.
loadFromData
(
data
[
,
aformat=None
]
)
¶
data
–
QByteArray
aformat – str
bool
这是重载函数。
加载图像从给定
QByteArray
data
.
PySide2.QtGui.QImage.
mirrored
(
[
horizontally=false
[
,
vertically=true
]
]
)
¶
horizontally
–
bool
vertically
–
bool
PySide2.QtGui.QImage.
mirrored_helper
(
horizontal
,
vertical
)
¶
horizontal
–
bool
vertical
–
bool
PySide2.QtGui.QImage.
mirrored_inplace
(
horizontal
,
vertical
)
¶
horizontal
–
bool
vertical
–
bool
PySide2.QtGui.QImage.
offset
(
)
¶
QPoint
Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images.
另请参阅
setOffset()
图像
Information
PySide2.QtGui.QImage.
__ne__
(
arg__1
)
¶
arg__1
–
QImage
bool
返回
true
若此图像和给定
image
拥有不同内容;否则返回
false
.
比较可能很慢,除非有一些明显差异 (譬如:不同宽度),在这种情况下函数会快速返回。
另请参阅
operator=()
PySide2.QtGui.QImage.
__eq__
(
arg__1
)
¶
arg__1
–
QImage
bool
返回
true
若此图像和给定
image
拥有相同内容;否则返回
false
.
比较可能很慢,除非有一些明显差异 (如:不同大小或格式),在这种情况下函数会快速返回。
另请参阅
operator=()
PySide2.QtGui.QImage.
pixel
(
pt
)
¶
pt
–
QPoint
long
返回像素的颜色在给定
position
.
若
position
无效,结果未定义。
警告
This function is expensive when used for massive pixel manipulations. Use
constBits()
or
constScanLine()
when many pixels needs to be read.
另请参阅
setPixel()
valid()
constBits()
constScanLine()
Pixel
操纵
PySide2.QtGui.QImage.
pixel
(
x
,
y
)
¶
x
–
int
y
–
int
long
这是重载函数。
返回像素的颜色在坐标 (
x
,
y
).
PySide2.QtGui.QImage.
pixelColor
(
pt
)
¶
pt
–
QPoint
返回像素的颜色在给定
position
作为
QColor
.
若
position
is not valid, an invalid
QColor
被返回。
警告
This function is expensive when used for massive pixel manipulations. Use
constBits()
or
constScanLine()
when many pixels needs to be read.
另请参阅
setPixelColor()
setPixel()
valid()
constBits()
constScanLine()
Pixel
操纵
PySide2.QtGui.QImage.
pixelColor
(
x
,
y
)
¶
x
–
int
y
–
int
这是重载函数。
返回像素的颜色在坐标 (
x
,
y
) 作为
QColor
.
PySide2.QtGui.QImage.
pixelFormat
(
)
¶
返回
格式
作为
QPixelFormat
PySide2.QtGui.QImage.
pixelIndex
(
pt
)
¶
pt
–
QPoint
int
返回像素索引在给定
position
.
若
position
无效,或图像不是调色板图像 (
depth()
> 8), the results are undefined.
另请参阅
valid()
depth()
Pixel
操纵
PySide2.QtGui.QImage.
pixelIndex
(
x
,
y
)
¶
x
–
int
y
–
int
int
这是重载函数。
返回像素索引在 (
x
,
y
).
PySide2.QtGui.QImage.
rect
(
)
¶
QRect
返回封闭矩形 (0, 0,
width()
,
height()
) of the image.
另请参阅
图像
Information
PySide2.QtGui.QImage.
reinterpretAsFormat
(
f
)
¶
f
–
格式
bool
将图像格式改为
format
不改变数据。仅工作于相同深度的格式之间。
返回
true
若成功。
This function can be used to change images with alpha-channels to their corresponding opaque formats if the data is known to be opaque-only, or to change the format of a given image buffer before overwriting it with new data.
警告
The function does not check if the image data is valid in the new format and will still return
true
if the depths are compatible. Operations on an image with invalid data are undefined.
警告
若图像未分离,这将导致数据被拷贝。
PySide2.QtGui.QImage.
rgbSwapped_inplace
(
)
¶
PySide2.QtGui.QImage.
save
(
device
[
,
format=None
[
,
quality=-1
]
]
)
¶
device
–
QIODevice
format – str
quality
–
int
bool
这是重载函数。
此函数写入
QImage
到给定
device
.
例如,这可以用于将图像直接保存到
QByteArray
:
image = QImage()
ba = QByteArray()
buffer(ba)
buffer.open(QIODevice.WriteOnly)
image.save(buffer, "PNG") # writes image into ba in PNG format
PySide2.QtGui.QImage.
save
(
fileName
[
,
format=None
[
,
quality=-1
]
]
)
¶
fileName – unicode
format – str
quality
–
int
bool
PySide2.QtGui.QImage.
scaled
(
s
[
,
aspectMode=Qt.IgnoreAspectRatio
[
,
mode=Qt.FastTransformation
]
]
)
¶
s
–
QSize
aspectMode
–
AspectRatioMode
mode
–
TransformationMode
Returns a copy of the image scaled to a rectangle defined by the given
size
according to the given
aspectRatioMode
and
transformMode
.
若
aspectRatioMode
is
IgnoreAspectRatio
, the image is scaled to
size
.
若
aspectRatioMode
is
KeepAspectRatio
, the image is scaled to a rectangle as large as possible inside
size
, 维持宽高比。
若
aspectRatioMode
is
KeepAspectRatioByExpanding
, the image is scaled to a rectangle as small as possible outside
size
, 维持宽高比。
若给定
size
为空,此函数返回 null 图像。
另请参阅
isNull()
图像
变换
PySide2.QtGui.QImage.
scaled
(
w
,
h
[
,
aspectMode=Qt.IgnoreAspectRatio
[
,
mode=Qt.FastTransformation
]
]
)
¶
w
–
int
h
–
int
aspectMode
–
AspectRatioMode
mode
–
TransformationMode
这是重载函数。
Returns a copy of the image scaled to a rectangle with the given
width
and
height
according to the given
aspectRatioMode
and
transformMode
.
若
width
或
height
为 0 或负数,此函数返回 null 图像。
PySide2.QtGui.QImage.
scaledToHeight
(
h
[
,
mode=Qt.FastTransformation
]
)
¶
h
–
int
mode
–
TransformationMode
Returns a scaled copy of the image. The returned image is scaled to the given
height
using the specified transformation
mode
.
This function automatically calculates the width of the image so that the ratio of the image is preserved.
若给定
height
为 0 或负数,返回 null 图像。
另请参阅
图像
变换
PySide2.QtGui.QImage.
scaledToWidth
(
w
[
,
mode=Qt.FastTransformation
]
)
¶
w
–
int
mode
–
TransformationMode
Returns a scaled copy of the image. The returned image is scaled to the given
width
using the specified transformation
mode
.
This function automatically calculates the height of the image so that its aspect ratio is preserved.
若给定
width
为 0 或负数,返回 null 图像。
另请参阅
图像
变换
PySide2.QtGui.QImage.
setAlphaChannel
(
alphaChannel
)
¶
alphaChannel
–
QImage
将此图像的 Alpha 通道设为给定
alphaChannel
.
若
alphaChannel
is an 8 bit alpha image, the alpha values are used directly. Otherwise,
alphaChannel
is converted to 8 bit grayscale and the intensity of the pixel values is used.
If the image already has an alpha channel, the existing alpha channel is multiplied with the new one. If the image doesn’t have an alpha channel it will be converted to a format that does.
操作类似于描绘
alphaChannel
as an alpha image over this image using
QPainter::CompositionMode_DestinationIn
.
另请参阅
hasAlphaChannel()
alphaChannel()
图像
变换
图像
格式
PySide2.QtGui.QImage.
setColor
(
i
,
c
)
¶
i
–
int
c – long
设置颜色在给定
index
在颜色表中,到给定
colorValue
。颜色值是 ARGB 四元组。
若
index
超出颜色表当前大小,展开它采用
setColorCount()
.
另请参阅
color()
colorCount()
setColorTable()
Pixel
操纵
PySide2.QtGui.QImage.
setColorCount
(
arg__1
)
¶
arg__1
–
int
重置颜色表大小以包含
colorCount
条目。
若颜色表被展开,所有额外颜色将被设为透明 (即
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.
另请参阅
colorCount()
colorTable()
setColor()
图像
变换
PySide2.QtGui.QImage.
setColorSpace
(
arg__1
)
¶
arg__1
–
QColorSpace
将图像色彩空间设为
colorSpace
不对图像数据履行任何转换。
另请参阅
PySide2.QtGui.QImage.
setColorTable
(
colors
)
¶
colors –
将用于翻译颜色索引的颜色表设为
QRgb
值,到指定
colors
.
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.
另请参阅
colorTable()
setColor()
图像
变换
PySide2.QtGui.QImage.
setDevicePixelRatio
(
scaleFactor
)
¶
scaleFactor
–
qreal
Sets the device pixel ratio for the image. This is the ratio between image pixels and device-independent pixels.
默认
scaleFactor
is 1.0. Setting it to something else has two effects:
QPainters that are opened on the image will be scaled. For example, painting on a 200x200 image if with a ratio of 2.0 will result in effective (device-independent) painting bounds of 100x100.
Code paths in Qt that calculate layout geometry based on the image size will take the ratio into account:
QSize
layoutSize = image.
size()
/ image.
devicePixelRatio()
The net effect of this is that the image is displayed as high-DPI image rather than a large image (see
绘制
High
Resolution
版本
of
Pixmaps
and
图像
).
另请参阅
devicePixelRatio()
PySide2.QtGui.QImage.
setDotsPerMeterX
(
arg__1
)
¶
arg__1
–
int
Sets the number of pixels that fit horizontally in a physical meter, to
x
.
Together with
dotsPerMeterY()
, this number defines the intended scale and aspect ratio of the image, and determines the scale at which
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.
另请参阅
dotsPerMeterX()
图像
Information
PySide2.QtGui.QImage.
setDotsPerMeterY
(
arg__1
)
¶
arg__1
–
int
Sets the number of pixels that fit vertically in a physical meter, to
y
.
Together with
dotsPerMeterX()
, this number defines the intended scale and aspect ratio of the image, and determines the scale at which
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.
另请参阅
dotsPerMeterY()
图像
Information
PySide2.QtGui.QImage.
setOffset
(
arg__1
)
¶
arg__1
–
QPoint
Sets the number of pixels by which the image is intended to be offset by when positioning relative to other images, to
offset
.
另请参阅
offset()
图像
Information
PySide2.QtGui.QImage.
setPixel
(
pt
,
index_or_rgb
)
¶
pt
–
QPoint
index_or_rgb
–
uint
设置像素索引或颜色在给定
position
to
index_or_rgb
.
If the image’s format is either monochrome or paletted, 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
>=
colorCount()
in the case of monochrome and paletted 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
scanLine()
or
bits()
to access pixel data directly.
另请参阅
pixel()
Pixel
操纵
PySide2.QtGui.QImage.
setPixel
(
x
,
y
,
index_or_rgb
)
¶
x
–
int
y
–
int
index_or_rgb
–
uint
这是重载函数。
设置像素索引或颜色在 (
x
,
y
) 到
index_or_rgb
.
PySide2.QtGui.QImage.
setPixelColor
(
pt
,
c
)
¶
pt
–
QPoint
c
–
QColor
设置颜色在给定
position
to
color
.
若
position
is not a valid coordinate pair in the image, or the image’s format is either monochrome or paletted, 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
scanLine()
or
bits()
to access pixel data directly.
另请参阅
pixelColor()
pixel()
bits()
scanLine()
Pixel
操纵
PySide2.QtGui.QImage.
setPixelColor
(
x
,
y
,
c
)
¶
x
–
int
y
–
int
c
–
QColor
这是重载函数。
设置像素颜色在 (
x
,
y
) 到
color
.
PySide2.QtGui.QImage.
setText
(
key
,
value
)
¶
key – unicode
value – unicode
将图像文本设为给定
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”.
图像文本被嵌入图像数据当调用
save()
or
write()
.
并非所有图像格式都支持嵌入文本。可以找出哪些特定图像或格式支持嵌入文本通过使用
supportsOption()
. We give an example:
writer = QImageWriter()
writer.setFormat("png")
if writer.supportsOption(QImageIOHandler.Description):
print "Png supports embedded text"
可以使用
supportedImageFormats()
to find out which image formats are available to you.
另请参阅
PySide2.QtGui.QImage.
size
(
)
¶
QSize
返回图片大小,即其
width()
and
height()
.
另请参阅
图像
Information
PySide2.QtGui.QImage.
sizeInBytes
(
)
¶
long
long
返回图像数据大小 (以字节为单位)。
另请参阅
byteCount()
bytesPerLine()
bits()
图像
Information
PySide2.QtGui.QImage.
smoothScaled
(
w
,
h
)
¶
w
–
int
h
–
int
返回平滑比例缩放图像副本。返回图像拥有尺寸的宽度为
w
按高度
h
像素。
PySide2.QtGui.QImage.
text
(
[
key=""
]
)
¶
key – unicode
unicode
PySide2.QtGui.QImage.
textKeys
(
)
¶
字符串列表
返回此图像的文本键。
You can use these keys with
text()
to list the image text for a certain key.
另请参阅
PySide2.QtGui.QImage.
toImageFormat
(
format
)
¶
format
–
QPixelFormat
转换
format
成
格式
PySide2.QtGui.QImage.
toPixelFormat
(
format
)
¶
format
–
格式
转换
format
成
QPixelFormat
PySide2.QtGui.QImage.
transformed
(
matrix
[
,
mode=Qt.FastTransformation
]
)
¶
注意
此函数被弃用。
PySide2.QtGui.QImage.
transformed
(
matrix
[
,
mode=Qt.FastTransformation
]
)
¶
matrix
–
QTransform
mode
–
TransformationMode
PySide2.QtGui.QImage.
trueMatrix
(
arg__1
,
w
,
h
)
¶
注意
此函数被弃用。
PySide2.QtGui.QImage.
trueMatrix
(
arg__1
,
w
,
h
)
¶
arg__1
–
QTransform
w
–
int
h
–
int