QPixmap 类

QPixmap 类是可以用作描绘设备的离屏图像表示。 更多...

Header: #include <QPixmap>
CMake: find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QPaintDevice
继承者:

QBitmap

公共函数

QPixmap (QPixmap && other )
QPixmap (const QPixmap & pixmap )
QPixmap (const char *const [] xpm )
QPixmap (const QString & fileName , const char * format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor)
QPixmap (const QSize & size )
QPixmap (int width , int height )
QPixmap ()
QPixmap & operator= (QPixmap && other )
QPixmap & operator= (const QPixmap & pixmap )
virtual ~QPixmap ()
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 = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor)
bool loadFromData (const uchar * data , uint len , const char * format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor)
bool loadFromData (const QByteArray & data , const char * format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor)
QBitmap mask () const
QRect rect () const
bool save (const QString & fileName , const char * format = nullptr, int quality = -1) const
bool save (QIODevice * device , const char * format = 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 = nullptr)
void scroll (int dx , int dy , const QRect & rect , QRegion * exposed = nullptr)
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
int width () const
QVariant operator QVariant () const
bool operator! () const

静态公共成员

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 )
QDataStream & operator<< (QDataStream & stream , const QPixmap & pixmap )
QDataStream & operator>> (QDataStream & stream , QPixmap & pixmap )

详细描述

Qt 为处理图像数据提供了 4 个类: QImage , QPixmap, QBitmap and QPicture . QImage 是为 I/O 及直接访问和操纵像素而设计和优化的,而 QPixmap 是为在屏幕上展示图像而设计和优化的。 QBitmap 只是继承 QPixmap 的方便类,确保 1 深度。 isQBitmap () 函数返回 true 如果 QPixmap 对象真的是位图,否则返回 false 。最后, QPicture 类是描绘设备,它记录并重演 QPainter 命令。

QPixmap 可以轻松地显示在屏幕上,使用 QLabel 或某一 QAbstractButton 子类 (譬如 QPushButton and QToolButton ). QLabel 拥有 pixmap 属性,而 QAbstractButton 拥有 icon 特性。

QPixmap 对象可以按值传递,由于 QPixmap 类使用隐式数据共享。更多信息,见 隐式数据共享 文档编制。QPixmap 对象还可以被流化。

注意:像素图中的像素数据是内部的,且由底层窗口系统管理。因为 QPixmap 是 QPaintDevice 子类, QPainter 可用于在像素图上直接绘制。像素只可以被访问透过 QPainter 函数或通过将 QPixmap 转换成 QImage 。不管怎样, fill () 函数可用于以给定颜色初始化整个像素图。

有函数能转换 QImage 和 QPixmap。通常, QImage 类用于加载图像文件,可选操纵图像数据,之后 QImage 对象被转换为 QPixmap,以展示在屏幕上。另外,若不期望操纵,可以直接将图像文件加载进 QPixmap。

QPixmap 提供一批函数,可用于获取有关像素图的各种信息。此外,还有几个函数使像素图能够变换。

读写图像文件

QPixmap 提供了读取图像文件的几种方式:可以在构造 QPixmap 对象时加载文件,或通过使用 load () 或 loadFromData () 函数稍后。当加载图像时,文件名可以引用实际磁盘文件,或引用某一应用程序嵌入资源。见 Qt 资源系统 概述,了解如何在应用程序可执行文件中嵌入图像及其它资源文件的细节。

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

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

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

像素图信息

QPixmap 提供可用于获取有关像素图各种信息的函数集合:

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

createHeuristicMask () 函数创建并返回 1-bpp 启发式遮罩 (即 QBitmap ) 对于此像素图而言。它通过在一个角选择颜色工作,然后从所有边缘开始切掉该颜色的像素。 createMaskFromColor () 函数创建并返回遮罩 (即 QBitmap ) 对于基于给定颜色的像素图而言。

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

cacheKey () 函数返回标识 QPixmap 对象内容的唯一数字。

像素图转换

QPixmap 对象可以转换成 QImage 使用 toImage () 函数。同样, QImage 可以转换成 QPixmap 使用 fromImage ()。若操作过于昂贵,可以使用 QBitmap::fromImage () 代替。

