QPixmap 类

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

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

QBitmap

公共函数

QPixmap ()
QPixmap (int width , int height )
QPixmap (const QSize & size )
QPixmap (const QString & fileName , const char * format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor)
QPixmap (const char *const [] xpm )
QPixmap (const QPixmap & pixmap )
virtual ~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 = 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 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
QVariant 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 is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap , ensuring a depth of 1. The isQBitmap () 函数返回 true if a QPixmap object is really a bitmap, otherwise returns false 。最后, QPicture 类是描绘设备,它记录并重演 QPainter 命令。

A QPixmap can easily be displayed on the screen using QLabel or one of QAbstractButton 's subclasses (such as QPushButton and QToolButton ). QLabel has a pixmap property, whereas QAbstractButton has an icon property.

QPixmap objects can be passed around by value since the QPixmap class uses implicit data sharing. For more information, see the Implicit Data Sharing 文档编制。 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 subclass, QPainter can be used to draw directly onto pixmaps. Pixels can only be accessed through QPainter functions or by converting the QPixmap to a QImage . However, the fill () function is available for initializing the entire pixmap with a given color.

There are functions to convert between QImage and QPixmap . Typically, the QImage class is used to load an image file, optionally manipulating the image data, before the 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 object, or by using the load () 或 loadFromData () functions later on. 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.

Simply call the save () function to save a QPixmap 对象。

The complete list of supported file formats are available through the QImageReader::supportedImageFormats () 和 QImageWriter::supportedImageFormats () functions. New file formats can be added as plugins. By default, Qt supports the following formats:

Format 描述 Qt 支持
BMP Windows Bitmap 读/写
GIF Graphic Interchange Format (optional)
JPG Joint Photographic Experts Group 读/写
JPEG Joint Photographic Experts Group 读/写
PNG Portable Network Graphics 读/写
PBM Portable Bitmap
PGM Portable Graymap
PPM Portable Pixmap 读/写
XBM X11 Bitmap 读/写
XPM X11 Pixmap 读/写

像素图信息

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

Available Functions
Geometry size (), width () 和 height () functions provide information about the pixmap's size. The rect () function returns the image's enclosing rectangle.
Alpha component hasAlphaChannel () 返回 true if the pixmap has a format that respects the alpha channel, otherwise returns false hasAlpha (), setMask () 和 mask () functions are legacy and should not be used. They are potentially very slow.

createHeuristicMask () function creates and returns a 1-bpp heuristic mask (i.e. a QBitmap ) for this pixmap. It works by selecting a color from one of the corners and then chipping away pixels of that color, starting at all the edges. The createMaskFromColor () function creates and returns a mask (i.e. a QBitmap ) for the pixmap based on a given color.

Low-level information depth () function returns the depth of the pixmap. The defaultDepth () function returns the default depth, i.e. the depth used by the application on the given screen.

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 () function. Likewise, a QImage can be converted into a QPixmap 使用 fromImage (). If this is too expensive an operation, you can use QBitmap::fromImage () 代替。

To convert a QPixmap to and from HICON you can use the QtWinExtras functions QtWin::toHICON() and 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 () functions return scaled copies of the pixmap, while the copy () function creates a QPixmap that is a plain copy of the original one.

transformed () function returns a copy of the pixmap 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 pixmap containing all transformed points of the original pixmap. The static trueMatrix () function returns the actual matrix used for transforming the pixmap.

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

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

成员函数文档编制

QPixmap:: QPixmap ()

Constructs a null pixmap.

另请参阅 isNull ().

QPixmap:: QPixmap ( int width , int height )

Constructs a pixmap with the given width and height . If either width or height is zero, a null pixmap is constructed.

警告: This will create a QPixmap with uninitialized data. Call fill () to fill the pixmap with an appropriate color before drawing onto it with QPainter .

另请参阅 isNull ().

QPixmap:: QPixmap (const QSize & size )

这是重载函数。

Constructs a pixmap of the given size .

警告: This will create a QPixmap with uninitialized data. Call fill () to fill the pixmap with an appropriate color before drawing onto it with QPainter .

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

Constructs a pixmap from the file with the given fileName . If the file does not exist or is of an unknown format, the pixmap becomes a null pixmap.

The loader attempts to read the pixmap using the specified 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 Resource System overview for details on how to embed images and other resource files in the application's executable.

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 parameters are passed on to 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 char *const [] xpm )

Constructs a pixmap from the given xpm data, which must be a valid XPM image.

Errors are silently ignored.

Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:

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

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 QPixmap & pixmap )

Constructs a pixmap that is a copy of the given pixmap .

另请参阅 copy ().

[virtual] QPixmap:: ~QPixmap ()

Destroys the pixmap.

QPixmap QPixmap:: alphaChannel () const

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

另请参阅 setAlphaChannel ().

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 using the specified flags to control the conversion. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags . Passing 0 for 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.

This function was introduced in 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 Implicit Data Sharing 文档编制。

若给定 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

Creates and returns a heuristic mask for this pixmap.

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

Returns the default pixmap depth used by the application.

On all platforms the depth of the primary screen will be returned.

注意: QGuiApplication must be created before calling this function.

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

int QPixmap:: depth () const

Returns the depth of the pixmap.

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

Detaches the pixmap from shared pixmap data.

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 to a pixmap using the specified flags to control the conversion. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags . Passing 0 for flags sets all the default options.

In case of monochrome and 8-bit images, the image is first converted to a 32-bit pixmap and then filled with the colors in the color table. If this is too expensive an operation, you can use QBitmap::fromImage () 代替。

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

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

这是重载函数。

转换给定 image to a pixmap without copying if possible.

This function was introduced in Qt 5.3.

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

创建 QPixmap from an image read directly from an imageReader flags argument is a bitwise-OR of the Qt::ImageConversionFlags . Passing 0 for flags sets all the default options.

On some systems, reading an image directly to QPixmap can use less memory than reading a QImage to convert it to QPixmap .

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

bool QPixmap:: hasAlpha () const

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

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

bool QPixmap:: hasAlphaChannel () const

返回 true if the pixmap has a format that respects the alpha channel, otherwise returns 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)

Loads a pixmap from the file with the given fileName . Returns true if the pixmap was successfully loaded; otherwise invalidates the pixmap and returns false .

The loader attempts to read the pixmap using the specified 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 Resource System 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.

Note that QPixmaps are automatically added to the 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 .

The loader attempts to read the pixmap using the specified 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 using the specified 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 0, an image format will be chosen from 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 .

If either the 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 is 0 or negative, a null pixmap is returned.

另请参阅 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 is 0 or negative, a null pixmap is returned.

另请参阅 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 ).

This function was introduced in Qt 4.6.

另请参阅 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.

This function was introduced in 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 )

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 )

设置遮罩位图。

This function merges the 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.

警告: This is potentially an expensive operation.

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

QSize QPixmap:: size () const

返回像素图尺寸。

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

void QPixmap:: swap ( QPixmap & other )

Swaps pixmap other with this pixmap. This operation is very fast and never fails.

This function was introduced in Qt 4.8.

QImage QPixmap:: toImage () const

Converts the pixmap to a QImage . Returns a null image if the conversion fails.

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 () 和 像素图变换 .

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

这是重载函数。

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

[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 () 和 像素图变换 .

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

这是重载函数。

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

int QPixmap:: width () const

Returns the width of the pixmap.

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

QVariant QPixmap:: operator QVariant () const

Returns the pixmap as a QVariant .

bool QPixmap:: operator! () const

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

另请参阅 isNull ().

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

Assigns the given pixmap to this pixmap and returns a reference to this pixmap.

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

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

移动赋值 other 到此 QPixmap 实例。

This function was introduced in Qt 5.2.

相关非成员

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

写入给定 pixmap 到给定 stream as a PNG image. Note that writing the stream to a file will not produce a valid image file.

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

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

Reads an image from the given stream into the given pixmap .

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