Qt 4.0: Qt 3 Support Members for QImage

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

# Qt 3 Support Members for QImage

The following class members are part of the Qt 3 support layer. They are provided to help you port old code to Qt 4. We advise against using them in new code.

- QImage class reference

### Public Functions

- QImage ( int w, int h, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )
- QImage ( const QSize & size, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )
- QImage ( uchar * data, int w, int h, int depth, const QRgb * colortable, int numColors, Endian bitOrder )
- QImage ( uchar * data, int w, int h, int depth, int bpl, const QRgb * colortable, int numColors, Endian bitOrder )
- QImage ( const QByteArray & data )
- Endian bitOrder () const
- QImage convertBitOrder ( Endian bitOrder ) const
- QImage convertDepth ( int depth, Qt::ImageConversionFlags flags = Qt::AutoColor ) const
- QImage convertDepthWithPalette ( int d, QRgb * palette, int palette_count, Qt::ImageConversionFlags flags = Qt::AutoColor ) const
- QImage copy ( int x, int y, int w, int h, Qt::ImageConversionFlags flags ) const
- QImage copy ( const QRect & rect, Qt::ImageConversionFlags flags ) const
- bool create ( int width, int height, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )
- bool create ( const QSize & size, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )
- bool hasAlphaBuffer () const
- void invertPixels ( bool invertAlpha )
- uchar ** jumpTable ()
- const uchar * const * jumpTable () const
- QImage mirror ( bool horizontal = false, bool vertical = true ) const
- void reset ()
- QImage scaleHeight ( int h ) const
- QImage scaleWidth ( int w ) const
- void setAlphaBuffer ( bool enable )
- QImage smoothScale ( int width, int height, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio ) const
- QImage smoothScale ( const QSize & size, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio ) const
- QImage swapRGB () const
- QImage xForm ( const QMatrix & matrix ) const

- 8 public functions inherited from QPaintDevice

### Static Public Members

- Endian systemBitOrder ()
- Endian systemByteOrder ()

- 13 static public members inherited from QPaintDevice

### Related Non-Members

- void bitBlt ( QImage * dst, int dx, int dy, const QImage * src, int sx = 0, int sy = 0, int sw = -1, int sh = -1, Qt::ImageConversionFlags flags = Qt::AutoColor )

## Member Function Documentation

### QImage::QImage ( int w, int h, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )

Constructs an image with w width, h height, depth bits per pixel, numColors colors and bit order bitOrder.

Using this constructor is the same as first constructing a null image and then calling the create() function.

See also create().

### QImage::QImage ( const QSize & size, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )

Constructs an image with size size pixels, depth depth bits, numColors and bitOrder endianness.

Using this constructor is the same as first constructing a null image and then calling the create() function.

See also create().

### QImage::QImage ( uchar * data, int w, int h, int depth, const QRgb * colortable, int numColors, Endian bitOrder )

Constructs an image w pixels wide, h pixels high with a color depth of depth, that uses an existing memory buffer, data. The buffer must remain valid throughout the life of the QImage. The image does not delete the buffer at destruction.

If colortable is 0, a color table sufficient for numColors will be allocated (and destructed later).

Note that data must be 32-bit aligned.

The endianness is given in bitOrder.

### QImage::QImage ( uchar * data, int w, int h, int depth, int bpl, const QRgb * colortable, int numColors, Endian bitOrder )

Constructs an image that uses an existing memory buffer. The buffer must remain valid for the life of the QImage. The image does not delete the buffer at destruction. The buffer is passed as data. The image's width is w and its height is h. The color depth is depth. bpl specifies the number of bytes per line.

If colortable is 0, a color table sufficient for numColors will be allocated (and destructed later).

The endianness is specified by bitOrder.

Warning: This constructor is only available in Qt/Embedded.

### QImage::QImage ( const QByteArray & data )

Use QImage::fromData(data) instead.

For example, if you have code like

        QByteArray data;
        ...
        QImage image(data);

you can rewrite it as

        QByteArray data;
        ...
        QImage image = QImage::fromData(data);

### Endian QImage::bitOrder () const

Returns the bit order for the image.

If it is a 1-bpp image, this function returns either QImage::BigEndian or QImage::LittleEndian.

If it is not a 1-bpp image, this function returns QImage::IgnoreEndian.

See also depth().

### QImage QImage::convertBitOrder ( Endian bitOrder ) const

Converts the bit order of the image to bitOrder and returns the converted image. The original image is not changed.

Returns `*this` if the bitOrder is equal to the image bit order, or a null image if this image cannot be converted.

See also bitOrder(), systemBitOrder(), and isNull().

### QImage QImage::convertDepth ( int depth, Qt::ImageConversionFlags flags = Qt::AutoColor ) const

Converts the depth (bpp) of the image to depth and returns the converted image. The original image is not changed.

The depth argument must be 1, 8 or 32.

Returns `*this` if depth is equal to the image depth, or a null image if this image cannot be converted.

If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to specify how you'd prefer this to happen.

See also depth() and isNull().

### QImage QImage::convertDepthWithPalette ( int d, QRgb * palette, int palette_count, Qt::ImageConversionFlags flags = Qt::AutoColor ) const

Returns an image with depth d, using the palette_count colors pointed to by palette. If d is 1 or 8, the returned image will have its color table ordered the same as palette.

If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to specify how you'd prefer this to happen.

Note: currently no closest-color search is made. If colors are found that are not in the palette, the palette may not be used at all. This result should not be considered valid because it may change in future implementations.

Currently inefficient for non-32-bit images.

### QImage QImage::copy ( int x, int y, int w, int h, Qt::ImageConversionFlags flags ) const

Use copy() and convertToFormat() instead.

### QImage QImage::copy ( const QRect & rect, Qt::ImageConversionFlags flags ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Use copy() and convertToFormat() instead.

### bool QImage::create ( int width, int height, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )

Sets the image width, height, depth, its number of colors (in numColors), and bit order. Returns true if successful, or false if the parameters are incorrect or if memory cannot be allocated.

The width and height is limited to 32767. depth must be 1, 8, or 32. If depth is 1, bitOrder must be set to either QImage::LittleEndian or QImage::BigEndian. For other depths bitOrder must be QImage::IgnoreEndian.

This function allocates a color table and a buffer for the image data. The image data is not initialized.

The image buffer is allocated as a single block that consists of a table of scanline pointers (jumpTable()) and the image data (bits()).

jumpTable() scanLine() bits() bytesPerLine() numBytes()

See also fill(), width(), height(), depth(), numColors(), and bitOrder().

### bool QImage::create ( const QSize & size, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

The width and height are specified in the size argument.

### bool QImage::hasAlphaBuffer () const

Returns true if alpha buffer mode is enabled; otherwise returns false.

See also setAlphaBuffer().

### void QImage::invertPixels ( bool invertAlpha )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Use the invertPixels() function that takes a QImage::InvertMode parameter instead.

### uchar ** QImage::jumpTable ()

Returns a pointer to the scanline pointer table.

This is the beginning of the data block for the image.

See also bits() and scanLine().

### const uchar * const * QImage::jumpTable () const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

### QImage QImage::mirror ( bool horizontal = false, bool vertical = true ) const

Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false. The original image is not changed.

See also scaled().

### void QImage::reset ()

Resets all image parameters and deallocates the image data.

### QImage QImage::scaleHeight ( int h ) const

Use scaledToHeight() instead.

### QImage QImage::scaleWidth ( int w ) const

Use scaledToWidth() instead.

### void QImage::setAlphaBuffer ( bool enable )

Enables alpha buffer mode if enable is true, otherwise disables it. The default setting is disabled.

An 8-bpp image has 8-bit pixels. A pixel is an index into the color table, which contains 32-bit color values. In a 32-bpp image, the 32-bit pixels are the color values.

This 32-bit value is encoded as follows: The lower 24 bits are used for the red, green, and blue components. The upper 8 bits contain the alpha component.

The alpha component specifies the transparency of a pixel. 0 means completely transparent and 255 means opaque. The alpha component is ignored if you do not enable alpha buffer mode.

The alpha buffer is used to set a mask when a QImage is translated to a QPixmap.

See also hasAlphaBuffer() and createAlphaMask().

### QImage QImage::smoothScale ( int width, int height, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio ) const

Use scale(width, height, mode, Qt::SmoothTransformation) instead.

### QImage QImage::smoothScale ( const QSize & size, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Use scale(size, mode, Qt::SmoothTransformation) instead.

### QImage QImage::swapRGB () const

Returns a QImage in which the values of the red and blue components of all pixels have been swapped, effectively converting an RGB image to a BGR image. The original QImage is not changed.

### Endian QImage::systemBitOrder () `[static]`

Determines the bit order of the display hardware. Returns QImage::LittleEndian (LSB first) or QImage::BigEndian (MSB first).

See also systemByteOrder().

### Endian QImage::systemByteOrder () `[static]`

Determines the host computer byte order. Returns QImage::LittleEndian (LSB first) or QImage::BigEndian (MSB first).

See also systemBitOrder().

### QImage QImage::xForm ( const QMatrix & matrix ) const

Use transform(matrix) instead.

## Related Non-Members

### void bitBlt ( QImage * dst, int dx, int dy, const QImage * src, int sx = 0, int sy = 0, int sw = -1, int sh = -1, Qt::ImageConversionFlags flags = Qt::AutoColor )

Copies a block of pixels from src to dst. The pixels copied from source (src) are converted according to flags if it is incompatible with the destination (dst).

sx, sy is the top-left pixel in src, dx, dy is the top-left position in dst and sw, sh is the size of the copied block.

The copying is clipped if areas outside src or dst are specified.

If sw is -1, it is adjusted to src->width(). Similarly, if sh is -1, it is adjusted to src->height().

Currently inefficient for non 32-bit images.