Qt 4.0: QBitmap Class Reference

|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QBitmap Class Reference
[QtGui module]

The QBitmap class provides monochrome (1-bit depth) pixmaps. More...

    #include <QBitmap>

Inherits QPixmap.

- List of all members, including inherited members
- Qt 3 support members

### Public Functions

- QBitmap ()
- QBitmap ( const QPixmap & pixmap )
- QBitmap ( int width, int height )
- QBitmap ( const QString & fileName, const char * format = 0 )
- QBitmap ( const QSize & size )
- ~QBitmap ()
- void clear ()
- QBitmap transformed ( const QMatrix & matrix ) const
- operator QVariant () const
- QBitmap & operator= ( const QPixmap & pixmap )

- 39 public functions inherited from QPixmap
- 10 public functions inherited from QPaintDevice

### Static Public Members

- QBitmap fromData ( const QSize & size, const uchar * bits, QImage::Format monoFormat = QImage::Format_MonoLSB )
- QBitmap fromImage ( const QImage & image, Qt::ImageConversionFlags flags = Qt::AutoColor )

- 7 static public members inherited from QPixmap

## Detailed Description

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, settings masks for pixmaps and widgets, and for QRegion.

A QBitmap is a QPixmap with a depth of 1. If a pixmap with a depth greater than 1 is assigned to a bitmap, the bitmap will be dithered automatically. A QBitmap is guaranteed to always have the depth 1, unless it is null since null pixmaps have depth 0.

When drawing in a QBitmap (or QPixmap with depth 1), we recommend using the QColor objects Qt::color0 and Qt::color1. 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). 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 can be transformed (translated, scaled, sheared, and rotated) using transform().

Just like the QPixmap class, QBitmap is optimized by the use of implicit sharing, so it is very efficient to pass QBitmap objects as arguments.

See also QPixmap, QPainter::drawPixmap(), bitBlt(), and Shared Classes.

## Member Function Documentation

### QBitmap::QBitmap ()

Constructs a null bitmap.

See also QPixmap::isNull().

### QBitmap::QBitmap ( const QPixmap & pixmap )

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

Dithering will be performed if the pixmap has a QPixmap::depth() greater than 1.

### QBitmap::QBitmap ( int width, int height )

Constructs a bitmap with the given width and height. The pixels inside are uninitialized.

### QBitmap::QBitmap ( const QString & fileName, const char * format = 0 )

Constructs a bitmap from the file referred to by fileName. If the file does not exist, or is of an unknown format, the bitmap becomes a null bitmap.

The parameters fileName and format are passed on to QPixmap::load(). Dithering will be performed if the file format uses more than 1 bit per pixel.

See also QPixmap::isNull(), QPixmap::load(), QPixmap::loadFromData(), QPixmap::save(), and QImageReader::imageFormat().

### QBitmap::QBitmap ( const QSize & size )

Constructs a bitmap with the given size.

The pixels in the bitmap are uninitialized.

### QBitmap::~QBitmap ()

Destroys the bitmap.

### void QBitmap::clear ()

Clear the bitmap to Qt::color0.

### QBitmap QBitmap::fromData ( const QSize & size, const uchar * bits, QImage::Format monoFormat = QImage::Format_MonoLSB ) `[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 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.

### QBitmap QBitmap::fromImage ( const QImage & image, Qt::ImageConversionFlags flags = Qt::AutoColor ) `[static]`

Returns a copy of the given image converted to a bitmap using the image conversion flags specified by flags.

### QBitmap QBitmap::transformed ( const QMatrix & matrix ) const

Returns a transformed copy of this bitmap using the matrix given.

This function does exactly the same as QPixmap::transform(), except that it returns a QBitmap instead of a QPixmap.

See also QPixmap::transformed().

### QBitmap::operator QVariant () const

Returns the bitmap as a QVariant.

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

Assigns the pixmap to this bitmap and returns a reference to it.

Dithering will be performed if the pixmap has a QPixmap::depth() greater than 1.