QImage(3qt)
๐ QImage ๐
okay bestie, sit DOWN, because this is QImage(3qt) from the Qt 3 era and she is a long one. this is part 1 of 5, so hydrate ๐ and let's get into it
โจ NAME โจ
QImage โ hardware-independent pixmap representation with direct access to the pixel data ๐
๐ SYNOPSIS ๐
#include <qimage.h>
๐ Public Members ๐
enum Endian { IgnoreEndian, BigEndian, LittleEndian }
QImage ()
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 ( const QString & fileName, const char * format = 0 )
QImage ( const char * const xpm[] )
QImage ( const QByteArray & array )
QImage ( uchar * yourdata, int w, int h, int depth, QRgb * colortable,
int numColors, Endian bitOrder )
QImage ( uchar * yourdata, int w, int h, int depth, int bpl, QRgb *
colortable, int numColors, Endian bitOrder )
QImage ( const QImage & image )
~QImage ()
QImage & operator= ( const QImage & image )
QImage & operator= ( const QPixmap & pixmap )
bool operator== ( const QImage & i ) const
bool operator!= ( const QImage & i ) const
void detach ()
QImage copy () const
QImage copy ( int x, int y, int w, int h, int conversion_flags = 0 )
const
QImage copy ( const QRect & r ) const
bool isNull () const
int width () const
int height () const
QSize size () const
QRect rect () const
int depth () const
int numColors () const
Endian bitOrder () const
QRgb color ( int i ) const
void setColor ( int i, QRgb c )
void setNumColors ( int numColors )
bool hasAlphaBuffer () const
void setAlphaBuffer ( bool enable )
bool allGray () const
bool isGrayscale () const
uchar * bits () const
uchar * scanLine ( int i ) const
uchar ** jumpTable () const
QRgb * colorTable () const
int numBytes () const
int bytesPerLine () const
bool create ( int width, int height, int depth, int numColors = 0,
Endian bitOrder = IgnoreEndian )
bool create ( const QSize &, int depth, int numColors = 0, Endian
bitOrder = IgnoreEndian )
void reset ()
void fill ( uint pixel )
void invertPixels ( bool invertAlpha = TRUE )
QImage convertDepth ( int depth ) const
QImage convertDepthWithPalette ( int d, QRgb * palette, int
palette_count, int conversion_flags = 0 ) const
QImage convertDepth ( int depth, int conversion_flags ) const
QImage convertBitOrder ( Endian bitOrder ) const
enum ScaleMode { ScaleFree, ScaleMin, ScaleMax }
QImage smoothScale ( int w, int h, ScaleMode mode = ScaleFree ) const
QImage smoothScale ( const QSize & s, ScaleMode mode = ScaleFree ) const
QImage scale ( int w, int h, ScaleMode mode = ScaleFree ) const
QImage scale ( const QSize & s, ScaleMode mode = ScaleFree ) const
QImage scaleWidth ( int w ) const
QImage scaleHeight ( int h ) const
QImage xForm ( const QWMatrix & matrix ) const
QImage createAlphaMask ( int conversion_flags = 0 ) const
QImage createHeuristicMask ( bool clipTight = TRUE ) const
QImage mirror () const
QImage mirror ( bool horizontal, bool vertical ) const
QImage swapRGB () const
bool load ( const QString & fileName, const char * format = 0 )
bool loadFromData ( const uchar * buf, uint len, const char * format = 0
)
bool loadFromData ( QByteArray buf, const char * format = 0 )
bool save ( const QString & fileName, const char * format, int quality =
-1 ) const
bool save ( QIODevice * device, const char * format, int quality = -1 )
const
bool valid ( int x, int y ) const
int pixelIndex ( int x, int y ) const
QRgb pixel ( int x, int y ) const
void setPixel ( int x, int y, uint index_or_rgb )
int dotsPerMeterX () const
int dotsPerMeterY () const
void setDotsPerMeterX ( int x )
void setDotsPerMeterY ( int y )
QPoint offset () const
void setOffset ( const QPoint & p )
QValueList<QImageTextKeyLang> textList () const
QStringList textLanguages () const
QStringList textKeys () const
QString text ( const char * key, const char * lang = 0 ) const
QString text ( const QImageTextKeyLang & kl ) const
void setText ( const char * key, const char * lang, const QString & s )
๐ Static Public Members ๐
QImage fromMimeSource ( const QString & abs_name )
Endian systemBitOrder ()
Endian systemByteOrder ()
const char * imageFormat ( const QString & fileName )
QStrList inputFormats ()
QStrList outputFormats ()
QStringList inputFormatList ()
QStringList outputFormatList ()
๐ฆ RELATED FUNCTION DOCUMENTATION ๐ฆ
QDataStream & operator<< ( QDataStream & s, const QImage & image )
QDataStream & operator>> ( QDataStream & s, QImage & image )
void bitBlt ( QImage * dst, int dx, int dy, const QImage * src, int sx,
int sy, int sw, int sh, int conversion_flags )
๐ธ DESCRIPTION ๐ธ
The QImage class provides a hardware-independent pixmap representation with direct access to the pixel data. periodt โจ
She is one of the two classes Qt gives you for dealing with images โ the other one is QPixmap. And here's the tea: QImage is designed and optimized for I/O and for direct pixel access/manipulation, while QPixmap is the one built for drawing. There are (slow ๐ญ) functions to convert between them: QPixmap::convertToImage() and QPixmap::convertFromImage().
An image has these parameters: width, height and depth (that's bits per pixel, bpp), a color table and the actual pixels. QImage supports 1-bpp, 8-bpp and 32-bpp image data. The 1-bpp and 8-bpp images use a color lookup table, where the pixel value is an index into the color table.
The 32-bpp images encode an RGB value in 24 bits and ignore the color table. The most significant byte is used for the alpha buffer. ๐
An entry in the color table is an RGB triplet encoded as a uint. Use the qRed(), qGreen() and qBlue() functions (qcolor.h) to access the components, and qRgb to make an RGB triplet (peep the QColor class documentation for that).
1-bpp (monochrome) images have a color table with at most two colors. There are two different formats: big endian (MSB first) or little endian (LSB first) bit order. To access a single bit you will have to do some bit shifts, no cap:
QImage image;
// sets bit at (x,y) to 1
if ( image.bitOrder() == QImage::LittleEndian )
*(image.scanLine(y) + (x >> 3)) |= 1 << (x & 7);
else
*(image.scanLine(y) + (x >> 3)) |= 1 << (7 - (x & 7));
If this looks complicated (and bestie, it kind of is ๐), it might be a good idea to convert the 1-bpp image to an 8-bpp image using convertDepth().
8-bpp images are much easier to work with than 1-bpp images because they have a single byte per pixel:
QImage image;
// set entry 19 in the color table to yellow
image.setColor( 19, qRgb(255,255,0) );
// set 8 bit pixel at (x,y) to value yellow (in color table)
*(image.scanLine(y) + x) = 19;
32-bpp images ignore the color table; instead, each pixel contains the RGB triplet. 24 bits contain the RGB value; the most significant byte is reserved for the alpha buffer.
QImage image;
// sets 32 bit pixel at (x,y) to yellow.
uint *p = (uint *)image.scanLine(y) + x;
*p = qRgb(255,255,0);
On Qt/Embedded, scanlines are aligned to the pixel depth and may be padded to any degree, while on all other platforms, the scanlines are 32-bit aligned for all depths. The constructor taking a uchar* argument always expects 32-bit aligned data. On Qt/Embedded, an additional constructor allows the number of bytes-per-line to be specified. ๐
QImage supports a whole variety of methods for getting information about the image, for example: colorTable(), allGray(), isGrayscale(), bitOrder(), bytesPerLine(), depth(), dotsPerMeterX() and dotsPerMeterY(), hasAlphaBuffer(), numBytes(), numColors(), and width() and height(). so many little getters, we love a thorough queen ๐
Pixel colors are retrieved with pixel() and set with setPixel().
QImage also supports a number of functions for creating a new image that is a transformed version of the original. For example: copy(), convertBitOrder(), convertDepth(), createAlphaMask(), createHeuristicMask(), mirror(), scale(), smoothScale(), swapRGB() and xForm(). There are also functions for changing attributes of an image in-place, for example: setAlphaBuffer(), setColor(), setDotsPerMeterX() and setDotsPerMeterY() and setNumColors().
Images can be loaded and saved in the supported formats. Images are saved to a file with save(). Images are loaded from a file with load() (or in the constructor) or from an array of data with loadFromData(). The lists of supported formats are available from inputFormatList() and outputFormatList(). ๐
Strings of text may be added to images using setText().
The QImage class uses explicit sharing, similar to that used by QMemArray.
New image formats can be added as plugins. โจ
See also QImageIO, QPixmap, Shared Classes, Graphics Classes, Image Processing Classes, and Implicitly and Explicitly Shared Classes.
๐ง Member Type Documentation ๐ง
QImage::Endian
This enum type is used to describe the endianness of the CPU and graphics hardware.
QImage::IgnoreEndianโ Endianness does not matter. Useful for some operations that are independent of endianness.QImage::BigEndianโ Network byte order, as on SPARC and Motorola CPUs.QImage::LittleEndianโ PC/Alpha byte order.
QImage::ScaleMode
The functions scale() and smoothScale() use different modes for scaling the image. The purpose of these modes is to retain the ratio of the image if this is required.
fun fact: the original manpage literally had a picture right here and it got omitted ๐ญ image who? we don't know her.
QImage::ScaleFreeโ The image is scaled freely: the resulting image fits exactly into the specified size; the ratio will not necessarily be preserved.QImage::ScaleMinโ The ratio of the image is preserved and the resulting image is guaranteed to fit into the specified size (it is as large as possible within these constraints) โ the image might be smaller than the requested size.QImage::ScaleMaxโ The ratio of the image is preserved and the resulting image fills the whole specified rectangle (it is as small as possible within these constraints) โ the image might be larger than the requested size.
๐ MEMBER FUNCTION DOCUMENTATION ๐
QImage::QImage ()
Constructs a null image. iconic, empty, unbothered ๐
See also isNull().
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().
okay that's part 1, keep scrolling bestie, we're not done yet ๐
QImage::QImage ( const QSize & size, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )
okay bestie, this one builds you an image that's size pixels big, with depth bits of depth, plus numColors and bitOrder for the endianness. ๐
Fun fact: using this constructor is literally the exact same thing as making a null image first and then hitting it with create().
See also create().
QImage::QImage ( const QString & fileName, const char * format = 0 )
This one constructs an image and tries to load it from the file fileName. ๐ซถ
If you hand it a format, the loader will attempt to read the image using that specified format. If format is not specified (which, btw, is the default), the loader reads a few bytes from the header to guess the file format like the little detective it is. ๐
And if the loading failed? Yeah, this object is a null image. no cap. ๐
The QImageIO documentation lists the supported image formats and explains how to add extra formats.
See also load(), isNull(), and QImageIO.
QImage::QImage ( const char * const xpm[] )
Constructs an image from xpm, which has to be a valid XPM image. โจ
Errors are silently ignored โ like, it's not gonna yell at you, it just quietly moves on. ๐
Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:
static const char * const start_xpm[]={
"16 15 8 1",
"a c #cec6bd",
....
That extra const makes the entire definition read-only, which is slightly more efficient (e.g. when the code is in a shared library) and ROMable when the application is to be stored in ROM. efficiency queen behavior ๐
QImage::QImage ( const QByteArray & array )
Constructs an image from the binary data in array. It tries to guess the file format. ๐ฎ
If the loading of the image failed, this object is a null image.
See also loadFromData(), isNull(), and imageFormat().
QImage::QImage ( uchar * yourdata, int w, int h, int depth, QRgb * colortable, int numColors, Endian bitOrder )
Constructs an image w pixels wide and h pixels high with a color depth of depth, that uses an existing memory buffer, yourdata. ๐ง
bestie, listen: the buffer must remain valid throughout the life of the QImage. The image does not delete the buffer at destruction. So don't you dare free it early. ๐ญ
If colortable is 0, a color table sufficient for numColors will be allocated (and destructed later).
Note that yourdata must be 32-bit aligned. โญ
The endianness is given in bitOrder.
QImage::QImage ( uchar * yourdata, int w, int h, int depth, int bpl, 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 yourdata. The image's width is w and its height is h. The color depth is depth. And 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 on Qt/Embedded. ๐จ
QImage::QImage ( const QImage & image )
Constructs a shallow copy of image. ๐ฆ
QImage::~QImage ()
Destroys the image and cleans up. bye bestie, it was real ๐ธ
bool QImage::allGray () const
Returns TRUE if all the colors in the image are shades of gray (i.e. their red, green and blue components are equal); otherwise returns FALSE. ๐ซ๏ธ
Heads up: this function is slow for large 16-bit (Qt/Embedded only) and 32-bit images. so maybe don't run it in a loop, iykyk ๐ญ
See also isGrayscale().
Endian QImage::bitOrder () const
Returns the bit order for the image. โจ
If it's a 1-bpp image, this function returns either QImage::BigEndian or QImage::LittleEndian.
If it's not a 1-bpp image, this function returns QImage::IgnoreEndian.
See also depth().
uchar * QImage::bits () const
Returns a pointer to the first pixel data. This is equivalent to scanLine(0). ๐ฏ
See also numBytes(), scanLine(), and jumpTable().
Example: opengl/texture/gltexobj.cpp.
int QImage::bytesPerLine () const
Returns the number of bytes per image scanline. This is equivalent to numBytes()/height(). ๐
See also numBytes() and scanLine().
QRgb QImage::color ( int i ) const
Returns the color in the color table at index i. The first color is at index 0. ๐จ
A color value is an RGB triplet. Use the qRed(), qGreen() and qBlue() functions (defined in qcolor.h) to get the color value components.
See also setColor(), numColors(), and QColor.
Example: themes/wood.cpp.
QRgb * QImage::colorTable () const
Returns a pointer to the color table. ๐๏ธ
See also numColors().
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 โ it's giving respectful, no take-backs. ๐
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, int conversion_flags ) 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, 16 (Qt/Embedded only) 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 conversion_flags to specify how you'd prefer this to happen. you're the main character here, you decide โจ
See also Qt::ImageConversionFlags, depth(), and isNull().
QImage QImage::convertDepth ( int depth ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. ๐ซถ
QImage QImage::convertDepthWithPalette ( int d, QRgb * palette, int palette_count, int conversion_flags = 0 ) 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 conversion_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. ๐ฉ so like, don't build your whole app on this, bestie.
Currently inefficient for non-32-bit images. ๐ญ
See also Qt::ImageConversionFlags.
QImage QImage::copy () const
Returns a deep copy of the image. โจ
See also detach().
QImage QImage::copy ( int x, int y, int w, int h, int conversion_flags = 0 ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns a deep copy of a sub-area of the image. ๐
The returned image is always w by h pixels in size, and is copied from position x, y in this image. In areas beyond this image, pixels are filled with pixel 0.
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 conversion_flags to specify how you'd prefer this to happen.
See also bitBlt() and Qt::ImageConversionFlags.
QImage QImage::copy ( const QRect & r ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns a deep copy of a sub-area of the image. ๐ฆ
The returned image always has the size of the rectangle r. In areas beyond this image, pixels are filled with pixel 0.
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. no mixing and matching, the rules are the rules ๐
This function allocates a color table and a buffer for the image data. The image data is not initialized. โ ๏ธ (so don't be surprised when it's giving chaos pixels)
The image buffer is allocated as a single block that consists of a table of scanline pointers (jumpTable()) and the image data (bits()).
See also fill(), width(), height(), depth(), numColors(), bitOrder(), jumpTable(), scanLine(), bits(), bytesPerLine(), and numBytes().
bool QImage::create ( const QSize &, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. โจ
QImage QImage::createAlphaMask ( int conversion_flags = 0 ) const
Builds and returns a 1-bpp mask from the alpha buffer in this image. Returns a null image if alpha buffer mode is disabled. ๐ญ
See QPixmap::convertFromImage() for a description of the conversion_flags argument.
The returned image has little-endian bit order, which you can convert to big-endianness using convertBitOrder(). ๐
See also createHeuristicMask(), hasAlphaBuffer(), and setAlphaBuffer().
QImage QImage::createHeuristicMask ( bool clipTight = TRUE ) const
Creates and returns a 1-bpp heuristic mask for this image. It works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges. ๐จ
The four corners vote for which color is to be masked away โ democracy but make it pixels. In case of a draw (this generally means that this function is not applicable to the image), the result is arbitrary. ๐คท
The returned image has little-endian bit order, which you can convert to big-endianness using convertBitOrder().
If clipTight is TRUE the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels. โ๏ธ
This function disregards the alpha buffer. ๐
See also createAlphaMask().
int QImage::depth () const
Returns the depth of the image. ๐
The image depth is the number of bits used to encode a single pixel, also called bits per pixel (bpp) or bit planes of an image.
The supported depths are 1, 8, 16 (Qt/Embedded only) and 32.
See also convertDepth().
void QImage::detach ()
Detaches from shared image data and makes sure that this image is the only one referring to the data. ๐ฆ
If multiple images share common data, this image makes a copy of the data and detaches itself from the sharing mechanism. Nothing is done if there is just a single reference. like, if it's already yours, it stays yours ๐
See also copy().
Example: themes/wood.cpp.
int QImage::dotsPerMeterX () const
Returns the number of pixels that fit horizontally in a physical meter. This and dotsPerMeterY() define the intended scale and aspect ratio of the image. ๐
See also setDotsPerMeterX().
int QImage::dotsPerMeterY () const
Returns the number of pixels that fit vertically in a physical meter. This and dotsPerMeterX() define the intended scale and aspect ratio of the image. ๐
See also setDotsPerMeterY().
void QImage::fill ( uint pixel )
okay so bestie, this one is giving full-coverage foundation for your image ๐
โ it fills the entire image with the pixel value pixel. Every single one. No survivors. Slay.
Here's the tea on what actually gets written, because it depends on your depth:
- If the depth of this image is 1, only the lowest bit is used. So if you say
fill(0),fill(2), etc., the image is filled with 0s. If you sayfill(1),fill(3), etc., the image is filled with 1s. - If the depth is 8, the lowest 8 bits are used.
- If the depth is 32 and the image has no alpha buffer, the pixel value is written to each pixel in the image. If the image has an alpha buffer, only the 24 RGB bits are set and the upper 8 bits (the alpha value) are left unchanged. so your alpha stays iconic and untouched, periodt.
Note:QImage::pixel()returns the color of the pixel at the given coordinates;QColor::pixel()returns the pixel value of the underlying window system (essentially an index value), so normally you will want to useQImage::pixel()to use a color from an existing image orQColor::rgb()to use a specific color. iykyk ๐
See also invertPixels(), depth(), hasAlphaBuffer(), and create().
QImage QImage::fromMimeSource ( const QString & abs_name ) [static]
Convenience function, bestie โ a little drive-thru for images ๐. It gets the data associated with the absolute name abs_name from the default mime source factory and decodes it to an image.
See also QMimeSourceFactory, QImage::fromMimeSource(), and QImageDrag::decode().
bool QImage::hasAlphaBuffer () const
Returns TRUE if alpha buffer mode is enabled; otherwise returns FALSE. that's it, that's the whole vibe check โจ
See also setAlphaBuffer().
int QImage::height () const
Returns the height of the image. iconic. vertical. ๐
See also width(), size(), and rect().
Examples:
const char * QImage::imageFormat ( const QString & fileName ) [static]
Returns a string that specifies the image format of the file fileName, or 0 if the file cannot be read or if the format is not recognized. so if it's giving mystery file, you get a 0 back, no cap.
The QImageIO documentation lists the guaranteed supported image formats, or use QImage::inputFormats() and QImage::outputFormats() to get lists that include the installed formats.
See also load() and save().
QStringList QImage::inputFormatList () [static]
Returns a list of image formats that are supported for image input. ๐ฅ
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QStringList list = myImage.inputFormatList();
QStringList::Iterator it = list.begin();
while( it != list.end() ) {
myProcessing( *it );
++it;
}
See also outputFormatList(), inputFormats(), and QImageIO.
Example: showimg/showimg.cpp.
QStrList QImage::inputFormats () [static]
Returns a list of image formats that are supported for image input. the OG version of the list function, fr fr.
See also outputFormats(), inputFormatList(), and QImageIO.
void QImage::invertPixels ( bool invertAlpha = TRUE )
Inverts all pixel values in the image. negative filter, but make it fashion ๐
If the depth is 32: if invertAlpha is TRUE, the alpha bits are also inverted, otherwise they are left unchanged.
If the depth is not 32, the argument invertAlpha has no meaning. it's just there, chilling, doing nothing ๐
Note that inverting an 8-bit image means to replace all pixels using color indexiwith a pixel using color index 255 minusi. Similarly for a 1-bit image. The color table is not changed. so the palette stays exactly as it was, bestie.
See also fill(), depth(), and hasAlphaBuffer().
bool QImage::isGrayscale () const
For 16-bit (Qt/Embedded only) and 32-bit images, this function is equivalent to allGray().
For 8-bpp images, this function returns TRUE if color(i) is QRgb(i,i,i) for all indices of the color table; otherwise returns FALSE. so it's checking every single entry is equal parts R, G and B โ the true neutral aesthetic ๐ฉถ
See also allGray() and depth().
bool QImage::isNull () const
Returns TRUE if it is a null image; otherwise returns FALSE.
A null image has all parameters set to zero and no allocated data. it's giving empty shell, no thoughts, head empty ๐ซถ
Example: showimg/showimg.cpp.
uchar ** QImage::jumpTable () const
Returns a pointer to the scanline pointer table. ๐ช
This is the beginning of the data block for the image.
See also bits() and scanLine().
bool QImage::load ( const QString & fileName, const char * format = 0 )
Loads an image from the file fileName. Returns TRUE if the image was successfully loaded; otherwise returns FALSE. bestie is fed ๐ฅโจ
If format is specified, the loader attempts to read the image using the specified format. If format is not specified (which is the default), the loader reads a few bytes from the header to guess the file format. detective era ๐
The QImageIO documentation lists the supported image formats and explains how to add extra formats.
See also loadFromData(), save(), imageFormat(), QPixmap::load(), and QImageIO.
bool QImage::loadFromData ( const uchar * buf, uint len, const char * format = 0 )
Loads an image from the first len bytes of binary data in buf. Returns TRUE if the image was successfully loaded; otherwise returns FALSE. no file needed, we're loading straight from the raw bytes bestie ๐
If format is specified, the loader attempts to read the image using the specified format. If format is not specified (which is the default), the loader reads a few bytes from the header to guess the file format.
The QImageIO documentation lists the supported image formats and explains how to add extra formats.
See also load(), save(), imageFormat(), QPixmap::loadFromData(), and QImageIO.
bool QImage::loadFromData ( QByteArray buf, const char * format = 0 )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Loads an image from the QByteArray buf. yes it's the same thing but with a QByteArray, and yes it's still slaying ๐
QImage QImage::mirror () const
Returns a QImage which is a vertically mirrored copy of this image. The original QImage is not changed. so your original stays untouched and unbothered, main character energy ๐
QImage QImage::mirror ( bool horizontal, bool vertical ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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. pick your axis, bestie, flip it any way you like ๐ช
See also smoothScale().
int QImage::numBytes () const
Returns the number of bytes occupied by the image data. the weight of the image, literally.
See also bytesPerLine() and bits().
int QImage::numColors () const
Returns the size of the color table for the image.
Notice thatnumColors()returns 0 for 16-bpp (Qt/Embedded only) and 32-bpp images because these images do not use color tables, but instead encode pixel values as RGB triplets. so if you got a0and you're confused โ that's not a bug bestie, that's just how RGB triplets roll ๐
See also setNumColors() and colorTable().
Example: themes/wood.cpp.
QPoint QImage::offset () const
Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images. a little nudge nudge ๐
bool QImage::operator!= ( const QImage & i ) const
Returns TRUE if this image and image i have different contents; otherwise returns FALSE. The comparison can be slow, unless there is some obvious difference, such as different widths, in which case the function will return quickly. so it's fast when it can be, slow when it has to be โ no notes, fr fr.
See also operator=().
QImage & QImage::operator= ( const QImage & image )
Assigns a shallow copy of image to this image and returns a reference to this image. shallow, not deep โ they're sharing, bestie ๐ค
See also copy().
QImage & QImage::operator= ( const QPixmap & pixmap )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Sets the image bits to the pixmap contents and returns a reference to the image.
If the image shares data with other images, it will first dereference the shared data. detaching era โจ
Makes a call to QPixmap::convertToImage().
bool QImage::operator== ( const QImage & i ) const
Returns TRUE if this image and image i have the same contents; otherwise returns FALSE. The comparison can be slow, unless there is some obvious difference, such as different widths, in which case the function will return quickly. twin energy, but only if it's actually a twin ๐
See also operator=().
QStringList QImage::outputFormatList () [static]
Returns a list of image formats that are supported for image output. ๐ค
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QStringList list = myImage.outputFormatList();
QStringList::Iterator it = list.begin();
while( it != list.end() ) {
myProcessing( *it );
++it;
}
See also inputFormatList(), outputFormats(), and QImageIO.
QStrList QImage::outputFormats () [static]
Returns a list of image formats that are supported for image output.
See also inputFormats(), outputFormatList(), and QImageIO.
Example: showimg/showimg.cpp.
QRgb QImage::pixel ( int x, int y ) const
Returns the color of the pixel at the coordinates (x, y). ๐ฏ
If (x,y) is not on the image, the results are undefined. bestie do NOT do that, that's not a vibe check you want to fail ๐ญ
See also setPixel(), qRed(), qGreen(), qBlue(), and valid().
Examples:
int QImage::pixelIndex ( int x, int y ) const
Returns the pixel index at the given coordinates.
If (x,y) is not valid, or if the image is not a paletted image (depth()> 8), the results are undefined. read that again bestie, undefined means undefined ๐จ
See also valid() and depth().
QRect QImage::rect () const
Returns the enclosing rectangle (0, 0, width(), height()) of the image. the whole box, the whole containment unit ๐ฆ
See also width(), height(), and size().
void QImage::reset ()
Resets all image parameters and deallocates the image data. factory reset, but make it slay ๐ everything gone, nothing left, clean slate periodt.
bool QImage::save ( const QString & fileName, const char * format, int quality = -1 ) const
Saves the image to the file fileName, using the image file format format and a quality factor of quality. quality must be in the range 0..100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 (the default) to use the default settings.
Returns TRUE if the image was successfully saved; otherwise returns FALSE. we love a successful export โจ๐ค
See also load(), loadFromData(), imageFormat(), QPixmap::save(), and QImageIO.
bool QImage::save ( QIODevice * device, const char * format, int quality = -1 ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
This function writes a QImage to the QIODevice, device. This can be used, for example, to save an image directly into a QByteArray:
QImage image;
QByteArray ba;
QBuffer buffer( ba );
buffer.open( IO_WriteOnly );
image.save( &buffer, "PNG" ); // writes image into ba in PNG format
QImage QImage::scale ( int w, int h, ScaleMode mode = ScaleFree ) const
Returns a copy of the image scaled to a rectangle of width w and height h according to the ScaleMode mode. glow up incoming โจ
- If
modeisScaleFree, the image is scaled to (w,h). no rules, just vibes, aspect ratio who? ๐ฆ - If
modeisScaleMin, the image is scaled to a rectangle as large as possible inside (w,h), preserving the aspect ratio. - If
modeisScaleMax, the image is scaled to a rectangle as small as possible outside (w,h), preserving the aspect ratio.
If either the width w or the height h is 0 or negative, this function returns a null image. yeah, you get nothing. nothing. ๐
This function uses a simple, fast algorithm. If you need better quality, use smoothScale() instead. fast and cheap vs pretty and slow โ the eternal struggle ๐ญ
See also scaleWidth(), scaleHeight(), smoothScale(), and xForm().
QImage QImage::scale ( const QSize & s, ScaleMode mode = ScaleFree ) constโ okay so this is an overloaded member function, provided for convenience (they literally just did it again but with aQSizebestie ๐ ). It behaves essentially like the above function. The requested size of the image iss. slay.QImage QImage::scaleHeight ( int h ) constโ returns a scaled copy of the image โจ. The returned image has a height ofhpixels. This function automatically calculates the width of the image so that the ratio of the image is preserved โ no math for you, queen ๐ซถ. Ifhis0or negative, a null image is returned. See alsoscale(),scaleWidth(),smoothScale(), andxForm().
Example: table/small-table-demo/main.cpp.
QImage QImage::scaleWidth ( int w ) constโ returns a scaled copy of the image โจ. The returned image has a width ofwpixels. This function automatically calculates the height of the image so that the ratio of the image is preserved. Ifwis0or negative, a null image is returned. See alsoscale(),scaleHeight(),smoothScale(), andxForm().uchar * QImage::scanLine ( int i ) constโ returns a pointer to the pixel data at the scanline with indexi๐ฅ. The first scanline is at index0. The scanline data is aligned on a 32-bit boundary.
Warning: if you are accessing 32-bpp image data, cast the returned pointer toQRgb*(QRgbhas a 32-bit size) and use it to read/write the pixel value. You cannot use theuchar*pointer directly, because the pixel format depends on the byte order on the underlying platform. Hint: useqRed(),qGreen()andqBlue(), etc. (qcolor.h) to access the pixels. ๐ญ
Warning: if you are accessing 16-bpp image data, you must handle endianness yourself. (Qt/Embedded only)
See also bytesPerLine(), bits(), and jumpTable().
Example: desktop/desktop.cpp.
void QImage::setAlphaBuffer ( bool enable )โ enables alpha buffer mode ifenableisTRUE, 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().
void QImage::setColor ( int i, QRgb c )โ sets a color in the color table at indexitoc๐จ. A color value is an RGB triplet. Use theqRgb()function (defined inqcolor.h) to make RGB triplets. See alsocolor(),setNumColors(), andnumColors().
Examples: (yes bestie, the original just says "Examples:" and leaves you hanging โ the vibe is the vibe ๐)
void QImage::setDotsPerMeterX ( int x )โ sets the value returned bydotsPerMeterX()tox.void QImage::setDotsPerMeterY ( int y )โ sets the value returned bydotsPerMeterY()toy.void QImage::setNumColors ( int numColors )โ resizes the color table tonumColorscolors. If the color table is expanded, all the extra colors will be set to black (RGB0,0,0). See alsonumColors(),color(),setColor(), andcolorTable().void QImage::setOffset ( const QPoint & p )โ sets the value returned byoffset()top.void QImage::setPixel ( int x, int y, uint index_or_rgb )โ sets the pixel index or color at the coordinates (x,y) toindex_or_rgb. If (x,y) is not valid, the result is undefined โ ๏ธ. If the image is a paletted image (depth()<= 8) andindex_or_rgb>=numColors(), the result is undefined. See alsopixelIndex(),pixel(),qRgb(),qRgba(), andvalid().void QImage::setText ( const char * key, const char * lang, const QString & s )โ records stringsfor the keywordkey๐. Thekeyshould be a portable keyword recognizable by other software โ some suggested values can be found in the PNG specification.scan be any text.langshould specify the language code (see RFC 1766) or0.QSize QImage::size () constโ returns the size of the image, i.e. its width and height ๐ฆ. See alsowidth(),height(), andrect().QImage QImage::smoothScale ( int w, int h, ScaleMode mode = ScaleFree ) constโ returns a smoothly scaled copy of the image โจ๐. The returned image has a size of widthwby heighthpixels ifmodeisScaleFree. The modesScaleMinandScaleMaxmay be used to preserve the ratio of the image: ifmodeisScaleMin, the returned image is guaranteed to fit into the rectangle specified bywandh(it is as large as possible within the constraints); ifmodeisScaleMax, the returned image fits at least into the specified rectangle (it is a small as possible within the constraints). ๐
For 32-bpp images and 1-bpp/8-bpp color images the result will be 32-bpp, whereas all-gray images (including black-and-white 1-bpp) will produce 8-bit grayscale images with the palette spanning 256 grays from black to white.
This function uses code based on pnmscale.c by Jef Poskanzer.
pnmscale.c - read a portable anymap and scale it
Copyright (C) 1989, 1991 by Jef Poskanzer.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation. This software is provided "as is" without
express or implied warranty.
See also scale() and mirror().
QImage QImage::smoothScale ( const QSize & s, ScaleMode mode = ScaleFree ) constโ this is an overloaded member function, provided for convenience. It behaves essentially like the above function. The requested size of the image iss.QImage QImage::swapRGB () constโ returns aQImagein 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 originalQImageis not changed โ she stays unbothered, periodt ๐ .Endian QImage::systemBitOrder () [static]โ determines the bit order of the display hardware. ReturnsQImage::LittleEndian(LSB first) orQImage::BigEndian(MSB first). See alsosystemByteOrder().Endian QImage::systemByteOrder () [static]โ determines the host computer byte order. ReturnsQImage::LittleEndian(LSB first) orQImage::BigEndian(MSB first). See alsosystemBitOrder().QString QImage::text ( const char * key, const char * lang = 0 ) constโ returns the string recorded for the keywordkeyin languagelang, or in a default language iflangis0.QString QImage::text ( const QImageTextKeyLang & kl ) constโ this is an overloaded member function, provided for convenience. It behaves essentially like the above function. Returns the string recorded for the keyword and languagekl.QStringList QImage::textKeys () constโ returns the keywords for which some texts are recorded ๐.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QStringList list = myImage.textKeys();
QStringList::Iterator it = list.begin();
while( it != list.end() ) {
myProcessing( *it );
++it;
}
See also textList(), text(), setText(), and textLanguages().
QStringList QImage::textLanguages () constโ returns the language identifiers for which some texts are recorded ๐.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QStringList list = myImage.textLanguages();
QStringList::Iterator it = list.begin();
while( it != list.end() ) {
myProcessing( *it );
++it;
}
See also textList(), text(), setText(), and textKeys().
QValueList<QImageTextKeyLang> QImage::textList () constโ returns a list ofQImageTextKeyLangobjects that enumerate all the texts key/language pairs set bysetText()for this image ๐.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QValueList<QImageTextKeyLang> list = myImage.textList();
QValueList<QImageTextKeyLang>::Iterator it = list.begin();
while( it != list.end() ) {
myProcessing( *it );
++it;
}
bool QImage::valid ( int x, int y ) constโ returnsTRUEif (x,y) is a valid coordinate in the image; otherwise returnsFALSEโ . See alsowidth(),height(), andpixelIndex().
Examples: (again bestie, "Examples:" and nothing else โ iconic cryptic behaviour honestly ๐)
int QImage::width () constโ returns the width of the image. See alsoheight(),size(), andrect().
Examples: (same energy ๐)
QImage QImage::xForm ( const QWMatrix & matrix ) constโ returns a copy of the image that is transformed using the transformation matrix,matrix๐ฎ.
The transformation matrix is internally adjusted to compensate for unwanted translation, i.e. xForm() returns the smallest image that contains all the transformed points of the original image.
See also scale(), QPixmap::xForm(), QPixmap::trueMatrix(), and QWMatrix.
โจ RELATED FUNCTION DOCUMENTATION โจ
void bitBlt ( QImage * dst, int dx, int dy, const QImage * src, int sx, int sy, int sw, int sh, int conversion_flags )โ copies a block of pixels fromsrctodst๐ผ๏ธ. The pixels copied from source (src) are converted according toconversion_flagsif 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 ๐.
QDataStream & operator<< ( QDataStream & s, const QImage & image )โ writes the imageimageto the streamsas a PNG image, or as a BMP image if the stream's version is1. Note that writing the stream to a file will not produce a valid image file ๐ญ. See alsoQImage::save()and Format of theQDataStreamoperators.QDataStream & operator>> ( QDataStream & s, QImage & image )โ reads an image from the streamsand stores it inimage๐ฅ. See alsoQImage::load()and Format of theQDataStreamoperators.
๐ SEE ALSO ๐
๐ COPYRIGHT ๐
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
๐ AUTHOR ๐
Generated automatically from the source code. (yes the author is literally a script, and honestly? she ate ๐ )
๐ BUGS ๐ (bestie we gotta talk) ๐
okay so like, if you find a bug in Qt โ and ngl you might, no shade to Trolltech, it's just a lot of code โ pls pls pls report it the way they describe at:
http://doc.trolltech.com/bughowto.html
and listen, good bug reports literally help us help you, okay?? that's the whole vibe. thank you ๐ซถ
okay so real talk about the docs situation because it's giving โจ important โจ:
the definitive Qt documentation is in HTML format โ that's the main character, no cap. it lives right here:
$QTDIR/doc/html
and you can read it either with Qt Assistant or with a web browser. your choice, both slay ๐
this man page?? bestie... it's provided as a convenience for those users who prefer man pages. that's it. that's the whole reason. it is not officially supported by Trolltech in this format. so like, enjoy it, but know that the HTML one is the real one ๐
and okay, one more thing โ if you find errors in this manual page itself (like, the words you're reading rn, which would be so embarrassing for everyone), pls report them to:
qt-bugs@trolltech.com
and when you do, include:
- the name of the manual page:
qimage.3qt - the Qt version:
3.3.8
don't skip those two, they need them to know what you're even talking about fr fr ๐ญ
๐ not me telling you to file bug reports at the very end of the page like a plot twist. iconic behavior honestly.
Trolltech AS โ 2 February 2007 ๐ธ that's who wrote this whole thing and when it went out into the world, and yeah the page itself is QImage(3qt) in case you forgot where you were ๐
k bye bestie, go forth and bitBlt responsibly ๐ฆโจ๐
๐ฆ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 ยท QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 ยท QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms