QPixmap 类

QPixmap class is an off-screen image representation that can be used as a paint device. 更多...

头: #include <QPixmap>
qmake: QT += gui
继承: QPaintDevice
继承者:

QBitmap

公共函数

QPixmap ()
QPixmap (int width , int height )
QPixmap (const QSize & size )
QPixmap (const QString & fileName , const char * format = Q_NULLPTR, Qt::ImageConversionFlags flags = Qt::AutoColor)
QPixmap (const char * const[] xpm )
QPixmap (const QPixmap & pixmap )
~QPixmap ()
(弃用) QPixmap alphaChannel () const
qint64 cacheKey () const
bool convertFromImage (const QImage & image , Qt::ImageConversionFlags flags = Qt::AutoColor)
QPixmap copy (const QRect & rectangle = QRect()) const
QPixmap copy (int x , int y , int width , int height ) const
QBitmap createHeuristicMask (bool clipTight = true) const
QBitmap createMaskFromColor (const QColor & maskColor , Qt::MaskMode mode = Qt::MaskInColor) const
int depth () const
void detach ()
qreal devicePixelRatio () const
void fill (const QColor & color = Qt::white)
bool hasAlpha () const
bool hasAlphaChannel () const
int height () const
bool isNull () const
bool isQBitmap () const
bool load (const QString & fileName , const char * format = Q_NULLPTR, Qt::ImageConversionFlags flags = Qt::AutoColor)
bool loadFromData (const uchar * data , uint len , const char * format = Q_NULLPTR, Qt::ImageConversionFlags flags = Qt::AutoColor)
bool loadFromData (const QByteArray & data , const char * format = Q_NULLPTR, Qt::ImageConversionFlags flags = Qt::AutoColor)
QBitmap mask () const
QRect rect () const
bool save (const QString & fileName , const char * format = Q_NULLPTR, int quality = -1) const
bool save (QIODevice * device , const char * format = Q_NULLPTR, int quality = -1) const
QPixmap scaled (const QSize & size , Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const
QPixmap scaled (int width , int height , Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const
QPixmap scaledToHeight (int height , Qt::TransformationMode mode = Qt::FastTransformation) const
QPixmap scaledToWidth (int width , Qt::TransformationMode mode = Qt::FastTransformation) const
void scroll (int dx , int dy , int x , int y , int width , int height , QRegion * exposed = Q_NULLPTR)
void scroll (int dx , int dy , const QRect & rect , QRegion * exposed = Q_NULLPTR)
(弃用) void setAlphaChannel (const QPixmap & p )
void setDevicePixelRatio (qreal scaleFactor )
void setMask (const QBitmap & mask )
QSize size () const
void swap (QPixmap & other )
QImage toImage () const
QPixmap transformed (const QTransform & transform , Qt::TransformationMode mode = Qt::FastTransformation) const
QPixmap transformed (const QMatrix & matrix , Qt::TransformationMode mode = Qt::FastTransformation) const
int width () const
operator QVariant () const
bool operator! () const
QPixmap & operator= (const QPixmap & pixmap )
QPixmap & operator= (QPixmap && other )

静态公共成员

int defaultDepth ()
QPixmap fromImage (const QImage & image , Qt::ImageConversionFlags flags = Qt::AutoColor)
QPixmap fromImage (QImage && image , Qt::ImageConversionFlags flags = Qt::AutoColor)
QPixmap fromImageReader (QImageReader * imageReader , Qt::ImageConversionFlags flags = Qt::AutoColor)
QTransform trueMatrix (const QTransform & matrix , int width , int height )
QMatrix trueMatrix (const QMatrix & m , int w , int h )
QDataStream & operator<< (QDataStream & stream , const QPixmap & pixmap )
QDataStream & operator>> (QDataStream & stream , QPixmap & pixmap )

额外继承成员

详细描述

QPixmap class is an off-screen image representation that can be used as a paint device.

Qt 为处理图像数据提供了 4 个类: QImage , QPixmap , QBitmap and QPicture . QImage 是为 I/O 和直接访问/操纵像素而设计并优化的,而 QPixmap 是为在屏幕上展示图像而设计并优化的。 QBitmap 只是方便类,继承 QPixmap , ensuring a depth of 1. The isQBitmap () 函数返回 true QPixmap object is really a bitmap, otherwise returns false 。最后, QPicture 类是描绘设备,它记录并重演 QPainter 命令。

A QPixmap can easily be displayed on the screen using QLabel 或某一 QAbstractButton 子类 (譬如 QPushButton and QToolButton ). QLabel 拥有 pixmap 属性,而 QAbstractButton 拥有 icon 特性。

QPixmap 对象可以按值传递,由于 QPixmap class uses implicit data sharing. For more information, see the 隐式数据共享 文档编制。 QPixmap objects can also be streamed.

Note that the pixel data in a pixmap is internal and is managed by the underlying window system. Because QPixmap QPaintDevice 子类, QPainter 可用于在像素图上直接绘制。像素只可以被访问透过 QPainter functions or by converting the QPixmap QImage 。不管怎样, fill () 函数可用于以给定颜色初始化整个像素图。

有函数能转换 QImage and QPixmap . Typically, the QImage 类用于加载图像文件,可选操纵图像数据,之后 QImage object is converted into a QPixmap to be shown on screen. Alternatively, if no manipulation is desired, the image file can be loaded directly into a QPixmap .

QPixmap provides a collection of functions that can be used to obtain a variety of information about the pixmap. In addition, there are several functions that enables transformation of the pixmap.

读写图像文件

QPixmap provides several ways of reading an image file: The file can be loaded when constructing the QPixmap 对象,或通过使用 load () 或 loadFromData () 函数稍后。当加载图像时,文件名可以引用实际磁盘文件,或引用应用程序的某一嵌入资源。见 Qt 资源系统 概述,了解如何在应用程序可执行文件中嵌入图像及其它资源文件的细节。

只需调用 save () 函数以保存 QPixmap 对象。

可获得支持的文件格式的完整列表,透过 QImageReader::supportedImageFormats () 和 QImageWriter::supportedImageFormats () 函数。可以将新文件格式添加作为插件。默认情况下,Qt 支持以下格式:

格式 描述 Qt 支持
BMP Windows 位图 读/写
GIF GIF (图形互换格式) 可选 读取
JPG JPEG (联合摄影专家组) 读/写
JPEG JPEG (联合摄影专家组) 读/写
PNG PNG (便携式网络图形) 读/写
PBM PBM (便携式位图) 读取
PGM PGM (便携式灰度图) 读取
PPM Portable Pixmap (便携式像素图) 读/写
XBM X11 Bitmap (X11 位图) 读/写
XPM X11 Pixmap (X11 像素图) 读/写

像素图信息

QPixmap provides a collection of functions that can be used to obtain a variety of information about the pixmap:

可用函数
几何体 size (), width () 和 height () 函数提供像素图大小的有关信息。 rect () 函数返回图像的封闭矩形。
Alpha 组件 hasAlphaChannel () 返回 true 若像素图是遵守 Alpha 通道的格式,否则返回 false hasAlpha (), setMask () 和 mask () 函数是传统的且不应使用。它们潜在非常慢。

createHeuristicMask () 函数创建并返回 1-bpp 试探遮罩 (即 QBitmap ) 对于此像素图。它的工作原理是通过从一角选择颜色,然后从所有边缘开始削掉相应颜色的像素。 createMaskFromColor () 函数创建并返回遮罩 (即 QBitmap ) 对于基于给定颜色的像素图而言。

低级信息 depth () 函数返回像素图的深度。 defaultDepth () 函数返回默认深度 (即:应用程序在给定屏幕上所使用的深度)。

cacheKey () function returns a number that uniquely identifies the contents of the QPixmap 对象。

The x11Info() function returns information about the configuration of the X display used by the screen to which the pixmap currently belongs. The x11PictureHandle() function returns the X11 Picture handle of the pixmap for XRender support. Note that the two latter functions are only available on x11.

像素图转换

A QPixmap object can be converted into a QImage 使用 toImage () 函数。同样, QImage can be converted into a QPixmap 使用 fromImage ()。若操作过于昂贵,可以使用 QBitmap::fromImage () 代替。

To convert a QPixmap to and from HICON you can use the QtWinExtras 函数 QtWin::toHICON () 和 QtWin::fromHICON () respectively.

像素图变换

QPixmap supports a number of functions for creating a new pixmap that is a transformed version of the original:

scaled (), scaledToWidth () 和 scaledToHeight () 函数返回像素图的比例缩放拷贝,而 copy () function creates a QPixmap that is a plain copy of the original one.

transformed () 函数返回按给定变换矩阵和变换模式变换的像素图副本:在内部,调节变换矩阵以补偿不想要的平移,即 transformed () 返回包含原始像素图所有变换点的最小像素图。静态 trueMatrix () 函数返回用于变换像素图的实际矩阵。

注意: When using the native X11 graphics system, the pixmap becomes invalid when the QApplication instance is destroyed.

另请参阅 QBitmap , QImage , QImageReader ,和 QImageWriter .

成员函数文档编制

QPixmap:: QPixmap ()

构造 null 像素图。

另请参阅 isNull ().

QPixmap:: QPixmap ( int width , int height )

构造像素图采用给定 width and height 。若 width or height 为 0,构造 null 像素图。

警告: 这将创建 QPixmap 采用未初始化数据。调用 fill () 以合适颜色填充像素图先于绘制采用 QPainter .

另请参阅 isNull ().

QPixmap:: QPixmap (const QSize & size )

这是重载函数。

构造像素图为给定 size .

警告: 这将创建 QPixmap 采用未初始化数据。调用 fill () 以合适颜色填充像素图先于绘制采用 QPainter .

QPixmap:: QPixmap (const QString & fileName , const char * format = Q_NULLPTR, Qt::ImageConversionFlags flags = Qt::AutoColor)

从文件构造像素图采用给定 fileName . If the file does not exist or is of an unknown format, the pixmap becomes a null pixmap.

加载器试图读取像素图使用指定 format 。若 format 未指定 (默认),加载器会探针文件 Header 头以猜测文件格式。

文件名可以引用实际磁盘文件,或引用应用程序的某一嵌入资源。见 资源系统 概述,了解如何在应用程序可执行文件中嵌入图像及其它资源文件的细节。

If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags 来控制转换。

fileName , format and flags 参数被传递给 load (). This means that the data in fileName is not compiled into the binary. If fileName 包含相对路径(如:仅文件名),必须相对运行时工作目录查找相关文件。

另请参阅 读写图像文件 .

QPixmap:: QPixmap (const char * const[] xpm )

构造像素图从给定 xpm 数据,必须是有效 XPM 图像。

错误被默默忽略。

注意,通过使用不寻常声明稍微挤压 XPM 变量是可能的:

static const char * const start_xpm[]={
    "16 15 8 1",
    "a c #cec6bd",
....
					

额外 const makes the entire definition read-only, which is slightly more efficient (for example, when the code is in a shared library) and ROMable when the application is to be stored in ROM.

QPixmap:: QPixmap (const QPixmap & pixmap )

构造像素图副本为给定 pixmap .

另请参阅 copy ().

QPixmap:: ~QPixmap ()

销毁像素图。

QPixmap QPixmap:: alphaChannel () const

此函数被弃用。

可以达成这的大多数使用案例是使用 QPainter and QPainter::CompositionMode 代替。

另请参阅 setAlphaChannel ().

qint64 QPixmap:: cacheKey () const

返回的数字标识此 QPixmap 。截然不同的 QPixmap 对象只可以拥有相同缓存键,若它们引用相同内容。

cacheKey() 会改变,当像素图变更时。

bool QPixmap:: convertFromImage (const QImage & image , Qt::ImageConversionFlags flags = Qt::AutoColor)

替换此像素图的数据采用给定 image 使用指定 flags 来控制转换。 flags 自变量是按位 OR 的 Qt::ImageConversionFlags 。传递 0 为 flags 设置所有默认选项。返回 true 若结果是此像素图不为 null。

注意:此函数是 Qt 4.6 及更早版本的 Qt 3 支持的一部分。在 4.7 已提升为官方 API 状态以支持更新像素图图像,不用创建新的 QPixmap as fromImage () would.

该函数在 Qt 4.7 引入。

另请参阅 fromImage ().

QPixmap QPixmap:: copy (const QRect & rectangle = QRect()) const

Returns a deep copy of the subset of the pixmap that is specified by the given rectangle . For more information on deep copies, see the 隐式数据共享 文档编制。

若给定 rectangle 为空,拷贝整个图像。

另请参阅 operator= (), QPixmap (),和 像素图变换 .

QPixmap QPixmap:: copy ( int x , int y , int width , int height ) const

这是重载函数。

返回像素图子集的深拷贝,指定通过矩形 QRect ( x , y , width , height ).

QBitmap QPixmap:: createHeuristicMask ( bool clipTight = true) const

创建并返回此像素图的试探遮罩。

The function works by selecting a color from one of the corners and then chipping away pixels of that color, starting at all the edges. If clipTight 为 true (默认),遮罩刚好足够大以覆盖像素;否则,遮罩大于数据像素。

The mask may not be perfect but it should be reasonable, so you can do things such as the following:

QPixmap myPixmap;
myPixmap.setMask(myPixmap.createHeuristicMask());
					

此函数很慢,因为它涉及转换到/从 QImage ,及非通俗计算。

另请参阅 QImage::createHeuristicMask () 和 createMaskFromColor ().

QBitmap QPixmap:: createMaskFromColor (const QColor & maskColor , Qt::MaskMode mode = Qt::MaskInColor) const

创建并返回用于此像素图的遮罩基于给定 maskColor 。若 mode is Qt::MaskInColor , all pixels matching the maskColor will be transparent. If mode is Qt::MaskOutColor , all pixels matching the maskColor will be opaque.

此函数很慢,因为它涉及转换到/从 QImage .

另请参阅 createHeuristicMask () 和 QImage::createMaskFromColor ().

[static] int QPixmap:: defaultDepth ()

返回用于应用程序的默认像素图深度。

在所有平台,将返回首要屏幕深度。

注意: QGuiApplication 必须被创建在调用此函数之前。

另请参阅 depth (), QColormap::depth (),和 像素图信息 .

int QPixmap:: depth () const

返回像素图的深度。

像素图深度又称 BPP (每像素位) 或像素图位平面。null 像素图拥有深度 0。

另请参阅 defaultDepth () 和 像素图信息 .

void QPixmap:: detach ()

从共享像素图数据分离像素图。

像素图会被 Qt 自动分离,每当其内容即将改变时。这的完成是在几乎所有 QPixmap 成员函数修改像素图 ( fill (), fromImage (), load (),等),和在 QPainter::begin () 在像素图。

必须明确调用 detach() 存在 2 种例外情况,就是当调用 handle() 或 x11PictureHandle() 函数 (只可用于 X11) 时。否则,使用系统调用完成的任何修改,都将在共享数据中履行。

detach() 函数会立即返回,若仅仅存在一个引用 (或者,若像素图尚未被初始化)。

qreal QPixmap:: devicePixelRatio () const

返回像素图的设备像素比率。此比率介于 设备像素 and 设备无关像素 .

使用此函数,当基于像素图大小计算布局几何体时: QSize layoutSize = image. size () / image.devicePixelRatio()

默认值为 1.0。

另请参阅 setDevicePixelRatio () 和 QImageReader .

void QPixmap:: fill (const QColor & color = Qt::white)

填充像素图采用给定 color .

此函数的作用未定义,当正在描绘像素图时。

另请参阅 像素图变换 .

[static] QPixmap QPixmap:: fromImage (const QImage & image , Qt::ImageConversionFlags flags = Qt::AutoColor)

转换给定 image 到像素图使用指定 flags 来控制转换。 flags 自变量是按位 OR 的 Qt::ImageConversionFlags 。传递 0 为 flags 设置所有默认选项。

在单色和 8 位图像情况下,图像首先被转换成 32 位像素图,然后采用颜色表颜色填充。若此操作过于昂贵,可以使用 QBitmap::fromImage () 代替。

另请参阅 fromImageReader (), toImage (),和 像素图转换 .

[static] QPixmap QPixmap:: fromImage ( QImage && image , Qt::ImageConversionFlags flags = Qt::AutoColor)

这是重载函数。

转换给定 image 到像素图不拷贝 (若可能的话)。

该函数在 Qt 5.3 引入。

[static] QPixmap QPixmap:: fromImageReader ( QImageReader * imageReader , Qt::ImageConversionFlags flags = Qt::AutoColor)

创建 QPixmap 从图像直接读取自 imageReader flags 自变量是按位 OR 的 Qt::ImageConversionFlags 。传递 0 为 flags 设置所有默认选项。

在某些系统,将图像直接读取到 QPixmap 可以使用更少内存相比读取 QImage 以转换它到 QPixmap .

另请参阅 fromImage (), toImage (),和 像素图转换 .

bool QPixmap:: hasAlpha () const

返回 true 若此像素图有 Alpha 通道, or 有遮罩,否则返回 false .

另请参阅 hasAlphaChannel () 和 mask ().

bool QPixmap:: hasAlphaChannel () const

返回 true 若像素图是遵守 Alpha 通道的格式,否则返回 false .

另请参阅 hasAlpha ().

int QPixmap:: height () const

返回像素图的高度。

另请参阅 size () 和 像素图信息 .

bool QPixmap:: isNull () const

返回 true 若这是 null 像素图;否则返回 false .

A null pixmap has zero width, zero height and no contents. You cannot draw in a null pixmap.

bool QPixmap:: isQBitmap () const

返回 true 若这是 QBitmap ;否则返回 false .

bool QPixmap:: load (const QString & fileName , const char * format = Q_NULLPTR, Qt::ImageConversionFlags flags = Qt::AutoColor)

从文件加载像素图采用给定 fileName 。返回 true 若像素图加载成功;否则使像素图无效并返回 false .

加载器试图读取像素图使用指定 format 。若 format 未指定 (默认),加载器会探针文件 Header 头以猜测文件格式。

文件名可以引用实际磁盘文件,或引用应用程序的某一嵌入资源。见 资源系统 概述了解如何在应用程序可执行文件中嵌入像素图及其它资源文件的细节。

若需要修改数据以拟合较低分辨率的结果 (如:从 32 位转换到 8 位),使用 flags 来控制转换。

注意:QPixmap 会被自动添加到 QPixmapCache when loaded from a file; the key used is internal and can not be acquired.

另请参阅 loadFromData () 和 读写图像文件 .

bool QPixmap:: loadFromData (const uchar * data , uint len , const char * format = Q_NULLPTR, Qt::ImageConversionFlags flags = Qt::AutoColor)

加载像素图从 len 首字节的给定二进制 data 。返回 true 若像素图加载成功;否则使像素图无效并返回 false .

加载器试图读取像素图使用指定 format 。若 format 未指定 (默认),加载器会探针文件 Header 头以猜测文件格式。

若需要修改数据以拟合较低分辨率的结果 (如:从 32 位转换到 8 位),使用 flags 来控制转换。

另请参阅 load () 和 读写图像文件 .

bool QPixmap:: loadFromData (const QByteArray & data , const char * format = Q_NULLPTR, Qt::ImageConversionFlags flags = Qt::AutoColor)

这是重载函数。

加载像素图从二进制 data 使用指定 format 和转换 flags .

QBitmap QPixmap:: mask () const

从像素图的 Alpha 通道提取位图遮罩。

警告: This is potentially an expensive operation. The mask of the pixmap is extracted dynamically from the pixeldata.

另请参阅 setMask () 和 像素图信息 .

QRect QPixmap:: rect () const

返回像素图的封闭矩形。

另请参阅 像素图信息 .

bool QPixmap:: save (const QString & fileName , const char * format = Q_NULLPTR, int quality = -1) const

把像素图保存到文件,采用给定 fileName 使用指定图像文件 format and quality 因子。返回 true 若成功;否则返回 false .

quality 因子必须在 [0,100] 范围内或为 -1。指定 0 以获得小压缩文件,100 为大的未压缩文件,和 -1 使用默认设置。

format is 0, an image format will be chosen from fileName 的后缀。

另请参阅 读写图像文件 .

bool QPixmap:: save ( QIODevice * device , const char * format = Q_NULLPTR, int quality = -1) const

这是重载函数。

此函数写入 QPixmap 到给定 device 使用指定图像文件 format and quality 因子。这可以被使用,例如:把像素图直接保存到 QByteArray :

        QPixmap pixmap;
        QByteArray bytes;
        QBuffer buffer(&bytes);
        buffer.open(QIODevice::WriteOnly);
        pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
					

QPixmap QPixmap:: scaled (const QSize & size , Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const

缩放像素图到给定 size ,使用宽高比和变换模式,指定通过 aspectRatioMode and transformMode .

若给定 size 为空,此函数返回 null 像素图。

在某些情况下,把像素图绘制到具有比例缩放设置的描绘器,比比例缩放像素图效果更好。如:当描绘器是基于 OpenGL 的实例,或当比例缩放因子快速变化时。

另请参阅 isNull () 和 像素图变换 .

QPixmap QPixmap:: scaled ( int width , int height , Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const

这是重载函数。

返回的像素图副本被比例缩放到矩形采用给定 width and height 根据给定 aspectRatioMode and transformMode .

width height 为 0 或负值,此函数返回 null 像素图。

QPixmap QPixmap:: scaledToHeight ( int height , Qt::TransformationMode mode = Qt::FastTransformation) const

返回图像的比例缩放副本。返回图像被比例缩放到给定 height 使用指定变换 mode . The width of the pixmap is automatically calculated so that the aspect ratio of the pixmap is preserved.

height 为 0 或负数,返回 null 像素图。

另请参阅 isNull () 和 像素图变换 .

QPixmap QPixmap:: scaledToWidth ( int width , Qt::TransformationMode mode = Qt::FastTransformation) const

返回图像的比例缩放副本。返回图像被比例缩放到给定 width 使用指定变换 mode . The height of the pixmap is automatically calculated so that the aspect ratio of the pixmap is preserved.

width 为 0 或负数,返回 null 像素图。

另请参阅 isNull () 和 像素图变换 .

void QPixmap:: scroll ( int dx , int dy , int x , int y , int width , int height , QRegion * exposed = Q_NULLPTR)

此方便函数相当于调用 QPixmap::scroll( dx , dy , QRect ( x , y , width , height ), exposed ).

该函数在 Qt 4.6 引入。

另请参阅 QWidget::scroll () 和 QGraphicsItem::scroll ().

void QPixmap:: scroll ( int dx , int dy , const QRect & rect , QRegion * exposed = Q_NULLPTR)

卷动区域 rect of this pixmap by ( dx , dy ). The exposed region is left unchanged. You can optionally pass a pointer to an empty QRegion to get the region that is exposed by the scroll operation.

QPixmap pixmap("background.png");
QRegion exposed;
pixmap.scroll(10, 10, pixmap.rect(), &exposed);
					

无法卷动,当像素图中有活动描绘器时。

该函数在 Qt 4.6 引入。

另请参阅 QWidget::scroll () 和 QGraphicsItem::scroll ().

void QPixmap:: setAlphaChannel (const QPixmap & p )

此函数被弃用。

Most use cases for this can be achieved using p with QPainter and QPainter::CompositionMode 代替。

另请参阅 alphaChannel ().

void QPixmap:: setDevicePixelRatio ( qreal scaleFactor )

设置像素图的设备像素比率。这是图像像素和设备无关像素之间的比率。

默认 scaleFactor 为 1.0。将它设为其它值有 2 种效果:

将比例缩放在像素图中打开的 QPainter。例如,若采用比率 2.0,在 200x200 图像中描绘将产生有效 (独立于设备) 的 100x100 描绘边界。

Qt 中基于像素图大小计算布局几何体的代码路径,会考虑比率: QSize layoutSize = pixmap. size () / pixmap. devicePixelRatio () 这的净效果是像素图被显示成高 DPI (每英寸点数) 像素图,而不是大像素图 (见 绘制高分辨率版本的像素图和图像 ).

另请参阅 devicePixelRatio ().

void QPixmap:: setMask (const QBitmap & mask )

设置遮罩位图。

此函数合并 mask 采用像素图的 Alpha 通道。遮罩像素值 1 意味着像素图的像素无变化;值 0 意味着像素透明。遮罩必须拥有如此像素图的相同大小。

设置 null 遮罩将重置遮罩,使先前透明像素变为黑色。此函数的效果未定义,当描绘像素图时。

警告: 这是潜在的昂贵操作。

另请参阅 mask (), 像素图变换 ,和 QBitmap .

QSize QPixmap:: size () const

返回像素图尺寸。

另请参阅 width (), height (),和 像素图信息 .

void QPixmap:: swap ( QPixmap & other )

交换像素图 other 与此像素图。此操作非常快且从不失败。

该函数在 Qt 4.8 引入。

QImage QPixmap:: toImage () const

将像素图转换成 QImage 。返回 null 图像,若转换失败。

若像素图拥有 1 位深度,返回图像也将是 1 位深。具有更多位的图像将按底层系统所表示的密切格式返回。通常,这会是 QImage::Format_ARGB32_Premultiplied 对于具有 Alpha 的像素图和 QImage::Format_RGB32 or QImage::Format_RGB16 对于没有 Alpha 的像素图。

注意:目前,单色图像忽略 Alpha 遮罩。

另请参阅 fromImage () 和 图像格式 .

QPixmap QPixmap:: transformed (const QTransform & transform , Qt::TransformationMode mode = Qt::FastTransformation) const

返回像素图副本的变换是使用给定变换 transform 和变换 mode 。不改变原始像素图。

变换 transform 在内部调节以补偿不想要的平移;即,产生像素图是包含原始像素图所有变换点的最小像素图。使用 trueMatrix () 函数能检索用于变换像素图的实际矩阵。

此函数很慢,因为它涉及变换到 QImage ,非通俗计算及变换回 QPixmap .

另请参阅 trueMatrix () 和 像素图变换 .

QPixmap QPixmap:: transformed (const QMatrix & matrix , Qt::TransformationMode mode = Qt::FastTransformation) const

这是重载函数。

This convenience function loads the matrix QTransform and calls the overloaded function.

[static] QTransform QPixmap:: trueMatrix (const QTransform & matrix , int width , int height )

返回用于变换像素图的实际矩阵采用给定 width , height and matrix .

当变换像素图使用 transformed () 函数,变换矩阵在内部调节以补偿不想要的平移,即 transformed () 返回包含原始像素图所有变换点的最小像素图。此函数返回将原始像素图中的点,正确映射到新像素图的修改矩阵。

另请参阅 transformed () 和 像素图变换 .

[static] QMatrix QPixmap:: trueMatrix (const QMatrix & m , int w , int h )

这是重载函数。

This convenience function loads the matrix m QTransform and calls the overloaded function with the QTransform and the width w and the height h .

int QPixmap:: width () const

返回像素图的宽度。

另请参阅 size () 和 像素图信息 .

QPixmap:: operator QVariant () const

将像素图返回为 QVariant .

bool QPixmap:: operator! () const

返回 true 若这是 null 像素图;否则返回 false .

另请参阅 isNull ().

QPixmap &QPixmap:: operator= (const QPixmap & pixmap )

赋值给定 pixmap 到此像素图并返回此像素图的引用。

另请参阅 copy () 和 QPixmap ().

QPixmap &QPixmap:: operator= ( QPixmap && other )

移动赋值 other 到此 QPixmap 实例。

该函数在 Qt 5.2 引入。

相关非成员

QDataStream & operator<< ( QDataStream & stream , const QPixmap & pixmap )

写入给定 pixmap 到给定 stream 作为 PNG 图像。注意:将流写入文件不会产生有效图像文件。

另请参阅 QPixmap::save () 和 序列化 Qt 数据类型 .

QDataStream & operator>> ( QDataStream & stream , QPixmap & pixmap )

读取图像从给定 stream 进给定 pixmap .

另请参阅 QPixmap::load () 和 序列化 Qt 数据类型 .