QtBase  v6.3.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | Related Functions | List of all members
QImage Class Reference

The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device. More...

#include <qimage.h>

Inheritance diagram for QImage:
Inheritance graph
[legend]
Collaboration diagram for QImage:
Collaboration graph
[legend]

Public Types

enum  InvertMode { InvertRgb , InvertRgba }
 
enum  Format {
  Format_Invalid , Format_Mono , Format_MonoLSB , Format_Indexed8 ,
  Format_RGB32 , Format_ARGB32 , Format_ARGB32_Premultiplied , Format_RGB16 ,
  Format_ARGB8565_Premultiplied , Format_RGB666 , Format_ARGB6666_Premultiplied , Format_RGB555 ,
  Format_ARGB8555_Premultiplied , Format_RGB888 , Format_RGB444 , Format_ARGB4444_Premultiplied ,
  Format_RGBX8888 , Format_RGBA8888 , Format_RGBA8888_Premultiplied , Format_BGR30 ,
  Format_A2BGR30_Premultiplied , Format_RGB30 , Format_A2RGB30_Premultiplied , Format_Alpha8 ,
  Format_Grayscale8 , Format_RGBX64 , Format_RGBA64 , Format_RGBA64_Premultiplied ,
  Format_Grayscale16 , Format_BGR888 , Format_RGBX16FPx4 , Format_RGBA16FPx4 ,
  Format_RGBA16FPx4_Premultiplied , Format_RGBX32FPx4 , Format_RGBA32FPx4 , Format_RGBA32FPx4_Premultiplied ,
  NImageFormats
}
 
typedef QImageDataDataPtr
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM ,
  PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY ,
  PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled
}
 

Public Member Functions

 QImage () noexcept
 
 QImage (const QSize &size, Format format)
 
 QImage (int width, int height, Format format)
 
 QImage (uchar *data, int width, int height, Format format, QImageCleanupFunction cleanupFunction=nullptr, void *cleanupInfo=nullptr)
 
 QImage (const uchar *data, int width, int height, Format format, QImageCleanupFunction cleanupFunction=nullptr, void *cleanupInfo=nullptr)
 
 QImage (uchar *data, int width, int height, qsizetype bytesPerLine, Format format, QImageCleanupFunction cleanupFunction=nullptr, void *cleanupInfo=nullptr)
 
 QImage (const uchar *data, int width, int height, qsizetype bytesPerLine, Format format, QImageCleanupFunction cleanupFunction=nullptr, void *cleanupInfo=nullptr)
 
 QImage (const char *const xpm[])
 
 QImage (const QString &fileName, const char *format=nullptr)
 
 QImage (const QImage &)
 
 QImage (QImage &&other) noexcept
 
 ~QImage ()
 
QImageoperator= (const QImage &)
 
void swap (QImage &other) noexcept
 
bool isNull () const
 
int devType () const override
 
bool operator== (const QImage &) const
 
bool operator!= (const QImage &) const
 
 operator QVariant () const
 
void detach ()
 
bool isDetached () const
 
QImage copy (const QRect &rect=QRect()) const
 
QImage copy (int x, int y, int w, int h) const
 
Format format () const
 
