QBitmap Class
QBitmap 类提供单色(1 位深度)像素图。更多
头文件: | #include <QBitmap> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
继承: | QPixmap |
- 所有成员(包括继承成员)的列表
- 已废弃成员
- QBitmap 属于绘制类和隐式共享类。
公共函数
QBitmap() | |
QBitmap(const QSize &size) | |
QBitmap(const QString &fileName, const char *format = nullptr) | |
QBitmap(int width, int height) | |
void | clear() |
void | swap(QBitmap &other) |
QBitmap | transformed(const QTransform &matrix) const |
QVariant | operator QVariant() const |
静态公共成员
QBitmap | fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat = QImage::Format_MonoLSB) |
QBitmap | fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor) |
QBitmap | fromImage(QImage &&image, Qt::ImageConversionFlags flags = Qt::AutoColor) |
(since 6.0) QBitmap | fromPixmap(const QPixmap &pixmap) |
详细描述
QBitmap 类是一种单色离屏绘制设备,主要用于创建自定义QCursor 和QBrush 对象、构建QRegion 对象以及为像素图和部件设置遮罩。
QBitmap 是QPixmap 的子类,可确保深度为 1,但深度为 0 的空对象除外。如果将深度大于 1 的像素图分配给位图,位图将自动抖动。
在 QBitmap 对象(或深度为 1 的QPixmap 对象)上绘图时,请使用QColor 对象Qt::color0 和Qt::color1 。
使用Qt::color0 绘制时会将位图位设置为 0,而使用Qt::color1 绘制时会将位设置为 1。对于位图,0 位表示背景(或透明像素),1 位表示前景(或不透明像素)。使用clear() 函数可将所有位设置为Qt::color0 。请注意,使用Qt::black 和Qt::white 颜色没有意义,因为 QColor::pixel() 值并不一定是黑色为 0,白色为 1。
QBitmap 类提供了返回位图变换副本的transformed() 函数;使用QTransform 参数可对位图进行平移、缩放、剪切和旋转。此外,QBitmap 还提供静态fromData() 函数和静态fromImage() 函数,前者返回由给定的uchar
数据构建的位图,后者返回QImage 对象的转换副本。
另请参阅 QPixmap,QImage,QImageReader 和QImageWriter 。
成员函数文档
QBitmap::QBitmap()
构造一个空位图。
另请参阅 QPixmap::isNull()。
[explicit]
QBitmap::QBitmap(const QSize &size)
用给定的size 构建一个位图。位图中的像素未初始化。
另请参阅 clear().
[explicit]
QBitmap::QBitmap(const QString &fileName, const char *format = nullptr)
用fileName 指定的文件构建位图。如果文件不存在或格式未知,位图将变为空位图。
fileName 和format 参数将传递给QPixmap::load() 函数。如果文件格式中每个像素使用超过 1 位,生成的位图将自动抖动。
另请参阅 QPixmap::isNull() 和QImageReader::imageFormat()。
QBitmap::QBitmap(int width, int height)
用给定的width 和height 构建一个位图。其中的像素未初始化。
另请参阅 clear().
void QBitmap::clear()
清除位图,将其所有位设置为Qt::color0 。
[static]
QBitmap QBitmap::fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat = QImage::Format_MonoLSB)
使用给定的size 构建位图,并将其内容设置为所提供的bits 。
位图数据必须按字节对齐,并以monoFormat 指定的位顺序提供。单声道格式必须是QImage::Format_Mono 或QImage::Format_MonoLSB 。使用QImage::Format_Mono 指定 XBM 格式的数据。
另请参阅 fromImage() 。
[static]
QBitmap QBitmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor)
返回使用指定图像转换flags 转换为位图的给定image 的副本。
另请参阅 fromData()。
[static]
QBitmap QBitmap::fromImage(QImage &&image, Qt::ImageConversionFlags flags = Qt::AutoColor)
这是一个重载函数。
返回使用指定图像转换flags 转换为位图的给定image 的副本。
另请参阅 fromData() 。
[static, since 6.0]
QBitmap QBitmap::fromPixmap(const QPixmap &pixmap)
返回将给定pixmap 转换为位图的副本。
如果像素图的深度大于 1,生成的位图将自动抖动。
此函数在 Qt 6.0 中引入。
另请参阅 QPixmap::depth()。
void QBitmap::swap(QBitmap &other)
将该位图与other 互换。该操作速度非常快,从未出现过故障。
QBitmap QBitmap::transformed(const QTransform &matrix) const
根据给定的matrix 返回该位图的副本。
另请参阅 QPixmap::transformed()。
QVariant QBitmap::operator QVariant() const
以QVariant 的形式返回位图。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.