The QPixmap 类是可以用作描绘设备的离屏图像表示。 更多...
| 头: | #include <QPixmap> |
| 继承: | QPaintDevice |
| 继承者: | Q3CanvasPixmap and QBitmap |
| enum | HBitmapFormat { NoAlpha, PremultipliedAlpha, Alpha } |
| enum | ShareMode { ImplicitlyShared, ExplicitlyShared } |
| QPixmap () | |
| QPixmap (int width , int height ) | |
| QPixmap (const QString & fileName , const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor) | |
| QPixmap (const char * const[] xpm ) | |
| QPixmap (const QPixmap & pixmap ) | |
| QPixmap (const QSize & size ) | |
| ~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 ) const |
| QBitmap | createMaskFromColor (const QColor & maskColor ) const |
| int | depth () const |
| void | detach () |
| void | fill (const QColor & color = Qt::white) |
| void | fill (const QWidget * widget , const QPoint & offset ) |
| void | fill (const QWidget * widget , int x , int y ) |
| Qt::HANDLE | handle () const |
| bool | hasAlpha () const |
| bool | hasAlphaChannel () const |
| int | height () const |
| bool | isNull () const |
| bool | isQBitmap () const |
| bool | load (const QString & fileName , const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor) |
| bool | loadFromData (const uchar * data , uint len , const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor) |
| bool | loadFromData (const QByteArray & data , const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor) |
| QBitmap | mask () const |
| QRect | rect () const |
| bool | save (const QString & fileName , const char * format = 0, int quality = -1) const |
| bool | save (QIODevice * device , const char * format = 0, 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 = 0) |
| void | scroll (int dx , int dy , const QRect & rect , QRegion * exposed = 0) |
| void | setMask (const QBitmap & mask ) |
| QSize | size () const |
| void | swap (QPixmap & other ) |
| QImage | toImage () const |
| CGImageRef | toMacCGImageRef () const |
| CFbsBitmap * | toSymbianCFbsBitmap () const |
| RSgImage * | toSymbianRSgImage () const |
| HBITMAP | toWinHBITMAP (HBitmapFormat format = NoAlpha) const |
| HICON | toWinHICON () 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 |
| const QX11Info & | x11Info () const |
| Qt::HANDLE | x11PictureHandle () 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 | fromImageReader (QImageReader * imageReader , Qt::ImageConversionFlags flags = Qt::AutoColor) |
| QPixmap | fromMacCGImageRef (CGImageRef image ) |
| QPixmap | fromSymbianCFbsBitmap (CFbsBitmap * bitmap ) |
| QPixmap | fromSymbianRSgImage (RSgImage * sgImage ) |
| QPixmap | fromWinHBITMAP (HBITMAP bitmap , HBitmapFormat format = NoAlpha) |
| QPixmap | fromWinHICON (HICON icon ) |
| QPixmap | fromX11Pixmap (Qt::HANDLE pixmap , ShareMode mode = ImplicitlyShared) |
| QPixmap | grabWidget (QWidget * widget , const QRect & rectangle ) |
| QPixmap | grabWidget (QWidget * widget , int x = 0, int y = 0, int width = -1, int height = -1) |
| QPixmap | grabWindow (WId window , int x = 0, int y = 0, int width = -1, int height = -1) |
| 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 ) |
The QPixmap 类是可以用作描绘设备的离屏图像表示。
Qt 为处理图像数据提供了 4 个类: QImage , QPixmap , QBitmap and QPicture . QImage 是为 I/O 和直接访问/操纵像素而设计并优化的,而 QPixmap 是为在屏幕上展示图像而设计并优化的。 QBitmap 只是方便类,继承 QPixmap ,确保 1 深度。 isQBitmap () function returns true if a QPixmap object is really a bitmap, otherwise returns false. Finally, the QPicture 类是描绘设备,它记录并重演 QPainter 命令。
A QPixmap 可以轻松显示在屏幕上使用 QLabel 或某一 QAbstractButton 子类 (譬如 QPushButton and QToolButton ). QLabel 拥有 pixmap 属性,而 QAbstractButton 拥有 icon 特性。
In addition to the ordinary constructors, a QPixmap can be constructed using the static grabWidget () 和 grabWindow () functions which creates a QPixmap and paints the given widget, or window, into it.
QPixmap 对象可以按值围绕传递由于 QPixmap 类使用隐式数据共享。更多信息,见 隐式数据共享 文档编制。 QPixmap 对象还可以被流化。
注意,像素图中的像素数据在内部,且由底层窗口系统管理。因为 QPixmap 是 QPaintDevice 子类, QPainter 可以用于在像素图中直接绘制。只可以访问像素透过 QPainter 函数或通过转换 QPixmap 到 QImage 。不管怎样, fill () 函数是可用的为采用给定颜色初始化整个像素图。
有函数能转换
QImage
and
QPixmap
。通常,
QImage
类用于加载图像文件,可选操纵图像数据,先于
QImage
对象被转换成
QPixmap
以展示在屏幕中。另外,若不期望操纵,可以直接将图像文件加载进
QPixmap
. On Windows, the
QPixmap
class also supports conversion between
HBITMAP
and
QPixmap
. On Symbian, the
QPixmap
class also supports conversion between CFbsBitmap and
QPixmap
.
QPixmap 提供可以用于获取像素图各种有关信息的一批函数。此外,还有几个函数启用像素图变换。
QPixmap 提供了几种读取图像文件的方式:可以加载文件当构造 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 提供了可用于获得像素图各种有关信息的一批函数:
| 可用函数 | |
|---|---|
| 几何体 | The size (), width () 和 height () 函数提供像素图大小的有关信息。 rect () 函数返回图像的封闭矩形。 |
| Alpha 组件 |
The
hasAlphaChannel
() returns true if the pixmap has a format that respects the alpha channel, otherwise returns false. The
hasAlpha
(),
setMask
() 和
mask
() 函数是传统的且不应使用。它们潜在非常慢。
The createHeuristicMask () 函数创建并返回 1-bpp 试探遮罩 (即 QBitmap ) 对于此像素图。它的工作是通过从一角选择颜色,然后从所有边缘开始去除相应颜色的像素。 createMaskFromColor () 函数创建并返回遮罩 (即 QBitmap ) 对于基于给定颜色的像素图而言。 |
| 低级信息 |
The
depth
() 函数返回像素图的深度。
defaultDepth
() 函数返回默认深度 (即:应用程序在给定屏幕上所使用的深度)。
The cacheKey () 函数返回内容的唯一标识数为 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 对象可以被转换成 QImage 使用 toImage () 函数。同样, QImage 可以被转换成 QPixmap 使用 fromImage ()。若操作过于昂贵,可以使用 QBitmap::fromImage () 代替。
In addition, on Windows, the QPixmap class supports conversion to and from HBITMAP: the toWinHBITMAP () function creates a HBITMAP equivalent to the QPixmap , based on the given HBitmapFormat , and returns the HBITMAP handle. The fromWinHBITMAP () 函数返回 QPixmap that is equivalent to the given bitmap which has the specified format. The QPixmap class also supports conversion to and from HICON: the toWinHICON () function creates a HICON equivalent to the QPixmap , and returns the HICON handle. The fromWinHICON () 函数返回 QPixmap that is equivalent to the given icon.
In addition, on Symbian, the QPixmap class supports conversion to and from CFbsBitmap: the toSymbianCFbsBitmap () function creates CFbsBitmap equivalent to the QPixmap , based on given mode and returns a CFbsBitmap object. The fromSymbianCFbsBitmap () 函数返回 QPixmap that is equivalent to the given bitmap and given mode.
QPixmap 支持用于创建新像素图 (是原始像素图的变换版本) 的许多函数:
The scaled (), scaledToWidth () 和 scaledToHeight () 函数返回像素图的比例缩放副本,而 copy () 函数创建 QPixmap 是原始的纯副本。
The transformed () 函数返回按给定变换矩阵和变换模式变换的像素图副本:在内部,调节变换矩阵以补偿不想要的平移,即 transformed () 返回包含原始像素图所有变换点的最小像素图。静态 trueMatrix () 函数返回用于变换像素图的实际矩阵。
注意: 当使用本机 X11 图形系统时,像素图变为无效当 QApplication 实例被销毁。
另请参阅 QBitmap , QImage , QImageReader ,和 QImageWriter .
Win32 only:
此枚举定义如何转换介于
HBITMAP
and
QPixmap
的履行。
警告: This enum is only available on Windows.
| 常量 | 值 | 描述 |
|---|---|---|
QPixmap::NoAlpha
|
0
|
The alpha channel is ignored and always treated as being set to fully opaque. This is preferred if the
HBITMAP
is used with standard GDI calls, such as
BitBlt()
.
|
QPixmap::PremultipliedAlpha
|
1
|
The
HBITMAP
is treated as having an alpha channel and premultiplied colors. This is preferred if the
HBITMAP
is accessed through the
AlphaBlend()
GDI function.
|
QPixmap::Alpha
|
2
|
The
HBITMAP
is treated as having a plain alpha channel. This is the preferred format if the
HBITMAP
is going to be used as an application icon or systray icon.
|
另请参阅 fromWinHBITMAP () 和 toWinHBITMAP ().
This enum type defines the share modes that are available when creating a QPixmap object from a raw X11 Pixmap handle.
| 常量 | 值 | 描述 |
|---|---|---|
QPixmap::ImplicitlyShared
|
0
|
This mode will cause the QPixmap object to create a copy of the internal data before it is modified, thus keeping the original X11 pixmap intact. |
QPixmap::ExplicitlyShared
|
1
|
In this mode, the pixmap data will not be copied before it is modified, which in effect will change the original X11 pixmap. |
警告: This enum is only used for X11 specific functions; using it is non-portable.
该枚举在 Qt 4.5 引入或被修改。
另请参阅 QPixmap::fromX11Pixmap ().
构造 null 像素图。
另请参阅 isNull ().
构造像素图采用给定 width and height 。若 width or height 为 0,构造 null 像素图。
警告: 这将创建 QPixmap 采用未初始化数据。调用 fill () 以合适颜色填充像素图先于绘制采用 QPainter .
另请参阅 isNull ().
从文件构造像素图采用给定 fileName 。若文件不存在 (或格式未知),像素图变为 null 像素图。
加载器试图读取像素图使用指定 format 。若 format 未指定 (默认),加载器会探针文件 Header (头) 以猜测文件格式。
文件名可以引用实际磁盘文件,或引用应用程序的某一嵌入资源。见 资源系统 概述,了解如何在应用程序可执行文件中嵌入图像及其它资源文件的细节。
若需要修改图像以拟合更低分辨率结果 (如:从 32 位转换成 8 位),使用 flags 来控制转换。
The fileName , format and flags 参数被传递给 load ()。这意味着数据在 fileName 未被编译成二进制。若 fileName 包含相对路径 (如:仅文件名),必须相对运行时工作目录查找相关文件。
另请参阅 读写图像文件 .
构造像素图从给定 xpm 数据,必须是有效 XPM 图像。
错误被默默忽略。
注意,通过使用不寻常声明稍微挤压 XPM 变量是可能的:
static const char * const start_xpm[]={ "16 15 8 1", "a c #cec6bd", ....
额外
const
使整个定义是稍微更高效的只读 (例如:当代码在共享库中时),且可 ROM 当应用程序存储在 ROM 中时。
构造像素图副本为给定 pixmap .
另请参阅 copy ().
这是重载函数。
构造像素图为给定 size .
警告: 这将创建 QPixmap 采用未初始化数据。调用 fill () 以合适颜色填充像素图先于绘制采用 QPainter .
销毁像素图。
返回的数字标识此 QPixmap 。截然不同的 QPixmap 对象只可以拥有相同缓存键,若它们引用相同内容。
cacheKey() 会改变,当像素图变更时。
替换此像素图的数据采用给定 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.
注意:此函数是 Qt 4.6 及更早版本的 Qt 3 支持的一部分。在 4.7 已提升为官方 API 状态以支持更新像素图图像,不用创建新的 QPixmap as fromImage () would.
该函数在 Qt 4.7 引入。
另请参阅 fromImage ().
返回像素图子集的深拷贝,指定通过给定 rectangle 。有关深拷贝的更多信息,见 隐式数据共享 文档编制。
若给定 rectangle 为空,拷贝整个图像。
另请参阅 operator= (), QPixmap (),和 像素图变换 .
这是重载函数。
返回像素图子集的深拷贝,指定通过矩形 QRect ( x , y , width , height ).
创建并返回此像素图的试探遮罩。
函数的工作是通过从一角选择颜色,然后从所有边缘开始去除相应颜色的像素。若 clipTight 为 true (默认),遮罩刚好足够大以覆盖像素;否则,遮罩 > 数据像素。
遮罩可能并不完美但应该合理,所以可以做的事情如下:
QPixmap myPixmap; myPixmap->setMask(myPixmap->createHeuristicMask());
此函数很慢,因为它涉及转换到/从 QImage ,及非通俗计算。
另请参阅 QImage::createHeuristicMask () 和 createMaskFromColor ().
创建并返回用于此像素图的遮罩基于给定 maskColor 。若 mode is Qt::MaskInColor ,与 maskColor 匹配的所有像素都将透明。若 mode is Qt::MaskOutColor ,与 maskColor 匹配的所有像素都将不透明。
此函数很慢,因为它涉及转换到/从 QImage .
另请参阅 createHeuristicMask () 和 QImage::createMaskFromColor ().
这是重载函数。
创建并返回用于此像素图的遮罩基于给定 maskColor . Same as calling createMaskFromColor (maskColor, Qt::MaskInColor )
另请参阅 createHeuristicMask () 和 QImage::createMaskFromColor ().
[static]
int
QPixmap::
defaultDepth
()
返回用于应用程序的默认像素图深度。
On Windows and Mac, the default depth is always 32. On X11 and embedded, the depth of the screen will be returned by this function.
另请参阅 depth (), QColormap::depth (),和 像素图信息 .
返回像素图的深度。
像素图深度又称 BPP (每像素位) 或像素图位平面。null 像素图拥有深度 0。
另请参阅 defaultDepth () 和 像素图信息 .
从共享像素图数据分离像素图。
像素图会被 Qt 自动分离,每当其内容即将改变时。这的完成是在几乎所有 QPixmap 成员函数修改像素图 ( fill (), fromImage (), load (),等),和在 QPainter::begin () 在像素图。
There are two exceptions in which detach() must be called explicitly, that is when calling the handle () 或 x11PictureHandle () function (only available on X11). Otherwise, any modifications done using system calls, will be performed on the shared data.
detach() 函数会立即返回,若仅仅存在一个引用 (或者,若像素图尚未被初始化)。
填充像素图采用给定 color .
此函数的效果未定义,当描绘像素图时。
另请参阅 像素图变换 .
Fills the pixmap with the widget 's background color or pixmap according to the given offset.
The QPoint offset defines a point in widget coordinates to which the pixmap's top-left pixel will be mapped to. This is only significant if the widget has a background pixmap; otherwise the pixmap will simply be filled with the background color of the widget.
这是重载函数。
Fills the pixmap with the widget 's background color or pixmap. The given point, ( x , y ), defines an offset in widget coordinates to which the pixmap's top-left pixel will be mapped to.
[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::
fromImageReader
(
QImageReader
*
imageReader
,
Qt::ImageConversionFlags
flags
= Qt::AutoColor)
创建 QPixmap 从图像直接读取自 imageReader 。 flags 自变量是按位 OR 的 Qt::ImageConversionFlags 。传递 0 为 flags 设置所有默认选项。
在某些系统,将图像直接读取到 QPixmap 可以使用更少内存相比读取 QImage 以转换它到 QPixmap .
另请参阅 fromImage (), toImage (),和 像素图转换 .
[static]
QPixmap
QPixmap::
fromMacCGImageRef
(
CGImageRef
image
)
返回 QPixmap 相当于给定 image .
警告: This function is only available on Mac OS X.
该函数在 Qt 4.2 引入。
另请参阅 toMacCGImageRef () 和 像素图转换 .
[static]
QPixmap
QPixmap::
fromSymbianCFbsBitmap
(
CFbsBitmap
*
bitmap
)
创建
QPixmap
从
CFbsBitmap
bitmap
. Internally this function will try to duplicate the bitmap handle instead of copying the data, however in scenarios where this is not possible the data will be copied. To be sure that
QPixmap
does not modify your original instance, you should make a copy of your
CFbsBitmap
before calling this function. If the CFbsBitmap is not valid this function will return a null
QPixmap
. For performance reasons it is recommended to use a
bitmap
with a display mode of EColor16MAP or EColor16MU whenever possible.
警告: This function is only available on Symbian OS.
该函数在 Qt 4.6 引入。
另请参阅 toSymbianCFbsBitmap () 和 像素图转换 .
[static]
QPixmap
QPixmap::
fromSymbianRSgImage
(
RSgImage
*
sgImage
)
返回 QPixmap that wraps given sgImage graphics resource. The data should be valid even when original RSgImage handle has been closed.
警告: This function is only available on Symbian OS.
该函数在 Qt 4.6 引入。
另请参阅 toSymbianRSgImage () 和 像素图转换 .
[static]
QPixmap
QPixmap::
fromWinHBITMAP
(
HBITMAP
bitmap
,
HBitmapFormat
format
= NoAlpha)
Win32 only: 返回 QPixmap 相当于给定 bitmap . The conversion is based on the specified format .
警告: This function is only available on Windows.
另请参阅 toWinHBITMAP () 和 像素图转换 .
[static]
QPixmap
QPixmap::
fromWinHICON
(
HICON
icon
)
Win32 only: 返回 QPixmap 相当于给定 icon .
警告: This function is only available on Windows.
该函数在 Qt 4.6 引入。
另请参阅 toWinHICON () 和 像素图转换 .
[static]
QPixmap
QPixmap::
fromX11Pixmap
(
Qt::HANDLE
pixmap
,
ShareMode
mode
= ImplicitlyShared)
创建 QPixmap from the native X11 Pixmap handle pixmap ,使用 mode as the share mode. The default share mode is QPixmap::ImplicitlyShared , which means that a copy of the pixmap is made if someone tries to modify it by e.g. drawing onto it.
QPixmap does not 拥有所有权对于 pixmap handle, and have to be deleted by the user.
警告: This function is X11 specific; using it is non-portable.
该函数在 Qt 4.5 引入。
另请参阅 QPixmap::ShareMode .
[static]
QPixmap
QPixmap::
grabWidget
(
QWidget
*
widget
, const
QRect
&
rectangle
)
Creates a pixmap and paints the given widget , restricted by the given rectangle , in it. If the widget has any children, then they are also painted in the appropriate positions.
If no rectangle is specified (the default) the entire widget is painted.
若 widget is 0, the specified rectangle doesn't overlap the widget's rectangle, or an error occurs, the function will return a null QPixmap . If the rectangle is a superset of the given widget , the areas outside the widget are covered with the widget's background.
This function actually asks widget to paint itself (and its children to paint themselves) by calling paintEvent() with painter redirection turned on. But QPixmap 还提供 grabWindow () function which is a bit faster by grabbing pixels directly off the screen. In addition, if there are overlaying windows, grabWindow (), unlike grabWidget(), will see them.
警告: Do not grab a widget from its QWidget::paintEvent (). However, it is safe to grab a widget from another widget's paintEvent() .
另请参阅 grabWindow ().
[static]
QPixmap
QPixmap::
grabWidget
(
QWidget
*
widget
,
int
x
= 0,
int
y
= 0,
int
width
= -1,
int
height
= -1)
这是重载函数。
Creates a pixmap and paints the given widget , restricted by QRect ( x , y , width , height ), in it.
警告: Do not grab a widget from its QWidget::paintEvent (). However, it is safe to grab a widget from another widget's paintEvent() .
[static]
QPixmap
QPixmap::
grabWindow
(
WId
window
,
int
x
= 0,
int
y
= 0,
int
width
= -1,
int
height
= -1)
创建并返回通过抓取内容构造的像素图,为给定 window 限定通过 QRect ( x , y , width , height ).
自变量 ( x , y ) 指定窗口偏移,而 ( width , height ) 指定要拷贝的区域。若 width 为负,函数将拷贝一切直到窗口右边界。若 height 为负,函数将拷贝一切直到窗口底部。
窗口系统标识符 (
WId
) 可以检索使用
QWidget::winId
() 函数。基本原理是使用窗口标识符而非
QWidget
,允许抓取不属于应用程序的窗口、窗口系统框架、等等。
grabWindow() 函数从屏幕而不是窗口抓取像素,即:若抓取的窗口之上有另一窗口的部分或全部,也会获取上面窗口的像素。通常,鼠标光标不被抓取。
注意:在 X11 若给定 window 没有如根窗口的相同深度,且另一窗口部分 (或完全) 遮盖抓取,将 not 获取上方窗口的像素。像素图遮盖区域的内容将是未定义和未初始化的。
在 Windows、Vista 及更高版本抓取分层窗口,创建通过设置 Qt::WA_TranslucentBackground 属性, 会不工作。相反,抓取桌面 Widget 应该工作。
警告: 一般而言,抓住屏幕外区域是不安全的。这取决于底层窗口系统。
另请参阅 grabWidget () 和 屏幕截图范例 .
Returns the pixmap's handle to the device context.
Note that, since QPixmap make use of 隐式数据共享 , detach () function must be called explicitly to ensure that only this pixmap's data is modified if the pixmap data is shared.
警告: This function is X11 specific; using it is non-portable.
警告: Since 4.8, pixmaps do not have an X11 handle unless created with fromX11Pixmap() , or if the native graphics system is explicitly enabled.
另请参阅 detach () 和 QApplication::setGraphicsSystem ().
Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false.
另请参阅 hasAlphaChannel () 和 mask ().
Returns true if the pixmap has a format that respects the alpha channel, otherwise returns false.
另请参阅 hasAlpha ().
返回像素图的高度。
Returns true if this is a null pixmap; otherwise returns false.
null 像素图拥有 0 宽度,0 高度,且没有内容。无法在 null 像素图中绘制。
Returns true if this is a QBitmap ;否则返回 false。
从文件加载像素图采用给定 fileName . Returns true if the pixmap was successfully loaded; otherwise returns false.
加载器试图读取像素图使用指定 format 。若 format 未指定 (默认),加载器会探针文件 Header (头) 以猜测文件格式。
文件名可以引用实际磁盘文件,或引用应用程序的某一嵌入资源。见 资源系统 概述了解如何在应用程序可执行文件中嵌入像素图及其它资源文件的细节。
若需要修改数据以拟合较低分辨率的结果 (如:从 32 位转换到 8 位),使用 flags 来控制转换。
注意:QPixmap 会被自动添加到 QPixmapCache 当从文件加载时;使用键在内部,且无法获得。
另请参阅 loadFromData () 和 读写图像文件 .
加载像素图从 len 首字节的给定二进制 data . Returns true if the pixmap was loaded successfully; otherwise returns false.
加载器试图读取像素图使用指定 format 。若 format 未指定 (默认),加载器会探针文件 Header (头) 以猜测文件格式。
若需要修改数据以拟合较低分辨率的结果 (如:从 32 位转换到 8 位),使用 flags 来控制转换。
这是重载函数。
加载像素图从二进制 data 使用指定 format 和转换 flags .
从像素图的 Alpha 通道提取位图遮罩。
警告: 这潜在是很昂贵的操作。像素图遮罩是从像素数据动态提取的。
返回像素图的封闭矩形。
另请参阅 像素图信息 .
把像素图保存到文件,采用给定 fileName 使用指定图像文件 format and quality factor. Returns true if successful; otherwise returns false.
The quality 因子必须在 [0,100] 范围内或为 -1。指定 0 以获得小压缩文件,100 为大的未压缩文件,和 -1 使用默认设置。
若 format 为 0,图像格式将选取自 fileName 的后缀。
另请参阅 读写图像文件 .
这是重载函数。
此函数写入 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
比例缩放像素图到给定 size ,使用宽高比和变换模式,指定通过 aspectRatioMode and transformMode .
若给定 size 为空,此函数返回 null 像素图。
In some cases it can be more beneficial to draw the pixmap to a painter with a scale set rather than scaling the pixmap. This is the case when the painter is for instance based on OpenGL or when the scale factor changes rapidly.
这是重载函数。
返回的像素图副本被比例缩放到矩形采用给定 width and height 根据给定 aspectRatioMode and transformMode .
若 width 或 height 为 0 或负值,此函数返回 null 像素图。
返回图像的比例缩放副本。返回图像被比例缩放到给定 height 使用指定变换 mode 。 自动计算像素图宽度,以便维持像素图宽高比。
若 height 为 0 或负数,返回 null 像素图。
返回图像的比例缩放副本。返回图像被比例缩放到给定 width 使用指定变换 mode 。自动计算像素图高度,以便维持像素图宽高比。
若 width 为 0 或负数,返回 null 像素图。
此方便函数相当于调用 QPixmap::scroll( dx , dy , QRect ( x , y , width , height ), exposed ).
该函数在 Qt 4.6 引入。
另请参阅 QWidget::scroll () 和 QGraphicsItem::scroll ().
卷动区域 rect 为此像素图按 ( dx , dy )。暴露区域保持不变。可以可选将指针传递给空 QRegion 以获取区域 exposed 通过卷动操作。
QPixmap pixmap("background.png"); QRegion exposed; pixmap.scroll(10, 10, pixmap.rect(), &exposed);
无法卷动,当像素图中有活动描绘器时。
该函数在 Qt 4.6 引入。
另请参阅 QWidget::scroll () 和 QGraphicsItem::scroll ().
设置遮罩位图。
此函数合并 mask 采用像素图的 Alpha 通道。遮罩像素值 1 意味着像素图的像素无变化;值 0 意味着像素透明。遮罩必须拥有如此像素图的相同大小。
设置 null 遮罩将重置遮罩,使先前透明像素变为黑色。此函数的效果未定义,当描绘像素图时。
警告: 这是潜在的昂贵操作。
另请参阅 mask (), 像素图变换 ,和 QBitmap .
返回像素图尺寸。
另请参阅 width (), height (),和 像素图信息 .
交换像素图 other 与此像素图。此操作非常快且从不失败。
该函数在 Qt 4.8 引入。
将像素图转换成 QImage 。返回 null 图像,若转换失败。
若像素图拥有 1 位深度,返回图像也将是 1 位深。具有更多位的图像将按底层系统所表示的密切格式返回。通常,这会是 QImage::Format_ARGB32_Premultiplied 对于具有 Alpha 的像素图和 QImage::Format_RGB32 or QImage::Format_RGB16 对于没有 Alpha 的像素图。
注意:目前,单色图像忽略 Alpha 遮罩。
创建
CGImageRef
equivalent to the
QPixmap
。返回
CGImageRef
句柄。
It is the caller's responsibility to release the
CGImageRef
数据在使用后。
警告: This function is only available on Mac OS X.
该函数在 Qt 4.2 引入。
另请参阅 fromMacCGImageRef ().
创建
CFbsBitmap
that is equivalent to the
QPixmap
. Internally this function will try to duplicate the handle instead of copying the data, however in scenarios where this is not possible the data will be copied. If the creation fails or the pixmap is null, then this function returns 0.
It is the caller's responsibility to release the
CFbsBitmap
data after use either by deleting the bitmap or calling
Reset()
.
警告: On S60 3.1 and S60 3.2, semi-transparent pixmaps are always copied and not duplicated.
警告: This function is only available on Symbian OS.
该函数在 Qt 4.6 引入。
另请参阅 fromSymbianCFbsBitmap ().
返回
RSgImage
that is equivalent to the
QPixmap
by copying the data.
It is the caller's responsibility to close/delete the
RSgImage
after use.
警告: This function is only available on Symbian OS.
该函数在 Qt 4.6 引入。
另请参阅 fromSymbianRSgImage ().
Win32 only:
创建
HBITMAP
equivalent to the
QPixmap
, based on the given
format
。返回
HBITMAP
句柄。
调用者负责释放
HBITMAP
数据在使用后。
警告: This function is only available on Windows.
另请参阅 fromWinHBITMAP () 和 像素图转换 .
Win32 only:
创建
HICON
equivalent to the
QPixmap
。返回
HICON
句柄。
调用者负责释放
HICON
数据在使用后。
警告: This function is only available on Windows.
该函数在 Qt 4.6 引入。
另请参阅 fromWinHICON () 和 像素图转换 .
返回像素图副本的变换是使用给定变换 transform 和变换 mode 。原始像素图不改变。
变换 transform 在内部调节以补偿不想要的平移;即,产生像素图是包含原始像素图所有变换点的最小像素图。使用 trueMatrix () 函数能检索用于变换像素图的实际矩阵。
此函数很慢,因为它涉及变换到 QImage ,非通俗计算及变换回 QPixmap .
另请参阅 trueMatrix () 和 像素图变换 .
这是重载函数。
此方便函数加载 matrix 成 QTransform 并调用重载函数。
[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
)
这是重载函数。
此方便函数加载矩阵 m 成 QTransform 并调用重载函数采用 QTransform 和宽度 w 和高度 h .
返回像素图的宽度。
X11 only: Returns information about the configuration of the X display used by the screen to which the pixmap currently belongs.
警告: This function is only available on X11.
另请参阅 像素图信息 .
X11 only: Returns the X11 Picture handle of the pixmap for XRender support.
This function will return 0 if XRender support is not compiled into Qt, if the XRender extension is not supported on the X11 display, or if the handle could not be created. Use of this function is not portable.
警告: This function is only available on X11.
另请参阅 像素图信息 .
将像素图返回为 QVariant .
Returns true if this is a null pixmap; otherwise returns false.
另请参阅 isNull ().
赋值给定 pixmap 到此像素图并返回此像素图的引用。
写入给定 pixmap 到给定 stream 作为 PNG 图像。注意:将流写入文件不会产生有效图像文件。
另请参阅 QPixmap::save () 和 序列化 Qt 数据类型 .
读取图像从给定 stream 进给定 pixmap .
另请参阅 QPixmap::load () 和 序列化 Qt 数据类型 .