QImage convertToFormat (Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
 
QImage convertToFormat (Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) &&
 
QImage convertToFormat (Format f, const QList< QRgb > &colorTable, Qt::ImageConversionFlags flags=Qt::AutoColor) const
 
bool reinterpretAsFormat (Format f)
 
QImage convertedTo (Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
 
QImage convertedTo (Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) &&
 
void convertTo (Format f, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
int width () const
 
int height () const
 
QSize size () const
 
QRect rect () const
 
int depth () const
 
int colorCount () const
 
int bitPlaneCount () const
 
QRgb color (int i) const
 
void setColor (int i, QRgb c)
 
void setColorCount (int)
 
bool allGray () const
 
bool isGrayscale () const
 
ucharbits ()
 
const ucharbits () const
 
const ucharconstBits () const
 
qsizetype sizeInBytes () const
 
ucharscanLine (int)
 
const ucharscanLine (int) const
 
const ucharconstScanLine (int) const
 
qsizetype bytesPerLine () const
 
bool valid (int x, int y) const
 
bool valid (const QPoint &pt) const
 
int pixelIndex (int x, int y) const
 
int pixelIndex (const QPoint &pt) const
 
QRgb pixel (int x, int y) const
 
QRgb pixel (const QPoint &pt) const
 
void setPixel (int x, int y, uint index_or_rgb)
 
void setPixel (const QPoint &pt, uint index_or_rgb)
 
QColor pixelColor (int x, int y) const
 
QColor pixelColor (const QPoint &pt) const
 
void setPixelColor (int x, int y, const QColor &c)
 
void setPixelColor (const QPoint &pt, const QColor &c)
 
QList< QRgbcolorTable () const
 
void setColorTable (const QList< QRgb > &colors)
 
qreal devicePixelRatio () const
 
void setDevicePixelRatio (qreal scaleFactor)
 
QSizeF deviceIndependentSize () const
 
void fill (uint pixel)
 
void fill (const QColor &color)
 
void fill (Qt::GlobalColor color)
 
bool hasAlphaChannel () const
 
void setAlphaChannel (const QImage &alphaChannel)
 
QImage createAlphaMask (Qt::ImageConversionFlags flags=Qt::AutoColor) const
 
QImage createHeuristicMask (bool clipTight=true) const
 
QImage createMaskFromColor (QRgb color, Qt::MaskMode mode=Qt::MaskInColor) const
 
QImage scaled (int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QImage scaled (const QSize &s, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QImage scaledToWidth (int w, Qt::TransformationMode mode=Qt::FastTransformation) const
 [9] More...
 
QImage scaledToHeight (int h, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QImage transformed (const QTransform &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QImage mirrored (bool horizontally=false, bool vertically=true) const &
 
QImage mirrored (bool horizontally=false, bool vertically=true) &&
 
QImage rgbSwapped () const &
 
QImage rgbSwapped () &&
 
void mirror (bool horizontally=false, bool vertically=true)
 
void rgbSwap ()
 
void invertPixels (InvertMode=InvertRgb)
 
QColorSpace colorSpace () const
 
QImage convertedToColorSpace (const QColorSpace &) const
 
void convertToColorSpace (const QColorSpace &)
 
void setColorSpace (const QColorSpace &)
 
void applyColorTransform (const QColorTransform &transform)
 
bool load (QIODevice *device, const char *format)
 
bool load (const QString &fileName, const char *format=nullptr)
 
bool loadFromData (QByteArrayView data, const char *format=nullptr)
 
bool loadFromData (const uchar *buf, int len, const char *format=nullptr)
 
bool loadFromData (const QByteArray &data, const char *format=nullptr)
 
bool save (const QString &fileName, const char *format=nullptr, int quality=-1) const
 
bool save (QIODevice *device, const char *format=nullptr, int quality=-1) const
 
qint64 cacheKey () const
 
QPaintEnginepaintEngine () const override
 
int dotsPerMeterX () const
 
int dotsPerMeterY () const
 
void setDotsPerMeterX (int)
 
void setDotsPerMeterY (int)
 
QPoint offset () const
 
void setOffset (const QPoint &)
 
QStringList textKeys () const
 
QString text (const QString &key=QString()) const
 
void setText (const QString &key, const QString &value)
 
QPixelFormat pixelFormat () const noexcept
 
DataPtrdata_ptr ()
 
- Public Member Functions inherited from QPaintDevice
virtual ~QPaintDevice ()
 
bool paintingActive () const
 
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 QTransform trueMatrix (const QTransform &, int w, int h)
 
static QImage fromData (QByteArrayView data, const char *format=nullptr)
 
static QImage fromData (const uchar *data, int size, const char *format=nullptr)
 
static QImage fromData (const QByteArray &data, const char *format=nullptr)
 
static QPixelFormat toPixelFormat (QImage::Format format) noexcept
 
static QImage::Format toImageFormat (QPixelFormat format) noexcept
 
- Static Public Member Functions inherited from QPaintDevice
static qreal devicePixelRatioFScale ()
 

Protected Member Functions

virtual int metric (PaintDeviceMetric metric) const override
 
QImage mirrored_helper (bool horizontal, bool vertical) const
 
QImage rgbSwapped_helper () const
 
void mirrored_inplace (bool horizontal, bool vertical)
 
void rgbSwapped_inplace ()
 
QImage convertToFormat_helper (Format format, Qt::ImageConversionFlags flags) const
 
bool convertToFormat_inplace (Format format, Qt::ImageConversionFlags flags)
 
QImage smoothScaled (int w, int h) const
 
- Protected Member Functions inherited from QPaintDevice
 QPaintDevice () noexcept
 
virtual void initPainter (QPainter *painter) const
 
virtual QPaintDeviceredirected (QPoint *offset) const
 
virtual QPaintersharedPainter () const
 

Friends

class QRasterPlatformPixmap
 
class QBlittablePlatformPixmap
 
class QPixmapCacheEntry
 
struct QImageData
 

Related Functions

(Note that these are not member functions.)

 QImageCleanupFunction
 
QDataStreamoperator<< (QDataStream &stream, const QImage &image)
 
QDataStreamoperator>> (QDataStream &stream, QImage &image)
 

Additional Inherited Members

- Protected Attributes inherited from QPaintDevice
ushort painters
 

Detailed Description

The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.

\inmodule QtGui

\reentrant

Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. Finally, the QPicture class is a paint device that records and replays QPainter commands.

Because QImage is a QPaintDevice subclass, QPainter can be used to draw directly onto images. When using QPainter on a QImage, the painting can be performed in another thread than the current GUI thread.

The QImage class supports several image formats described by the \l Format enum. These include monochrome, 8-bit, 32-bit and alpha-blended images which are available in all versions of Qt 4.x.

QImage provides a collection of functions that can be used to obtain a variety of information about the image. There are also several functions that enables transformation of the image.

QImage objects can be passed around by value since the QImage class uses \l{Implicit Data Sharing}{implicit data sharing}. QImage objects can also be streamed and compared.

Note
If you would like to load QImage objects in a static build of Qt, refer to the \l{How to Create Qt Plugins}{Plugin HowTo}.
Warning
Painting on a QImage with the format QImage::Format_Indexed8 is not supported.

Definition at line 72 of file qimage.h.

Member Typedef Documentation

◆ DataPtr

Definition at line 340 of file qimage.h.

Member Enumeration Documentation

◆ Format

The following image formats are available in Qt. See the notes after the table.

\value Format_Invalid The image is invalid. \value Format_Mono The image is stored using 1-bit per pixel. Bytes are packed with the most significant bit (MSB) first. \value Format_MonoLSB The image is stored using 1-bit per pixel. Bytes are packed with the less significant bit (LSB) first.

\value Format_Indexed8 The image is stored using 8-bit indexes into a colormap.

\value Format_RGB32 The image is stored using a 32-bit RGB format (0xffRRGGBB).

\value Format_ARGB32 The image is stored using a 32-bit ARGB format (0xAARRGGBB).

\value Format_ARGB32_Premultiplied The image is stored using a premultiplied 32-bit ARGB format (0xAARRGGBB), i.e. the red, green, and blue channels are multiplied by the alpha component divided by 255. (If RR, GG, or BB has a higher value than the alpha channel, the results are undefined.) Certain operations (such as image composition using alpha blending) are faster using premultiplied ARGB32 than with plain ARGB32.

\value Format_RGB16 The image is stored using a 16-bit RGB format (5-6-5).

\value Format_ARGB8565_Premultiplied The image is stored using a premultiplied 24-bit ARGB format (8-5-6-5). \value Format_RGB666 The image is stored using a 24-bit RGB format (6-6-6). The unused most significant bits is always zero. \value Format_ARGB6666_Premultiplied The image is stored using a premultiplied 24-bit ARGB format (6-6-6-6). \value Format_RGB555 The image is stored using a 16-bit RGB format (5-5-5). The unused most significant bit is always zero. \value Format_ARGB8555_Premultiplied The image is stored using a premultiplied 24-bit ARGB format (8-5-5-5). \value Format_RGB888 The image is stored using a 24-bit RGB format (8-8-8). \value Format_RGB444 The image is stored using a 16-bit RGB format (4-4-4). The unused bits are always zero. \value Format_ARGB4444_Premultiplied The image is stored using a premultiplied 16-bit ARGB format (4-4-4-4). \value Format_RGBX8888 The image is stored using a 32-bit byte-ordered RGB(x) format (8-8-8-8). This is the same as the Format_RGBA8888 except alpha must always be 255. (added in Qt 5.2) \value Format_RGBA8888 The image is stored using a 32-bit byte-ordered RGBA format (8-8-8-8). Unlike ARGB32 this is a byte-ordered format, which means the 32bit encoding differs between big endian and little endian architectures, being respectively (0xRRGGBBAA) and (0xAABBGGRR). The order of the colors is the same on any architecture if read as bytes 0xRR,0xGG,0xBB,0xAA. (added in Qt 5.2) \value Format_RGBA8888_Premultiplied The image is stored using a premultiplied 32-bit byte-ordered RGBA format (8-8-8-8). (added in Qt 5.2) \value Format_BGR30 The image is stored using a 32-bit BGR format (x-10-10-10). (added in Qt 5.4) \value Format_A2BGR30_Premultiplied The image is stored using a 32-bit premultiplied ABGR format (2-10-10-10). (added in Qt 5.4) \value Format_RGB30 The image is stored using a 32-bit RGB format (x-10-10-10). (added in Qt 5.4) \value Format_A2RGB30_Premultiplied The image is stored using a 32-bit premultiplied ARGB format (2-10-10-10). (added in Qt 5.4) \value Format_Alpha8 The image is stored using an 8-bit alpha only format. (added in Qt 5.5) \value Format_Grayscale8 The image is stored using an 8-bit grayscale format. (added in Qt 5.5) \value Format_Grayscale16 The image is stored using an 16-bit grayscale format. (added in Qt 5.13) \value Format_RGBX64 The image is stored using a 64-bit halfword-ordered RGB(x) format (16-16-16-16). This is the same as the Format_RGBA64 except alpha must always be 65535. (added in Qt 5.12) \value Format_RGBA64 The image is stored using a 64-bit halfword-ordered RGBA format (16-16-16-16). (added in Qt 5.12) \value Format_RGBA64_Premultiplied The image is stored using a premultiplied 64-bit halfword-ordered RGBA format (16-16-16-16). (added in Qt 5.12) \value Format_BGR888 The image is stored using a 24-bit BGR format. (added in Qt 5.14) \value Format_RGBX16FPx4 The image is stored using a 4 16-bit halfword floating point RGBx format (16FP-16FP-16FP-16FP). This is the same as the Format_RGBA16FPx4 except alpha must always be 1.0. (added in Qt 6.2) \value Format_RGBA16FPx4 The image is stored using a 4 16-bit halfword floating point RGBA format (16FP-16FP-16FP-16FP). (added in Qt 6.2) \value Format_RGBA16FPx4_Premultiplied The image is stored using a premultiplied 4 16-bit halfword floating point RGBA format (16FP-16FP-16FP-16FP). (added in Qt 6.2) \value Format_RGBX32FPx4 The image is stored using a 4 32-bit floating point RGBx format (32FP-32FP-32FP-32FP). This is the same as the Format_RGBA32FPx4 except alpha must always be 1.0. (added in Qt 6.2) \value Format_RGBA32FPx4 The image is stored using a 4 32-bit floating point RGBA format (32FP-32FP-32FP-32FP). (added in Qt 6.2) \value Format_RGBA32FPx4_Premultiplied The image is stored using a premultiplied 4 32-bit floating point RGBA format (32FP-32FP-32FP-32FP). (added in Qt 6.2)

Note
Drawing into a QImage with QImage::Format_Indexed8 is not supported.
Avoid most rendering directly to most of these formats using QPainter. Rendering is best optimized to the Format_RGB32 and Format_ARGB32_Premultiplied formats, and secondarily for rendering to the Format_RGB16, Format_RGBX8888, Format_RGBA8888_Premultiplied, Format_RGBX64 and Format_RGBA64_Premultiplied formats
See also
format(), convertToFormat()
Enumerator
Format_Invalid 
Format_Mono 
Format_MonoLSB 
Format_Indexed8 
Format_RGB32 
Format_ARGB32 
Format_ARGB32_Premultiplied 
Format_RGB16 
Format_ARGB8565_Premultiplied 
Format_RGB666 
Format_ARGB6666_Premultiplied 
Format_RGB555 
Format_ARGB8555_Premultiplied 
Format_RGB888 
Format_RGB444 
Format_ARGB4444_Premultiplied 
Format_RGBX8888 
Format_RGBA8888 
Format_RGBA8888_Premultiplied 
Format_BGR30 
Format_A2BGR30_Premultiplied 
Format_RGB30 
Format_A2RGB30_Premultiplied 
Format_Alpha8 
Format_Grayscale8 
Format_RGBX64 
Format_RGBA64 
Format_RGBA64_Premultiplied 
Format_Grayscale16 
Format_BGR888 
Format_RGBX16FPx4 
Format_RGBA16FPx4 
Format_RGBA16FPx4_Premultiplied 
Format_RGBX32FPx4 
Format_RGBA32FPx4 
Format_RGBA32FPx4_Premultiplied 
NImageFormats 

Definition at line 77 of file qimage.h.

◆ InvertMode

This enum type is used to describe how pixel values should be inverted in the invertPixels() function.

\value InvertRgb Invert only the RGB values and leave the alpha channel unchanged.

\value InvertRgba Invert all channels, including the alpha channel.

See also
invertPixels()
Enumerator
InvertRgb 
InvertRgba 

Definition at line 76 of file qimage.h.

Constructor & Destructor Documentation

◆ QImage() [1/11]

QImage::QImage ( )
noexcept

Constructs a null image.

See also
isNull()

Definition at line 788 of file qimage.cpp.

Here is the caller graph for this function:

◆ QImage() [2/11]

QImage::QImage ( const QSize size,
Format  format 
)

Constructs an image with the given size and format.

A \l{isNull()}{null} image is returned if memory cannot be allocated.

Warning
This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter.

Definition at line 818 of file qimage.cpp.

Here is the call graph for this function:

◆ QImage() [3/11]

QImage::QImage ( int  width,
int  height,
Format  format 
)

Constructs an image with the given width, height and format.

A \l{isNull()}{null} image will be returned if memory cannot be allocated.

Warning
This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter.

Definition at line 804 of file qimage.cpp.

◆ QImage() [4/11]

QImage::QImage ( uchar data,
int  width,
int  height,
Format  format,
QImageCleanupFunction  cleanupFunction = nullptr,
void cleanupInfo = nullptr 
)

Constructs an image with the given width, height and format, that uses an existing memory buffer, data. The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.

The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.

If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setColorCount() or setColorTable() before the image is used.

Definition at line 885 of file qimage.cpp.

◆ QImage() [5/11]

QImage::QImage ( const uchar data,
int  width,
int  height,
Format  format,
QImageCleanupFunction  cleanupFunction = nullptr,
void cleanupInfo = nullptr 
)

Constructs an image with the given width, height and format, that uses an existing read-only memory buffer, data. The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.

The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.

If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setColorCount() or setColorTable() before the image is used.

Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, calling QImage::bits() will return a deep copy of the image, rather than the buffer passed to the constructor. This allows for the efficiency of constructing a QImage from raw data, without the possibility of the raw data being changed.

Definition at line 916 of file qimage.cpp.

◆ QImage() [6/11]

QImage::QImage ( uchar data,
int  width,
int  height,
qsizetype  bytesPerLine,
Format  format,
QImageCleanupFunction  cleanupFunction = nullptr,
void cleanupInfo = nullptr 
)

Constructs an image with the given width, height and format, that uses an existing memory buffer, data. The width and height must be specified in pixels. bytesPerLine specifies the number of bytes per line (stride).

The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.

If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setColorCount() or setColorTable() before the image is used.

Definition at line 940 of file qimage.cpp.

◆ QImage() [7/11]

QImage::QImage ( const uchar data,
int  width,
int  height,
qsizetype  bytesPerLine,
Format  format,
QImageCleanupFunction  cleanupFunction = nullptr,
void cleanupInfo = nullptr 
)

Constructs an image with the given width, height and format, that uses an existing memory buffer, data. The width and height must be specified in pixels. bytesPerLine specifies the number of bytes per line (stride).

The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.

If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setColorCount() or setColorTable() before the image is used.

Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, calling QImage::bits() will return a deep copy of the image, rather than the buffer passed to the constructor. This allows for the efficiency of constructing a QImage from raw data, without the possibility of the raw data being changed.

Definition at line 971 of file qimage.cpp.

◆ QImage() [8/11]

QImage::QImage ( const char *const  xpm[])
explicit

Constructs an image from the given xpm image.

Make sure that the image is a valid XPM image. Errors are silently ignored.

Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:

The extra const makes the entire definition read-only, which is slightly more efficient (e.g., when the code is in a shared library) and able to be stored in ROM with the application.

Definition at line 1023 of file qimage.cpp.

Here is the call graph for this function:

◆ QImage() [9/11]

QImage::QImage ( const QString fileName,
const char *  format = nullptr 
)
explicit

Constructs an image and tries to load the image from the file with the given fileName.

The loader attempts to read the image using the specified format. If the format is not specified (which is the default), it is auto-detected based on the file's suffix and header. For details, see {QImageReader::setAutoDetectImageFormat()}{QImageReader}.

If the loading of the image failed, this object is a null image.

The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the \l{resources.html}{Resource System} overview for details on how to embed images and other resource files in the application's executable.

See also
isNull(), {QImage::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 997 of file qimage.cpp.

Here is the call graph for this function:

◆ QImage() [10/11]

QImage::QImage ( const QImage image)

Constructs a shallow copy of the given image.

For more information about shallow copies, see the \l {Implicit Data Sharing} documentation.

See also
copy()

Definition at line 1044 of file qimage.cpp.

Here is the call graph for this function:

◆ QImage() [11/11]

QImage::QImage ( QImage &&  other)
inlinenoexcept

Move-constructs a QImage instance, making it point at the same object that other was pointing to.

Since
5.2

Definition at line 134 of file qimage.h.

◆ ~QImage()

QImage::~QImage ( )

Destroys the image and cleans up.

Definition at line 1061 of file qimage.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ allGray()

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 false.

Note that this function is slow for images without color table.

See also
isGrayscale()

Definition at line 2827 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyColorTransform()

void QImage::applyColorTransform ( const QColorTransform transform)
Since
5.14

Applies the color transformation transform to all pixels in the image.

Definition at line 5013 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bitPlaneCount()

int QImage::bitPlaneCount ( ) const
Since
4.7 Returns the number of bit planes in the image.

The number of bit planes is the number of bits of color and transparency information for each pixel. This is different from (i.e. smaller than) the depth when the image format contains unused bits.

See also
depth(), format(), {QImage::Image Formats}{Image Formats}

Definition at line 4562 of file qimage.cpp.

Here is the call graph for this function:

◆ bits() [1/2]

uchar * QImage::bits ( )

Returns a pointer to the first pixel data. This is equivalent to scanLine(0).

Note that QImage uses \l{Implicit Data Sharing} {implicit data sharing}. This function performs a deep copy of the shared pixel data, thus ensuring that this QImage is the only one using the current return value.

See also
scanLine(), sizeInBytes(), constBits()

Definition at line 1675 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bits() [2/2]

const uchar * QImage::bits ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note that QImage uses \l{Implicit Data Sharing} {implicit data sharing}, but this function does not perform a deep copy of the shared pixel data, because the returned data is const.

Definition at line 1695 of file qimage.cpp.

◆ bytesPerLine()

qsizetype QImage::bytesPerLine ( ) const

Returns the number of bytes per image scanline.

This is equivalent to sizeInBytes() / height() if height() is non-zero.

See also
scanLine()

Definition at line 1536 of file qimage.cpp.

Here is the caller graph for this function:

◆ cacheKey()

qint64 QImage::cacheKey ( ) const

Returns a number that identifies the contents of this QImage object. Distinct QImage objects can only have the same key if they refer to the same contents.

The key will change when the image is altered.

Definition at line 4457 of file qimage.cpp.

Here is the caller graph for this function:

◆ color()

QRgb QImage::color ( int  i) const

Returns the color in the color table at index i. The first color is at index 0.

The colors in an image's color table are specified as ARGB quadruplets (QRgb). Use the qAlpha(), qRed(), qGreen(), and qBlue() functions to get the color value components.

See also
setColor(), pixelIndex(), {QImage::Pixel Manipulation}{Pixel Manipulation}

Definition at line 1553 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ colorCount()

int QImage::colorCount ( ) const
Since
4.6

Returns the size of the color table for the image.

Notice that colorCount() returns 0 for 32-bpp images because these images do not use color tables, but instead encode pixel values as ARGB quadruplets.

See also
setColorCount(), {QImage::Image Information}{Image Information}

Definition at line 1402 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ colorSpace()

QColorSpace QImage::colorSpace ( ) const
Since
5.14

Returns the color space of the image if a color space is defined.

Definition at line 5001 of file qimage.cpp.

Here is the caller graph for this function:

◆ colorTable()

QList< QRgb > QImage::colorTable ( ) const

Returns a list of the colors contained in the image's color table, or an empty list if the image does not have a color table

See also
setColorTable(), colorCount(), color()

Definition at line 1444 of file qimage.cpp.

Here is the caller graph for this function:

◆ constBits()

const uchar * QImage::constBits ( ) const

Returns a pointer to the first pixel data.

Note that QImage uses \l{Implicit Data Sharing} {implicit data sharing}, but this function does not perform a deep copy of the shared pixel data, because the returned data is const.

See also
bits(), constScanLine()
Since
4.7

Definition at line 1711 of file qimage.cpp.

Here is the caller graph for this function:

◆ constScanLine()

const uchar * QImage::constScanLine ( int  i) const

Returns a pointer to the pixel data at the scanline with index i. The first scanline is at index 0.

The scanline data is as minimum 32-bit aligned. For 64-bit formats it follows the native alignment of 64-bit integers (64-bit for most platforms, but notably 32-bit on i386).

Note that QImage uses \l{Implicit Data Sharing} {implicit data sharing}, but this function does not perform a deep copy of the shared pixel data, because the returned data is const.

See also
scanLine(), constBits()
Since
4.7

Definition at line 1655 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convertedTo() [1/2]

QImage QImage::convertedTo ( Format  f,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
) &&
inline

Definition at line 175 of file qimage.h.

◆ convertedTo() [2/2]

QImage QImage::convertedTo ( Format  f,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
) const &
inline

Definition at line 173 of file qimage.h.

◆ convertedToColorSpace()

QImage QImage::convertedToColorSpace ( const QColorSpace colorSpace) const
Since
5.14

Returns the image converted to colorSpace.

If the image has no valid color space, a null QImage is returned.

See also
convertToColorSpace()

Definition at line 4987 of file qimage.cpp.

Here is the call graph for this function:

◆ convertTo()

void QImage::convertTo ( Format  format,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
)
Since
5.13

Converts the image to the given format in place, detaching if necessary.

The specified image conversion flags control how the image data is handled during the conversion process.

See also
convertedTo()

Definition at line 2357 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convertToColorSpace()

void QImage::convertToColorSpace ( const QColorSpace colorSpace)
Since
5.14

Converts the image to colorSpace.

If the image has no valid color space, the method does nothing.

See also
convertedToColorSpace(), setColorSpace()

Definition at line 4962 of file qimage.cpp.

Here is the call graph for this function:

◆ convertToFormat() [1/3]

QImage QImage::convertToFormat ( Format  format,
const QList< QRgb > &  colorTable,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
) 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 copy of the image converted to the given format, using the specified colorTable.

Conversion from RGB formats to indexed formats is a slow operation and will use a straightforward nearest color approach, with no dithering.

Definition at line 2287 of file qimage.cpp.

Here is the call graph for this function:

◆ convertToFormat() [2/3]

QImage QImage::convertToFormat ( Format  f,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
) &&
inline

Definition at line 162 of file qimage.h.

◆ convertToFormat() [3/3]

QImage QImage::convertToFormat ( Format  f,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
) const &
inline

Definition at line 160 of file qimage.h.

Here is the caller graph for this function:

◆ convertToFormat_helper()

QImage QImage::convertToFormat_helper ( Format  format,
Qt::ImageConversionFlags  flags 
) const
protected

Definition at line 2152 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convertToFormat_inplace()

bool QImage::convertToFormat_inplace ( Format  format,
Qt::ImageConversionFlags  flags 
)
protected

Definition at line 2199 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy() [1/2]

QImage QImage::copy ( const QRect rectangle = QRect()) const

Returns a sub-area of the image as a new image.

The returned image is copied from the position ({rectangle}.x(), {rectangle}.y()) in this image, and will always have the size of the given rectangle.

In areas beyond this image, pixels are set to 0. For 32-bit RGB images, this means black; for 32-bit ARGB images, this means transparent black; for 8-bit images, this means the color with index 0 in the color table which can be anything; for 1-bit images, this means Qt::color0.

If the given rectangle is a null rectangle the entire image is copied.

See also
QImage()

Definition at line 1197 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy() [2/2]

QImage QImage::copy ( int  x,
int  y,
int  width,
int  height 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The returned image is copied from the position (x, y) in this image, and will always have the given width and height. In areas beyond this image, pixels are set to 0.

Definition at line 155 of file qimage.h.

Here is the caller graph for this function:

◆ createAlphaMask()

QImage QImage::createAlphaMask ( Qt::ImageConversionFlags  flags = Qt::AutoColor) const

Builds and returns a 1-bpp mask from the alpha buffer in this image. Returns a null image if the image's format is QImage::Format_RGB32.

The flags argument is a bitwise-OR of the Qt::ImageConversionFlags, and controls the conversion process. Passing 0 for flags sets all the default options.

The returned image has little-endian bit order (i.e. the image's format is QImage::Format_MonoLSB), which you can convert to big-endian (QImage::Format_Mono) using the convertToFormat() function.

See also
createHeuristicMask(), {QImage::Image Transformations}{Image Transformations}

Definition at line 3068 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createHeuristicMask()

QImage QImage::createHeuristicMask ( bool  clipTight = true) const

Creates and returns a 1-bpp heuristic mask for this image.

The function 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. 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 (i.e. the image's format is QImage::Format_MonoLSB), which you can convert to big-endian (QImage::Format_Mono) using the convertToFormat() function.

If clipTight is true (the default) the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels.

Note that this function disregards the alpha buffer.

See also
createAlphaMask(), {QImage::Image Transformations}{Image Transformations}

Definition at line 3112 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createMaskFromColor()

QImage QImage::createMaskFromColor ( QRgb  color,
Qt::MaskMode  mode = Qt::MaskInColor 
) const

Creates and returns a mask for this image based on the given color value. If the mode is MaskInColor (the default value), all pixels matching color will be opaque pixels in the mask. If mode is MaskOutColor, all pixels matching the given color will be transparent.

See also
createAlphaMask(), createHeuristicMask()

Definition at line 3216 of file qimage.cpp.

Here is the call graph for this function:

◆ data_ptr()

DataPtr & QImage::data_ptr ( )
inline

Definition at line 341 of file qimage.h.

Here is the caller graph for this function:

◆ depth()

int QImage::depth ( ) const

Returns the depth of the image.

The image depth is the number of bits used to store a single pixel, also called bits per pixel (bpp).

The supported depths are 1, 8, 16, 24, 32 and 64.

See also
bitPlaneCount(), convertToFormat(), {QImage::Image Formats}{Image Formats}, {QImage::Image Information}{Image Information}

Definition at line 1385 of file qimage.cpp.

Here is the caller graph for this function:

◆ detach()

void QImage::detach ( )

Definition at line 1126 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deviceIndependentSize()

QSizeF QImage::deviceIndependentSize ( ) const

Returns the size of the pixmap in device independent pixels.

This value should be used when using the pixmap size in user interface size calculations.

The return value is equivalent to pixmap.size() / pixmap.devicePixelRatio(),

Definition at line 1509 of file qimage.cpp.

Here is the caller graph for this function:

◆ devicePixelRatio()

qreal QImage::devicePixelRatio ( ) const

Returns the device pixel ratio for the image. This is the ratio between {device pixels} and {device independent pixels}.

Use this function when calculating layout geometry based on the image size: QSize layoutSize = image.size() / image.devicePixelRatio()

The default value is 1.0.

See also
setDevicePixelRatio(), QImageReader

Definition at line 1460 of file qimage.cpp.

Here is the caller graph for this function:

◆ devType()

int QImage::devType ( ) const
overridevirtual

Reimplemented from QPaintDevice.

Definition at line 1102 of file qimage.cpp.

◆ dotsPerMeterX()

int QImage::dotsPerMeterX ( ) const

Returns the number of pixels that fit horizontally in a physical meter. Together with dotsPerMeterY(), this number defines the intended scale and aspect ratio of the image.

See also
setDotsPerMeterX(), {QImage::Image Information}{Image Information}

Definition at line 4036 of file qimage.cpp.

Here is the call graph for this function:

◆ dotsPerMeterY()

int QImage::dotsPerMeterY ( ) const

Returns the number of pixels that fit vertically in a physical meter. Together with dotsPerMeterX(), this number defines the intended scale and aspect ratio of the image.

See also
setDotsPerMeterY(), {QImage::Image Information}{Image Information}

Definition at line 4049 of file qimage.cpp.

Here is the call graph for this function:

◆ fill() [1/3]

void QImage::fill ( const QColor color)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Fills the entire image with the given color.

If the depth of the image is 1, the image will be filled with 1 if color equals Qt::color1; it will otherwise be filled with 0.

If the depth of the image is 8, the image will be filled with the index corresponding the color in the color table if present; it will otherwise be filled with 0.

Since
4.8

Definition at line 1846 of file qimage.cpp.

Here is the call graph for this function:

◆ fill() [2/3]

void QImage::fill ( Qt::GlobalColor  color)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.8

Fills the image with the given color, described as a standard global color.

Definition at line 1822 of file qimage.cpp.

Here is the call graph for this function:

◆ fill() [3/3]

void QImage::fill ( uint  pixelValue)

Fills the entire image with the given pixelValue.

If the depth of this image is 1, only the lowest bit is used. If you say fill(0), fill(2), etc., the image is filled with 0s. If you say fill(1), fill(3), etc., the image is filled with 1s. If the depth is 8, the lowest 8 bits are used and if the depth is 16 the lowest 16 bits are used.

If the image depth is higher than 32bit the result is undefined.

Note
There are no corresponding value getter, though QImage::pixelIndex() will return the same value for indexed formats, and QImage::pixel() for RGB32, ARGB32, and ARGB32PM formats.
See also
depth(), {QImage::Image Transformations}{Image Transformations}

Definition at line 1736 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format()

QImage::Format QImage::format ( ) const

Returns the format of the image.

See also
{QImage::Image Formats}{Image Formats}

Definition at line 2119 of file qimage.cpp.

Here is the caller graph for this function:

◆ fromData() [1/3]

QImage QImage::fromData ( const QByteArray data,
const char *  format = nullptr 
)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Constructs a QImage from the given QByteArray data.

Definition at line 287 of file qimage.h.

◆ fromData() [2/3]

QImage QImage::fromData ( const uchar data,
int  size,
const char *  format = nullptr 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Constructs a QImage from the first size bytes of the given binary data.

Definition at line 3813 of file qimage.cpp.

Here is the call graph for this function:

◆ fromData() [3/3]

QImage QImage::fromData ( QByteArrayView  data,
const char *  format = nullptr 
)
static
Since
6.2

Constructs an image from the given QByteArrayView data. The loader attempts to read the image using the specified format. If format is not specified (which is the default), the loader probes the data for a header to guess the file format.

If format is specified, it must be one of the values returned by QImageReader::supportedImageFormats().

If the loading of the image fails, the image returned will be a null image.

See also
load(), save(), {QImage::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 3796 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasAlphaChannel()

bool QImage::hasAlphaChannel ( ) const

Returns true if the image has a format that respects the alpha channel, otherwise returns false.

See also
{QImage::Image Information}{Image Information}

Definition at line 4539 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ height()

int QImage::height ( ) const

Returns the height of the image.

See also
{QImage::Image Information}{Image Information}

Definition at line 1343 of file qimage.cpp.

Here is the caller graph for this function:

◆ invertPixels()

void QImage::invertPixels ( InvertMode  mode = InvertRgb)

Inverts all pixel values in the image.

The given invert mode only have a meaning when the image's depth is 32. The default mode is InvertRgb, which leaves the alpha channel unchanged. If the mode is InvertRgba, the alpha bits are also inverted.

Inverting an 8-bit image means to replace all pixels using color index i with a pixel using color index 255 minus i. The same is the case for a 1-bit image. Note that the color table is not changed.

If the image has a premultiplied alpha channel, the image is first converted to an unpremultiplied image format to be inverted and then converted back.

See also
{QImage::Image Transformations}{Image Transformations}

Definition at line 1943 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDetached()

bool QImage::isDetached ( ) const

Definition at line 4473 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isGrayscale()

bool QImage::isGrayscale ( ) const

For 32-bit images, this function is equivalent to allGray().

For color indexed images, this function returns true if color(i) is QRgb(i, i, i) for all indexes of the color table; otherwise returns false.

See also
allGray(), {QImage::Image Formats}{Image Formats}

Definition at line 2903 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNull()

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.

Definition at line 1319 of file qimage.cpp.

Here is the caller graph for this function:

◆ load() [1/2]

bool QImage::load ( const QString fileName,
const char *  format = nullptr 
)

Loads an image from the file with the given fileName. Returns true if the image was successfully loaded; otherwise invalidates the image and returns false.

The loader attempts to read the image using the specified format, e.g., PNG or JPG. If format is not specified (which is the default), it is auto-detected based on the file's suffix and header. For details, see QImageReader::setAutoDetectImageFormat().

The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the \l{resources.html}{Resource System} overview for details on how to embed images and other resource files in the application's executable.

See also
{QImage::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 3722 of file qimage.cpp.

Here is the call graph for this function:

◆ load() [2/2]

bool QImage::load ( QIODevice device,
const char *  format 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function reads a QImage from the given device. This can, for example, be used to load an image directly into a QByteArray.

Definition at line 3735 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFromData() [1/3]

bool QImage::loadFromData ( const QByteArray data,
const char *  format = nullptr 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Loads an image from the given QByteArray data.

Definition at line 279 of file qimage.h.

◆ loadFromData() [2/3]

bool QImage::loadFromData ( const uchar data,
int  len,
const char *  format = nullptr 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Loads an image from the first len bytes of the given binary data.

Definition at line 3768 of file qimage.cpp.

Here is the call graph for this function:

◆ loadFromData() [3/3]

bool QImage::loadFromData ( QByteArrayView  data,
const char *  format = nullptr 
)
Since
6.2

Loads an image from the given QByteArrayView data. Returns true if the image was successfully loaded; otherwise invalidates the image and returns false.

The loader attempts to read the image using the specified format, e.g., PNG or JPG. If format is not specified (which is the default), the loader probes the file for a header to guess the file format.

See also
{QImage::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 3754 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ metric()

int QImage::metric ( PaintDeviceMetric  metric) const
overrideprotectedvirtual

Reimplemented from QPaintDevice.

Definition at line 4228 of file qimage.cpp.

Here is the call graph for this function:

◆ mirror()

void QImage::mirror ( bool  horizontal = false,
bool  vertical = true 
)
inline
Since
6.0

Mirrors of the image in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false.

See also
mirrored(), {QImage::Image Transformations}{Image Transformations}

Definition at line 262 of file qimage.h.

◆ mirrored() [1/2]

QImage QImage::mirrored ( bool  horizontally = false,
bool  vertically = true 
) &&
inline

Definition at line 256 of file qimage.h.

◆ mirrored() [2/2]

QImage QImage::mirrored ( bool  horizontally = false,
bool  vertically = true 
) const &
inline

Definition at line 254 of file qimage.h.

Here is the caller graph for this function:

◆ mirrored_helper()

QImage QImage::mirrored_helper ( bool  horizontal,
bool  vertical 
) const
protected

Definition at line 3435 of file qimage.cpp.

Here is the call graph for this function:

◆ mirrored_inplace()

void QImage::mirrored_inplace ( bool  horizontal,
bool  vertical 
)
protected

Definition at line 3463 of file qimage.cpp.

Here is the call graph for this function:

◆ offset()

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.

See also
setOffset(), {QImage::Image Information}{Image Information}

Definition at line 4106 of file qimage.cpp.

Here is the caller graph for this function:

◆ operator QVariant()

QImage::operator QVariant ( ) const

Returns the image as a QVariant.

Definition at line 1110 of file qimage.cpp.

Here is the call graph for this function:

◆ operator!=()

bool QImage::operator!= ( const QImage image) const

Returns true if this image and the given image 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.

See also
operator=()

Definition at line 4020 of file qimage.cpp.

◆ operator=()

QImage & QImage::operator= ( const QImage image)

Move-assigns other to this QImage instance.

Since
5.2

Assigns a shallow copy of the given image to this image and returns a reference to this image.

For more information about shallow copies, see the \l {Implicit Data Sharing} documentation.

See also
copy(), QImage()

Definition at line 1077 of file qimage.cpp.

Here is the call graph for this function:

◆ operator==()

bool QImage::operator== ( const QImage image) const

Returns true if this image and the given image have the same contents; otherwise returns false.

The comparison can be slow, unless there is some obvious difference (e.g. different size or format), in which case the function will return quickly.

See also
operator=()

Definition at line 3955 of file qimage.cpp.

Here is the call graph for this function:

◆ paintEngine()

QPaintEngine * QImage::paintEngine ( ) const
overridevirtual

Implements QPaintDevice.

Definition at line 4205 of file qimage.cpp.

Here is the call graph for this function:

◆ pixel() [1/2]

QRgb QImage::pixel ( const QPoint position) const
inline

Returns the color of the pixel at the given position.

If the position is not valid, the results are undefined.

Warning
This function is expensive when used for massive pixel manipulations. Use constBits() or constScanLine() when many pixels needs to be read.
See also
setPixel(), valid(), constBits(), constScanLine(), {QImage::Pixel Manipulation}{Pixel Manipulation}

Definition at line 350 of file qimage.h.

Here is the call graph for this function:

◆ pixel() [2/2]

QRgb QImage::pixel ( int  x,
int  y 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns the color of the pixel at coordinates (x, y).

Definition at line 2451 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pixelColor() [1/2]

QColor QImage::pixelColor ( const QPoint position) const
inline
Since
5.6

Returns the color of the pixel at the given position as a QColor.

If the position is not valid, an invalid QColor is returned.

Warning
This function is expensive when used for massive pixel manipulations. Use constBits() or constScanLine() when many pixels needs to be read.
See also
setPixel(), valid(), constBits(), constScanLine(), {QImage::Pixel Manipulation}{Pixel Manipulation}

Definition at line 352 of file qimage.h.

Here is the call graph for this function:

◆ pixelColor() [2/2]

QColor QImage::pixelColor ( int  x,
int  y 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
5.6

Returns the color of the pixel at coordinates (x, y) as a QColor.

Definition at line 2664 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pixelFormat()

QPixelFormat QImage::pixelFormat ( ) const
noexcept

Returns the QImage::Format as a QPixelFormat

Definition at line 5626 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pixelIndex() [1/2]

int QImage::pixelIndex ( const QPoint position) const
inline

Returns the pixel index at the given position.

If position is not valid, or if the image is not a paletted image (depth() > 8), the results are undefined.

See also
valid(), depth(), {QImage::Pixel Manipulation}{Pixel Manipulation}

Definition at line 349 of file qimage.h.

Here is the call graph for this function:

◆ pixelIndex() [2/2]

int QImage::pixelIndex ( int  x,
int  y 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns the pixel index at (x, y).

Definition at line 2410 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rect()

QRect QImage::rect ( ) const

Returns the enclosing rectangle (0, 0, width(), height()) of the image.

See also
{QImage::Image Information}{Image Information}

Definition at line 1368 of file qimage.cpp.

Here is the caller graph for this function:

◆ reinterpretAsFormat()

bool QImage::reinterpretAsFormat ( Format  format)
Since
5.9

Changes the format of the image to format without changing the data. Only works between formats of the same depth.

Returns true if successful.

This function can be used to change images with alpha-channels to their corresponding opaque formats if the data is known to be opaque-only, or to change the format of a given image buffer before overwriting it with new data.

Warning
The function does not check if the image data is valid in the new format and will still return true if the depths are compatible. Operations on an image with invalid data are undefined.
If the image is not detached, this will cause the data to be copied.
See also
hasAlphaChannel(), convertToFormat()

Definition at line 2323 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rgbSwap()

void QImage::rgbSwap ( )
inline
Since
6.0

Swaps the values of the red and blue components of all pixels, effectively converting an RGB image to an BGR image.

See also
rgbSwapped(), {QImage::Image Transformations}{Image Transformations}

Definition at line 264 of file qimage.h.

◆ rgbSwapped() [1/2]

QImage QImage::rgbSwapped ( ) &&
inline

Definition at line 260 of file qimage.h.

◆ rgbSwapped() [2/2]

QImage QImage::rgbSwapped ( ) const &
inline

Definition at line 258 of file qimage.h.

Here is the caller graph for this function:

◆ rgbSwapped_helper()

QImage QImage::rgbSwapped_helper ( ) const
protected

Definition at line 3520 of file qimage.cpp.

Here is the call graph for this function:

◆ rgbSwapped_inplace()

void QImage::rgbSwapped_inplace ( )
protected

Definition at line 3614 of file qimage.cpp.

Here is the call graph for this function:

◆ save() [1/2]

bool QImage::save ( const QString fileName,
const char *  format = nullptr,
int  quality = -1 
) const

Saves the image to the file with the given fileName, using the given image file format and quality factor. If format is \nullptr, QImage will attempt to guess the format by looking at fileName's suffix.

The quality factor must be in the range 0 to 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.

See also
{QImage::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 3843 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save() [2/2]

bool QImage::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 QImage to the given device.

This can, for example, be used to save an image directly into a QByteArray:

Definition at line 3862 of file qimage.cpp.

Here is the call graph for this function:

◆ scaled() [1/2]

QImage QImage::scaled ( const QSize size,
Qt::AspectRatioMode  aspectRatioMode = Qt::IgnoreAspectRatio,
Qt::TransformationMode  transformMode = Qt::FastTransformation 
) const

Returns a copy of the image scaled to a rectangle defined by the given size according to the given aspectRatioMode and transformMode.

\list

  • If aspectRatioMode is Qt::IgnoreAspectRatio, the image is scaled to size.
  • If aspectRatioMode is Qt::KeepAspectRatio, the image is scaled to a rectangle as large as possible inside size, preserving the aspect ratio.
  • If aspectRatioMode is Qt::KeepAspectRatioByExpanding, the image is scaled to a rectangle as small as possible outside size, preserving the aspect ratio. \endlist

If the given size is empty, this function returns a null image.

See also
isNull(), {QImage::Image Transformations}{Image Transformations}

Definition at line 2968 of file qimage.cpp.

Here is the call graph for this function:

◆ scaled() [2/2]

QImage QImage::scaled ( int  width,
int  height,
Qt::AspectRatioMode  aspectRatioMode = Qt::IgnoreAspectRatio,
Qt::TransformationMode  transformMode = Qt::FastTransformation 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns a copy of the image scaled to a rectangle with the given width and height according to the given aspectRatioMode and transformMode.

If either the width or the height is zero or negative, this function returns a null image.

Definition at line 244 of file qimage.h.

Here is the call graph for this function:

◆ scaledToHeight()

QImage QImage::scaledToHeight ( int  height,
Qt::TransformationMode  mode = Qt::FastTransformation 
) const

Returns a scaled copy of the image. The returned image is scaled to the given height using the specified transformation mode.

This function automatically calculates the width of the image so that the ratio of the image is preserved.

If the given height is 0 or negative, a null image is returned.

See also
{QImage::Image Transformations}{Image Transformations}

Definition at line 3035 of file qimage.cpp.

Here is the call graph for this function:

◆ scaledToWidth()

QImage QImage::scaledToWidth ( int  width,
Qt::TransformationMode  mode = Qt::FastTransformation 
) const

[9]

[10]

Returns a scaled copy of the image. The returned image is scaled to the given width using the specified transformation mode.

This function automatically calculates the height of the image so that its aspect ratio is preserved.

If the given width is 0 or negative, a null image is returned.

See also
{QImage::Image Transformations}{Image Transformations}

Definition at line 3005 of file qimage.cpp.

Here is the call graph for this function:

◆ scanLine() [1/2]

uchar * QImage::scanLine ( int  i)

Returns a pointer to the pixel data at the scanline with index i. The first scanline is at index 0.

The scanline data is as minimum 32-bit aligned. For 64-bit formats it follows the native alignment of 64-bit integers (64-bit for most platforms, but notably 32-bit on i386).

For example, to remove the green component of each pixel in an image:

Warning
If you are accessing 32-bpp image data, cast the returned pointer to {QRgb*} (QRgb has a 32-bit size) and use it to read/write the pixel value. You cannot use the {uchar*} pointer directly, because the pixel format depends on the byte order on the underlying platform. Use qRed(), qGreen(), qBlue(), and qAlpha() to access the pixels.
See also
bytesPerLine(), bits(), {QImage::Pixel Manipulation}{Pixel Manipulation}, constScanLine()

Definition at line 1613 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanLine() [2/2]

const uchar * QImage::scanLine ( int  i) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1630 of file qimage.cpp.

Here is the call graph for this function:

◆ setAlphaChannel()

void QImage::setAlphaChannel ( const QImage alphaChannel)

Sets the alpha channel of this image to the given alphaChannel.

If alphaChannel is an 8 bit alpha image, the alpha values are used directly. Otherwise, alphaChannel is converted to 8 bit grayscale and the intensity of the pixel values is used.

If the image already has an alpha channel, the existing alpha channel is multiplied with the new one. If the image doesn't have an alpha channel it will be converted to a format that does.

The operation is similar to painting alphaChannel as an alpha image over this image using QPainter::CompositionMode_DestinationIn.

See also
hasAlphaChannel(), {QImage::Image Transformations}{Image Transformations}, {QImage::Image Formats}{Image Formats}

Definition at line 4498 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setColor()

void QImage::setColor ( int  index,
QRgb  colorValue 
)

Sets the color at the given index in the color table, to the given to colorValue. The color value is an ARGB quadruplet.

If index is outside the current size of the color table, it is expanded with setColorCount().

See also
color(), colorCount(), setColorTable(), {QImage::Pixel Manipulation}{Pixel Manipulation}

Definition at line 1571 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setColorCount()

void QImage::setColorCount ( int  colorCount)
Since
4.6 Resizes the color table to contain colorCount entries.

If the color table is expanded, all the extra colors will be set to transparent (i.e qRgba(0, 0, 0, 0)).

When the image is used, the color table must be large enough to have entries for all the pixel/index values present in the image, otherwise the results are undefined.

See also
colorCount(), colorTable(), setColor(), {QImage::Image Transformations}{Image Transformations}

Definition at line 2089 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setColorSpace()

void QImage::setColorSpace ( const QColorSpace colorSpace)
Since
5.14

Sets the image color space to colorSpace without performing any conversions on image data.

See also
colorSpace()

Definition at line 4942 of file qimage.cpp.

Here is the call graph for this function:

◆ setColorTable()

void QImage::setColorTable ( const QList< QRgb > &  colors)

Sets the color table used to translate color indexes to QRgb values, to the specified colors.

When the image is used, the color table must be large enough to have entries for all the pixel/index values present in the image, otherwise the results are undefined.

See also
colorTable(), setColor(), {QImage::Image Transformations}{Image Transformations}

Definition at line 1418 of file qimage.cpp.

◆ setDevicePixelRatio()

void QImage::setDevicePixelRatio ( qreal  scaleFactor)

Sets the device pixel ratio for the image. This is the ratio between image pixels and device-independent pixels.

The default scaleFactor is 1.0. Setting it to something else has two effects:

QPainters that are opened on the image will be scaled. For example, painting on a 200x200 image if with a ratio of 2.0 will result in effective (device-independent) painting bounds of 100x100.

Code paths in Qt that calculate layout geometry based on the image size will take the ratio into account: QSize layoutSize = image.size() / image.devicePixelRatio() The net effect of this is that the image is displayed as high-DPI image rather than a large image (see \l{Drawing High Resolution Versions of Pixmaps and Images}).

See also
devicePixelRatio(), deviceIndependentSize()

Definition at line 1488 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDotsPerMeterX()

void QImage::setDotsPerMeterX ( int  x)

Sets the number of pixels that fit horizontally in a physical meter, to x.

Together with dotsPerMeterY(), this number defines the intended scale and aspect ratio of the image, and determines the scale at which QPainter will draw graphics on the image. It does not change the scale or aspect ratio of the image when it is rendered on other paint devices.

See also
dotsPerMeterX(), {QImage::Image Information}{Image Information}

Definition at line 4066 of file qimage.cpp.

Here is the call graph for this function:

◆ setDotsPerMeterY()

void QImage::setDotsPerMeterY ( int  y)

Sets the number of pixels that fit vertically in a physical meter, to y.

Together with dotsPerMeterX(), this number defines the intended scale and aspect ratio of the image, and determines the scale at which QPainter will draw graphics on the image. It does not change the scale or aspect ratio of the image when it is rendered on other paint devices.

See also
dotsPerMeterY(), {QImage::Image Information}{Image Information}

Definition at line 4088 of file qimage.cpp.

Here is the call graph for this function:

◆ setOffset()

void QImage::setOffset ( const QPoint offset)

Sets the number of pixels by which the image is intended to be offset by when positioning relative to other images, to offset.

See also
offset(), {QImage::Image Information}{Image Information}

Definition at line 4120 of file qimage.cpp.

Here is the call graph for this function:

◆ setPixel() [1/2]

void QImage::setPixel ( const QPoint position,
uint  index_or_rgb 
)
inline

Sets the pixel index or color at the given position to index_or_rgb.

If the image's format is either monochrome or paletted, the given index_or_rgb value must be an index in the image's color table, otherwise the parameter must be a QRgb value.

If position is not a valid coordinate pair in the image, or if index_or_rgb >= colorCount() in the case of monochrome and paletted images, the result is undefined.

Warning
This function is expensive due to the call of the internal {detach()} function called within; if performance is a concern, we recommend the use of scanLine() or bits() to access pixel data directly.
See also
pixel(), {QImage::Pixel Manipulation}{Pixel Manipulation}

Definition at line 351 of file qimage.h.

Here is the call graph for this function:

◆ setPixel() [2/2]

void QImage::setPixel ( int  x,
int  y,
uint  index_or_rgb 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Sets the pixel index or color at (x, y) to index_or_rgb.

Definition at line 2546 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPixelColor() [1/2]

void QImage::setPixelColor ( const QPoint position,
const QColor color 
)
inline
Since
5.6

Sets the color at the given position to color.

If position is not a valid coordinate pair in the image, or the image's format is either monochrome or paletted, the result is undefined.

Warning
This function is expensive due to the call of the internal {detach()} function called within; if performance is a concern, we recommend the use of scanLine() or bits() to access pixel data directly.
See also
pixel(), bits(), scanLine(), {QImage::Pixel Manipulation}{Pixel Manipulation}

Definition at line 353 of file qimage.h.

Here is the call graph for this function:

◆ setPixelColor() [2/2]

void QImage::setPixelColor ( int  x,
int  y,
const QColor color 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
5.6

Sets the pixel color at (x, y) to color.

Definition at line 2743 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setText()

void QImage::setText ( const QString key,
const QString text 
)

Sets the image text to the given text and associate it with the given key.

If you just want to store a single text block (i.e., a "comment" or just a description), you can either pass an empty key, or use a generic key like "Description".

The image text is embedded into the image data when you call save() or QImageWriter::write().

Not all image formats support embedded text. You can find out if a specific image or format supports embedding text by using QImageWriter::supportsOption(). We give an example:

You can use QImageWriter::supportedImageFormats() to find out which image formats are available to you.

See also
text(), textKeys()

Definition at line 4190 of file qimage.cpp.

Here is the call graph for this function:

◆ size()

QSize QImage::size ( ) const

Returns the size of the image, i.e. its width() and height().

See also
{QImage::Image Information}{Image Information}, deviceIndependentSize()

Definition at line 1355 of file qimage.cpp.

Here is the caller graph for this function:

◆ sizeInBytes()

qsizetype QImage::sizeInBytes ( ) const
Since
5.10 Returns the image data size in bytes.
See also
bytesPerLine(), bits(), {QImage::Image Information}{Image Information}

Definition at line 1524 of file qimage.cpp.

Here is the caller graph for this function:

◆ smoothScaled()

QImage QImage::smoothScaled ( int  w,
int  h 
) const
protected

Definition at line 4615 of file qimage.cpp.

Here is the call graph for this function:

◆ swap()

void QImage::swap ( QImage other)
inlinenoexcept
Since
4.8

Swaps image other with this image. This operation is very fast and never fails.

Definition at line 141 of file qimage.h.

Here is the call graph for this function:

◆ text()

QString QImage::text ( const QString key = QString()) const

Returns the image text associated with the given key. If the specified key is an empty string, the whole image text is returned, with each key-text pair separated by a newline.

See also
setText(), textKeys()

Definition at line 4150 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textKeys()

QStringList QImage::textKeys ( ) const

Returns the text keys for this image.

You can use these keys with text() to list the image text for a certain key.

See also
text()

Definition at line 4138 of file qimage.cpp.

Here is the call graph for this function:

◆ toImageFormat()

QImage::Format QImage::toImageFormat ( QPixelFormat  format)
staticnoexcept

Converts format into a QImage::Format

Definition at line 5643 of file qimage.cpp.

Here is the caller graph for this function:

◆ toPixelFormat()

QPixelFormat QImage::toPixelFormat ( QImage::Format  format)
staticnoexcept

Converts format into a QPixelFormat

Definition at line 5634 of file qimage.cpp.

Here is the caller graph for this function:

◆ transformed()

QImage QImage::transformed ( const QTransform matrix,
Qt::TransformationMode  mode = Qt::FastTransformation 
) const

Returns a copy of the image that is transformed using the given transformation matrix and transformation mode.

The returned image will normally have the same {Image Formats}{format} as the original image. However, a complex transformation may result in an image where not all pixels are covered by the transformed pixels of the original image. In such cases, those background pixels will be assigned a transparent color value, and the transformed image will be given a format with an alpha channel, even if the original image did not have that.

The transformation matrix is internally adjusted to compensate for unwanted translation; i.e. the image produced is the smallest image that contains all the transformed points of the original image. Use the trueMatrix() function to retrieve the actual matrix used for transforming an image.

Unlike the other overload, this function can be used to perform perspective transformations on images.

See also
trueMatrix(), {QImage::Image Transformations}{Image Transformations}

Definition at line 4747 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trueMatrix()

QTransform QImage::trueMatrix ( const QTransform matrix,
int  width,
int  height 
)
static

Returns the actual matrix used for transforming an image with the given width, height and matrix.

When transforming an image using the transformed() function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. transformed() returns the smallest image containing all transformed points of the original image. This function returns the modified matrix, which maps points correctly from the original image into the new image.

Unlike the other overload, this function creates transformation matrices that can be used to perform perspective transformations on images.

See also
transformed(), {QImage::Image Transformations}{Image Transformations}

Definition at line 4927 of file qimage.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ valid() [1/2]

bool QImage::valid ( const QPoint pos) const
inline

Returns true if pos is a valid coordinate pair within the image; otherwise returns false.

See also
rect(), QRect::contains()

Definition at line 348 of file qimage.h.

◆ valid() [2/2]

bool QImage::valid ( int  x,
int  y 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns true if QPoint(x, y) is a valid coordinate pair within the image; otherwise returns false.

Definition at line 2387 of file qimage.cpp.

◆ width()

int QImage::width ( ) const

Returns the width of the image.

See also
{QImage::Image Information}{Image Information}

Definition at line 1331 of file qimage.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QImage image 
)
related

Writes the given image to the given stream as a PNG image, or as a BMP image if the stream's version is 1. Note that writing the stream to a file will not produce a valid image file.

See also
QImage::save(), {Serializing Qt Data Types}

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QImage image 
)
related

Reads an image from the given stream and stores it in the given image.

See also
QImage::load(), {Serializing Qt Data Types}

◆ QBlittablePlatformPixmap

friend class QBlittablePlatformPixmap
friend

Definition at line 335 of file qimage.h.

◆ QImageCleanupFunction()

QImageCleanupFunction
related
Since
5.0

A function with the following signature that can be used to implement basic image memory management:

void myImageCleanupHandler(void *info);
backing_store_ptr info
[4]
Definition: jmemsys.h:161

◆ QImageData

friend struct QImageData
friend

Definition at line 337 of file qimage.h.

◆ QPixmapCacheEntry

friend class QPixmapCacheEntry
friend

Definition at line 336 of file qimage.h.

◆ QRasterPlatformPixmap

friend class QRasterPlatformPixmap
friend

Definition at line 334 of file qimage.h.


The documentation for this class was generated from the following files: