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 數據類型 .