要转换 QPixmap 和 HICON,可以使用 QtWinExtras 函数 QtWin::toHICON() 和 QtWin::fromHICON()。

像素图变换

QPixmap 支持许多用于创建新像素图 (即:原始变换版本) 的函数:

scaled (), scaledToWidth () 和 scaledToHeight () 函数返回像素图的比例缩放拷贝,而 copy () 函数创建是原始 QPixmap 普通拷贝的 QPixmap。

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

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

成员函数文档编制

QPixmap:: QPixmap ( QPixmap && other )

移动构造 QPixmap 实例从 other .

另请参阅 swap () 和 operator= (QPixmap&&).

QPixmap:: QPixmap (const QPixmap & pixmap )

构造像素图拷贝为给定 pixmap .

另请参阅 copy ().

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

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

错误被默默忽略。

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

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

The extra 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 QString & fileName , const char * format = 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 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 资源系统 概述,了解如何在应用程序可执行文件中嵌入图像及其它资源文件的细节。

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 to control the conversion.

fileName , format and flags 参数被传递给 load (). This means that the data in fileName is not compiled into the binary. If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

另请参阅 读写图像文件 .

QPixmap:: QPixmap (const QSize & size )

这是重载函数。

构造像素图为给定 size .

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

QPixmap:: QPixmap ( int width , int height )

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

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

另请参阅 isNull ().

QPixmap:: QPixmap ()

构造 null 像素图。

另请参阅 isNull ().

[since 5.2] QPixmap &QPixmap:: operator= ( QPixmap && other )

移动赋值 other 到此 QPixmap 实例。

该函数在 Qt 5.2 引入。

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

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

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

[virtual] QPixmap:: ~QPixmap ()

销毁像素图。

qint64 QPixmap:: cacheKey () const

Returns a number that identifies this QPixmap . Distinct QPixmap objects can only have the same cache key if they refer to the same contents.

The cacheKey() will change when the pixmap is altered.

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

Replaces this pixmap's data with the given image 使用指定 flags 来控制转换。 flags 自变量是按位 OR 的 Qt::ImageConversionFlags 。传递 0 为 flags sets all the default options. Returns true if the result is that this pixmap is not null.

Note: this function was part of Qt 3 support in Qt 4.6 and earlier. It has been promoted to official API status in 4.7 to support updating the pixmap's image without creating a new QPixmap as fromImage () would.

另请参阅 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 is empty, the whole image is copied.

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

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

这是重载函数。

Returns a deep copy of the subset of the pixmap that is specified by the rectangle 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 is true (the default) the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels.

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());
							

This function is slow because it involves converting to/from a QImage , and non-trivial computations.

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

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

Creates and returns a mask for this pixmap based on the given 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.

This function is slow because it involves converting to/from a QImage .

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

[static] int QPixmap:: defaultDepth ()

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

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

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

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

int QPixmap:: depth () const

返回像素图的深度。

The pixmap depth is also called bits per pixel (bpp) or bit planes of a pixmap. A null pixmap has depth 0.

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

void QPixmap:: detach ()

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

A pixmap is automatically detached by Qt whenever its contents are about to change. This is done in almost all QPixmap member functions that modify the pixmap ( fill (), fromImage (), load (), etc.), and in QPainter::begin () on a pixmap.

There are two exceptions in which detach() must be called explicitly, that is when calling the handle() or the x11PictureHandle() function (only available on X11). Otherwise, any modifications done using system calls, will be performed on the shared data.

The detach() function returns immediately if there is just a single reference or if the pixmap has not been initialized yet.

qreal QPixmap:: devicePixelRatio () const

Returns the device pixel ratio for the pixmap. This is the ratio between device pixels and device independent pixels .

Use this function when calculating layout geometry based on the pixmap size: 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, since 5.3] 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 = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor)

从文件加载像素图采用给定 fileName . Returns true if the pixmap was successfully loaded; otherwise invalidates the pixmap and returns false .

加载器试图读取像素图使用指定 format 。若 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 资源系统 overview for details on how to embed pixmaps and other resource files in the application's executable.

If the data needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to control the conversion.

注意,QPixmap 被自动添加到 QPixmapCache when loaded from a file in main thread; the key used is internal and cannot be acquired.

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

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

Loads a pixmap from the len first bytes of the given binary data 。返回 true if the pixmap was loaded successfully; otherwise invalidates the pixmap and returns false .

加载器试图读取像素图使用指定 format 。若 format is not specified (which is the default), the loader probes the file for a header to guess the file format.

If the data needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to control the conversion.

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

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

这是重载函数。

Loads a pixmap from the binary data 使用指定 format and conversion flags .

QBitmap QPixmap:: mask () const

Extracts a bitmap mask from the pixmap's alpha channel.

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

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

QRect QPixmap:: rect () const

Returns the pixmap's enclosing rectangle.

另请参阅 像素图信息 .

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

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

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

format is nullptr ,图像格式将选取自 fileName 的后缀。

另请参阅 读写图像文件 .

bool QPixmap:: save ( QIODevice * device , const char * format = 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

这是重载函数。

Returns a copy of the pixmap scaled to a rectangle with the given width and height according to the given aspectRatioMode and transformMode .

width height is zero or negative, this function returns a null pixmap.

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

Returns a scaled copy of the image. The returned image is scaled to the given height using the specified transformation 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

Returns a scaled copy of the image. The returned image is scaled to the given width using the specified transformation 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 = nullptr)

This convenience function is equivalent to calling QPixmap::scroll( dx , dy , QRect ( x , y , width , height ), exposed ).

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

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

Scrolls the area 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);
							

You cannot scroll while there is an active painter on the pixmap.

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

void QPixmap:: setDevicePixelRatio ( qreal scaleFactor )

Sets the device pixel ratio for the pixmap. 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 pixmap 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 pixmap size will take the ratio into account: QSize layoutSize = pixmap. size () / pixmap. devicePixelRatio () The net effect of this is that the pixmap is displayed as high-DPI pixmap rather than a large pixmap (see 绘制高分辨率版本的像素图和图像 ).

另请参阅 devicePixelRatio ().

void QPixmap:: setMask (const QBitmap & mask )

设置遮罩位图。

此函数合并 mask with the pixmap's alpha channel. A pixel value of 1 on the mask means the pixmap's pixel is unchanged; a value of 0 means the pixel is transparent. The mask must have the same size as this pixmap.

Setting a null mask resets the mask, leaving the previously transparent pixels black. The effect of this function is undefined when the pixmap is being painted on.

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

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

QSize QPixmap:: size () const

返回像素图尺寸。

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

void QPixmap:: swap ( QPixmap & other )

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

QImage QPixmap:: toImage () const

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

If the pixmap has 1-bit depth, the returned image will also be 1 bit deep. Images with more bits will be returned in a format closely represents the underlying system. Usually this will be QImage::Format_ARGB32_Premultiplied for pixmaps with an alpha and QImage::Format_RGB32 or QImage::Format_RGB16 for pixmaps without alpha.

Note that for the moment, alpha masks on monochrome images are ignored.

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

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

Returns a copy of the pixmap that is transformed using the given transformation transform and transformation mode . The original pixmap is not changed.

The transformation transform is internally adjusted to compensate for unwanted translation; i.e. the pixmap produced is the smallest pixmap that contains all the transformed points of the original pixmap. Use the trueMatrix () function to retrieve the actual matrix used for transforming the pixmap.

This function is slow because it involves transformation to a QImage , non-trivial computations and a transformation back to a QPixmap .

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

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

Returns the actual matrix used for transforming a pixmap with the given width , height and matrix .

When transforming a pixmap using the transformed () function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. transformed () returns the smallest pixmap containing all transformed points of the original pixmap. This function returns the modified matrix, which maps points correctly from the original pixmap into the new pixmap.

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

int QPixmap:: width () const

返回像素图的宽度。

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

QVariant QPixmap:: operator QVariant () const

将像素图返回为 QVariant .

bool QPixmap:: operator! () const

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

另请参阅 isNull ().

相关非成员

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

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

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

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

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

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