![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtGui More...
#include <qbitmap.h>
Public Types | |
typedef QExplicitlySharedDataPointer< QPlatformPixmap > | DataPtr |
![]() | |
typedef QExplicitlySharedDataPointer< QPlatformPixmap > | DataPtr |
![]() | |
enum | PaintDeviceMetric { PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM , PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY , PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled } |
Public Member Functions | |
QBitmap () | |
Constructs a null bitmap. | |
QBitmap (int w, int h) | |
Constructs a bitmap with the given width and height. | |
QBitmap (const QSize &) | |
QBitmap (const QString &fileName, const char *format=nullptr) | |
Constructs a bitmap from the file specified by the given fileName. | |
~QBitmap () override | |
void | swap (QBitmap &other) |
operator QVariant () const | |
Returns the bitmap as a QVariant. | |
void | clear () |
Clears the bitmap, setting all its bits to Qt::color0. | |
QBitmap | transformed (const QTransform &matrix) const |
Returns a copy of this bitmap, transformed according to the given matrix. | |
![]() | |
QPixmap () | |
Constructs a null pixmap. | |
QPixmap (QPlatformPixmap *data) | |
QPixmap (int w, int h) | |
Constructs a pixmap with the given width and height. | |
QPixmap (const QSize &) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Constructs a pixmap of the given size. | |
QPixmap (const QString &fileName, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor) | |
Constructs a pixmap from the file with the given fileName. | |
QPixmap (const char *const xpm[]) | |
Constructs a pixmap from the given xpm data, which must be a valid XPM image. | |
QPixmap (const QPixmap &) | |
Constructs a pixmap that is a copy of the given pixmap. | |
QPixmap (QPixmap &&other) noexcept | |
Move-constructs a QPixmap instance from other. | |
~QPixmap () | |
Destroys the pixmap. | |
QPixmap & | operator= (const QPixmap &) |
Assigns the given pixmap to this pixmap and returns a reference to this pixmap. | |
void | swap (QPixmap &other) noexcept |
bool | operator== (const QPixmap &) const =delete |
bool | operator!= (const QPixmap &) const =delete |
operator QVariant () const | |
Returns the pixmap as a QVariant. | |
bool | isNull () const |
Returns true if this is a null pixmap; otherwise returns false . | |
int | devType () const override |
int | width () const |
Returns the width of the pixmap. | |
int | height () const |
Returns the height of the pixmap. | |
QSize | size () const |
Returns the size of the pixmap. | |
QRect | rect () const |
Returns the pixmap's enclosing rectangle. | |
int | depth () const |
Returns the depth of the pixmap. | |
void | fill (const QColor &fillColor=Qt::white) |
Fills the pixmap with the given color. | |
QBitmap | mask () const |
Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false . | |
void | setMask (const QBitmap &) |
Sets a mask bitmap. | |
qreal | devicePixelRatio () const |
Returns the device pixel ratio for the pixmap. | |
void | setDevicePixelRatio (qreal scaleFactor) |
Sets the device pixel ratio for the pixmap. | |
QSizeF | deviceIndependentSize () const |
Returns the size of the pixmap in device independent pixels. | |
bool | hasAlpha () const |
bool | hasAlphaChannel () const |
QBitmap | createHeuristicMask (bool clipTight=true) const |
Creates and returns a heuristic mask for this pixmap. | |
QBitmap | createMaskFromColor (const QColor &maskColor, Qt::MaskMode mode=Qt::MaskInColor) const |
Creates and returns a mask for this pixmap based on the given maskColor. | |
QPixmap | scaled (int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const |
QPixmap | scaled (const QSize &s, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const |
QPixmap | scaledToWidth (int w, Qt::TransformationMode mode=Qt::FastTransformation) const |
Returns a scaled copy of the image. | |
QPixmap | scaledToHeight (int h, Qt::TransformationMode mode=Qt::FastTransformation) const |
Returns a scaled copy of the image. | |
QPixmap | transformed (const QTransform &, Qt::TransformationMode mode=Qt::FastTransformation) const |
QImage | toImage () const |
Converts the pixmap to a QImage. | |
bool | load (const QString &fileName, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor) |
Loads a pixmap from the file with the given fileName. | |
bool | loadFromData (const uchar *buf, uint len, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor) |
Loads a pixmap from the len first bytes of the given binary data. | |
bool | loadFromData (const QByteArray &data, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Loads a pixmap from the binary data using the specified format and conversion flags. | |
bool | save (const QString &fileName, const char *format=nullptr, int quality=-1) const |
Saves the pixmap to the file with the given fileName using the specified image file format and quality factor. | |
bool | save (QIODevice *device, const char *format=nullptr, int quality=-1) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function writes a QPixmap to the given device using the specified image file format and quality factor. | |
bool | convertFromImage (const QImage &img, Qt::ImageConversionFlags flags=Qt::AutoColor) |
Replaces this pixmap's data with the given image using the specified flags to control the conversion. | |
QPixmap | copy (int x, int y, int width, int height) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x, y, width, height). | |
QPixmap | copy (const QRect &rect=QRect()) const |
Returns a deep copy of the subset of the pixmap that is specified by the given rectangle. | |
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) |
qint64 | cacheKey () const |
Returns a number that identifies this QPixmap. | |
bool | isDetached () const |
void | detach () |
Detaches the pixmap from shared pixmap data. | |
bool | isQBitmap () const |
Returns true if this is a QBitmap; otherwise returns false . | |
QPaintEngine * | paintEngine () const override |
bool | operator! () const |
Returns true if this is a null pixmap; otherwise returns false . | |
QPlatformPixmap * | handle () const |
DataPtr & | data_ptr () |
![]() | |
virtual | ~QPaintDevice () |
virtual int | devType () const |
bool | paintingActive () const |
virtual QPaintEngine * | paintEngine () const =0 |
int | width () const |
int | height () const |
int | widthMM () const |
int | heightMM () const |
int | logicalDpiX () const |
int | logicalDpiY () const |
int | physicalDpiX () const |
int | physicalDpiY () const |
qreal | devicePixelRatio () const |
qreal | devicePixelRatioF () const |
int | colorCount () const |
int | depth () const |
Static Public Member Functions | |
static QBitmap | fromImage (const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor) |
Returns a copy of the given image converted to a bitmap using the specified image conversion flags. | |
static QBitmap | fromImage (QImage &&image, Qt::ImageConversionFlags flags=Qt::AutoColor) |
static QBitmap | fromData (const QSize &size, const uchar *bits, QImage::Format monoFormat=QImage::Format_MonoLSB) |
Constructs a bitmap with the given size, and sets the contents to the bits supplied. | |
static QBitmap | fromPixmap (const QPixmap &pixmap) |
Returns a copy of the given pixmap converted to a bitmap. | |
![]() | |
static int | defaultDepth () |
static QTransform | trueMatrix (const QTransform &m, int w, int h) |
Returns the actual matrix used for transforming a pixmap with the given width, height and matrix. | |
static QPixmap | fromImage (const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor) |
Converts the given image to a pixmap using the specified flags to control the conversion. | |
static QPixmap | fromImageReader (QImageReader *imageReader, Qt::ImageConversionFlags flags=Qt::AutoColor) |
Create a QPixmap from an image read directly from an imageReader. | |
static QPixmap | fromImage (QImage &&image, Qt::ImageConversionFlags flags=Qt::AutoColor) |
![]() | |
static qreal | devicePixelRatioFScale () |
Additional Inherited Members | |
![]() | |
int | metric (PaintDeviceMetric) const override |
![]() | |
QPaintDevice () noexcept | |
virtual int | metric (PaintDeviceMetric metric) const |
virtual void | initPainter (QPainter *painter) const |
virtual QPaintDevice * | redirected (QPoint *offset) const |
virtual QPainter * | sharedPainter () const |
![]() | |
static QPixmap | fromImageInPlace (QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor) |
![]() | |
ushort | painters |
![]() | |
QDataStream & | operator<< (QDataStream &stream, const QPixmap &pixmap) |
Writes the given pixmap to the given stream as a PNG image. | |
QDataStream & | operator>> (QDataStream &stream, QPixmap &pixmap) |
Reads an image from the given stream into the given pixmap. | |
\inmodule QtGui
The QBitmap class provides monochrome (1-bit depth) pixmaps.
The QBitmap class is a monochrome off-screen paint device used mainly for creating custom QCursor and QBrush objects, constructing QRegion objects, and for setting masks for pixmaps and widgets.
QBitmap is a QPixmap subclass ensuring a depth of 1, except for null objects which have a depth of 0. If a pixmap with a depth greater than 1 is assigned to a bitmap, the bitmap will be dithered automatically.
Use the QColor objects Qt::color0 and Qt::color1 when drawing on a QBitmap object (or a QPixmap object with depth 1).
Painting with Qt::color0 sets the bitmap bits to 0, and painting with Qt::color1 sets the bits to 1. For a bitmap, 0-bits indicate background (or transparent pixels) and 1-bits indicate foreground (or opaque pixels). Use the clear() function to set all the bits to Qt::color0. Note that using the Qt::black and Qt::white colors make no sense because the QColor::pixel() value is not necessarily 0 for black and 1 for white.
The QBitmap class provides the transformed() function returning a transformed copy of the bitmap; use the QTransform argument to translate, scale, shear, and rotate the bitmap. In addition, QBitmap provides the static fromData() function which returns a bitmap constructed from the given uchar
data, and the static fromImage() function returning a converted copy of a QImage object.
Just like the QPixmap class, QBitmap is optimized by the use of implicit data sharing. For more information, see the \l {Implicit Data Sharing} documentation.
QBitmap::QBitmap | ( | ) |
Constructs a null bitmap.
Definition at line 70 of file qbitmap.cpp.
Referenced by fromImage(), fromImage(), and fromPixmap().
QBitmap::QBitmap | ( | int | width, |
int | height | ||
) |
Constructs a bitmap with the given width and height.
The pixels inside are uninitialized.
Definition at line 83 of file qbitmap.cpp.
|
explicit |
Constructs a bitmap with the given size. The pixels in the bitmap are uninitialized.
Definition at line 96 of file qbitmap.cpp.
Constructs a bitmap from the file specified by the given fileName.
If the file does not exist, or has an unknown format, the bitmap becomes a null bitmap.
The fileName and format parameters are passed on to the QPixmap::load() function. If the file format uses more than 1 bit per pixel, the resulting bitmap will be dithered automatically.
Definition at line 124 of file qbitmap.cpp.
References fileName, QPixmap::load(), and Qt::MonoOnly.
|
overridedefault |
This dtor must stay empty until Qt 7 (was inline until 6.2).
|
inline |
Clears the bitmap, setting all its bits to Qt::color0.
Definition at line 33 of file qbitmap.h.
References Qt::color0, and QPixmap::fill().
|
static |
Constructs a bitmap with the given size, and sets the contents to the bits supplied.
The bitmap data has to be byte aligned and provided in the bit order specified by monoFormat. The mono format must be either QImage::Format_Mono or QImage::Format_MonoLSB. Use QImage::Format_Mono to specify data on the XBM format.
Definition at line 207 of file qbitmap.cpp.
References Qt::color0, Qt::color1, QImage::Format_Mono, QImage::Format_MonoLSB, fromImage(), Q_ASSERT, and rgb.
Referenced by createPixmapCursorFromData(), qHasPixmapTexture(), QSvgPaintEngine::savePatternMask(), and QX11PlatformPixmap::transformed().
|
static |
Returns a copy of the given image converted to a bitmap using the specified image conversion flags.
Definition at line 170 of file qbitmap.cpp.
References QBitmap(), QImage::Format_MonoLSB, and makeBitmap().
Referenced by QCursor::QCursor(), QPixmap::QPixmap(), QGraphicsItem::boundingRegion(), QPixmap::createHeuristicMask(), QPixmap::createMaskFromColor(), fromData(), QX11PlatformPixmap::fromImage(), fromPixmap(), QPlatformPixmap::mask(), QX11PlatformPixmap::mask(), qt_patternForAlpha(), QMacStyle::styleHint(), and QQC2_NAMESPACE::QMacStyle::styleHint().
|
static |
Returns a copy of the given image converted to a bitmap using the specified image conversion flags.
Definition at line 187 of file qbitmap.cpp.
References QBitmap(), QImage::Format_MonoLSB, and makeBitmap().
Returns a copy of the given pixmap converted to a bitmap.
If the pixmap has a depth greater than 1, the resulting bitmap will be dithered automatically.
Definition at line 234 of file qbitmap.cpp.
References QBitmap(), fromImage(), and pixmap.
Referenced by makeBitmap(), QShapedPixmapWindow::setPixmap(), and transformed().
QBitmap::operator QVariant | ( | ) | const |
Returns the bitmap as a QVariant.
Definition at line 141 of file qbitmap.cpp.
References QVariant::fromValue().
Swaps bitmap other with this bitmap. This operation is very fast and never fails.
Definition at line 30 of file qbitmap.h.
References other(), and QPixmap::swap().
QBitmap QBitmap::transformed | ( | const QTransform & | matrix | ) | const |
Returns a copy of this bitmap, transformed according to the given matrix.
Definition at line 291 of file qbitmap.cpp.
References fromPixmap(), and QPixmap::transformed().
Referenced by QX11PlatformPixmap::transformed().