Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QImage Class Reference

\inmodule QtGui More...

#include <qimage.h>

+ Inheritance diagram for QImage:
+ Collaboration diagram for QImage:

Public Types

enum  InvertMode { InvertRgb , InvertRgba }
 This enum type is used to describe how pixel values should be inverted in the invertPixels() function. More...
 
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 ,
  Format_CMYK8888 , NImageFormats
}
 The following image formats are available in Qt. More...
 
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
 Constructs a null image.
 
 QImage (const QSize &size, Format format)
 Constructs an image with the given size and format.
 
 QImage (int width, int height, Format format)
 Constructs an image with the given width, height and format.
 
 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.
 
 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.
 
 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.
 
 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.
 
 QImage (const char *const xpm[])
 Constructs an image from the given xpm image.
 
 QImage (const QString &fileName, const char *format=nullptr)
 Constructs an image and tries to load the image from the file with the given fileName.
 
 QImage (const QImage &)
 Constructs a shallow copy of the given image.
 
 QImage (QImage &&other) noexcept
 Move-constructs a QImage instance, making it point at the same object that other was pointing to.
 
 ~QImage ()
 Destroys the image and cleans up.
 
QImageoperator= (const QImage &)
 Move-assigns other to this QImage instance.
 
void swap (QImage &other) noexcept
 
bool isNull () const
 Returns true if it is a null image, otherwise returns false.
 
int devType () const override
 
bool operator== (const QImage &) const
 Returns true if this image and the given image have the same contents; otherwise returns false.
 
bool operator!= (const QImage &) const
 Returns true if this image and the given image have different contents; otherwise returns false.
 
 operator QVariant () const
 Returns the image as a QVariant.
 
void detach ()
 
bool isDetached () const
 
QImage copy (const QRect &rect=QRect()) const
 Returns a sub-area of the image as a new image.
 
QImage copy (int x, int y, int w, int h) const
 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.
 
Format format () const
 Returns the format of the image.
 
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
 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.
 
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
 Returns the width of the image.
 
int height () const
 Returns the height of the image.
 
QSize size () const
 Returns the size of the image, i.e.
 
QRect rect () const
 Returns the enclosing rectangle (0, 0, width(), height()) of the image.
 
int depth () const
 
int colorCount () const
 Returns the depth of the image.
 
int bitPlaneCount () const
 
QRgb color (int i) const
 Returns the color in the color table at index i.
 
void setColor (int i, QRgb c)
 Sets the color at the given index in the color table, to the given to colorValue.
 
void setColorCount (int)
 
bool allGray () const
 Returns true if all the colors in the image are shades of gray (i.e.
 
bool isGrayscale () const
 For 32-bit images, this function is equivalent to allGray().
 
ucharbits ()
 Returns a pointer to the first pixel data.
 
const ucharbits () 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.
 
const ucharconstBits () const
 Returns a pointer to the first pixel data.
 
qsizetype sizeInBytes () const
 
ucharscanLine (int)
 Returns a pointer to the pixel data at the scanline with index i.
 
const ucharscanLine (int) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const ucharconstScanLine (int) const
 Returns a pointer to the pixel data at the scanline with index i.
 
qsizetype bytesPerLine () const
 Returns the number of bytes per image scanline.
 
bool 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.
 
bool valid (const QPoint &pt) const
 Returns true if pos is a valid coordinate pair within the image; otherwise returns false.
 
int 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).
 
int pixelIndex (const QPoint &pt) const
 Returns the pixel index at the given position.
 
QRgb 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).
 
QRgb pixel (const QPoint &pt) const
 Returns the color of the pixel at the given position.
 
void 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.
 
void setPixel (const QPoint &pt, uint index_or_rgb)
 Sets the pixel index or color at the given position to index_or_rgb.
 
QColor 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.
 
QColor pixelColor (const QPoint &pt) const
 
void setPixelColor (int x, int y, const QColor &c)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void setPixelColor (const QPoint &pt, const QColor &c)
 
QList< QRgbcolorTable () 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.
 
void setColorTable (const QList< QRgb > &colors)
 
qreal devicePixelRatio () const
 Returns the device pixel ratio for the image.
 
void setDevicePixelRatio (qreal scaleFactor)
 Sets the device pixel ratio for the image.
 
QSizeF deviceIndependentSize () const
 Returns the size of the image in device independent pixels.
 
void fill (uint pixel)
 Fills the entire image with the given pixelValue.
 
void 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.
 
void 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.
 
bool hasAlphaChannel () const
 Returns true if the image has a format that respects the alpha channel, otherwise returns false.
 
void setAlphaChannel (const QImage &alphaChannel)
 Sets the alpha channel of this image to the given 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
 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.
 
QImage scaled (const QSize &s, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=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.
 
QImage scaledToWidth (int w, Qt::TransformationMode mode=Qt::FastTransformation) const
 [9]
 
QImage scaledToHeight (int h, Qt::TransformationMode mode=Qt::FastTransformation) const
 Returns a scaled copy of the image.
 
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)
 Inverts all pixel values in the image.
 
QColorSpace colorSpace () const
 
QImage convertedToColorSpace (const QColorSpace &colorSpace) const
 
QImage convertedToColorSpace (const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags=Qt::AutoColor) const
 
void convertToColorSpace (const QColorSpace &colorSpace)
 
void convertToColorSpace (const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
void setColorSpace (const QColorSpace &colorSpace)
 
QImage colorTransformed (const QColorTransform &transform) const &
 
QImage colorTransformed (const QColorTransform &transform, QImage::Format format, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
 
QImage colorTransformed (const QColorTransform &transform) &&
 
QImage colorTransformed (const QColorTransform &transform, QImage::Format format, Qt::ImageConversionFlags flags=Qt::AutoColor) &&
 
void applyColorTransform (const QColorTransform &transform)
 
void applyColorTransform (const QColorTransform &transform, QImage::Format format, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
bool 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.
 
bool load (const QString &fileName, const char *format=nullptr)
 Loads an image from the file with the given fileName.
 
bool loadFromData (QByteArrayView data, const char *format=nullptr)
 
bool loadFromData (const uchar *buf, 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.
 
bool loadFromData (const QByteArray &data, 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 given QByteArray data.
 
bool 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.
 
bool save (QIODevice *device, const char *format=nullptr, int quality=-1) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function writes a QImage to the given device.
 
qint64 cacheKey () const
 Returns a number that identifies the contents of this QImage object.
 
QPaintEnginepaintEngine () const override
 
int dotsPerMeterX () const
 Returns the number of pixels that fit horizontally in a physical meter.
 
int dotsPerMeterY () const
 Returns the number of pixels that fit vertically in a physical meter.
 
void setDotsPerMeterX (int)
 Sets the number of pixels that fit horizontally in a physical meter, to x.
 
void setDotsPerMeterY (int)
 Sets the number of pixels that fit vertically in a physical meter, to y.
 
QPoint offset () const
 Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images.
 
void setOffset (const QPoint &)
 Sets the number of pixels by which the image is intended to be offset by when positioning relative to other images, to offset.
 
QStringList textKeys () const
 Returns the text keys for this image.
 
QString text (const QString &key=QString()) const
 Returns the image text associated with the given key.
 
void setText (const QString &key, const QString &value)
 Sets the image text to the given text and associate it with the given key.
 
QPixelFormat pixelFormat () const noexcept
 Returns the QImage::Format as a QPixelFormat.
 
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)
 Returns a copy of the image that is transformed using the given transformation matrix and transformation mode.
 
static QImage fromData (QByteArrayView data, const char *format=nullptr)
 
static QImage fromData (const uchar *data, int size, 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.Constructs a QImage from the first size bytes of the given binary data.
 
static QImage fromData (const QByteArray &data, 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.Constructs a QImage from the given QByteArray data.
 
static QPixelFormat toPixelFormat (QImage::Format format) noexcept
 Converts format into a QPixelFormat.
 
static QImage::Format toImageFormat (QPixelFormat format) noexcept
 Converts format into a QImage::Format.
 
- 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
 
void detachMetadata (bool invalidateCache=false)
 
- 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 Symbols

(Note that these are not member symbols.)

 QImageCleanupFunction
 
QDataStreamoperator<< (QDataStream &stream, const QImage &image)
 Writes the given image to the given stream as a PNG image, or as a BMP image if the stream's version is 1.
 
QDataStreamoperator>> (QDataStream &stream, QImage &image)
 Reads an image from the given stream and stores it in the given image.
 

Additional Inherited Members

- Protected Attributes inherited from QPaintDevice
ushort painters
 

Detailed Description

\inmodule QtGui

\reentrant

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.

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 or QImage::Format_CMYK8888 is not supported.

Definition at line 36 of file qimage.h.

Member Typedef Documentation

◆ DataPtr

Definition at line 314 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 [since 5.2] 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. \value [since 5.2] 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. \value [since 5.2] Format_RGBA8888_Premultiplied The image is stored using a premultiplied 32-bit byte-ordered RGBA format (8-8-8-8). \value [since 5.4] Format_BGR30 The image is stored using a 32-bit BGR format (x-10-10-10). \value [since 5.4] Format_A2BGR30_Premultiplied The image is stored using a 32-bit premultiplied ABGR format (2-10-10-10). \value [since 5.4] Format_RGB30 The image is stored using a 32-bit RGB format (x-10-10-10). \value [since 5.4] Format_A2RGB30_Premultiplied The image is stored using a 32-bit premultiplied ARGB format (2-10-10-10). \value [since 5.5] Format_Alpha8 The image is stored using an 8-bit alpha only format. \value [since 5.5] Format_Grayscale8 The image is stored using an 8-bit grayscale format. \value [since 5.13] Format_Grayscale16 The image is stored using an 16-bit grayscale format. \value [since 5.12] 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. \value [since 5.12] Format_RGBA64 The image is stored using a 64-bit halfword-ordered RGBA format (16-16-16-16). \value [since 5.12] Format_RGBA64_Premultiplied The image is stored using a premultiplied 64-bit halfword-ordered RGBA format (16-16-16-16). \value [since 5.14] Format_BGR888 The image is stored using a 24-bit BGR format. \value [since 6.2] Format_RGBX16FPx4 The image is stored using a four 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. \value [since 6.2] Format_RGBA16FPx4 The image is stored using a four 16-bit halfword floating point RGBA format (16FP-16FP-16FP-16FP). \value [since 6.2] Format_RGBA16FPx4_Premultiplied The image is stored using a premultiplied four 16-bit halfword floating point RGBA format (16FP-16FP-16FP-16FP). \value [since 6.2] Format_RGBX32FPx4 The image is stored using a four 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. \value [since 6.2] Format_RGBA32FPx4 The image is stored using a four 32-bit floating point RGBA format (32FP-32FP-32FP-32FP). \value [since 6.2] Format_RGBA32FPx4_Premultiplied The image is stored using a premultiplied four 32-bit floating point RGBA format (32FP-32FP-32FP-32FP). \value [since 6.8] Format_CMYK8888 The image is stored using a 32-bit byte-ordered CMYK format.

Note
Drawing into a QImage with format QImage::Format_Indexed8 or QImage::Format_CMYK8888 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 
Format_CMYK8888 
NImageFormats 

Definition at line 41 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 40 of file qimage.h.

Constructor & Destructor Documentation

◆ QImage() [1/11]

QImage::QImage ( )
noexcept

Constructs a null image.

See also
isNull()

Definition at line 791 of file qimage.cpp.

References d.

Referenced by convertedToColorSpace(), convertedToColorSpace(), convertToFormat(), convertToFormat_helper(), and mirrored_helper().

+ 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 821 of file qimage.cpp.

References QImageData::create(), and d.

+ 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 807 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 888 of file qimage.cpp.

References QImageData::create(), and d.

+ Here is the call graph for this function:

◆ 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 919 of file qimage.cpp.

References QImageData::create(), and d.

+ Here is the call graph for this function:

◆ 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 943 of file qimage.cpp.

References bytesPerLine(), QImageData::create(), and d.

+ Here is the call graph for this function:

◆ 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 974 of file qimage.cpp.

References bytesPerLine(), QImageData::create(), and d.

+ Here is the call graph for this function:

◆ 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:

static const char * const start_xpm[] = {
"16 15 8 1",
"a c #cec6bd",
// etc.
};

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 1026 of file qimage.cpp.

References d, qt_read_xpm_image_or_array(), and qWarning.

+ 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 1000 of file qimage.cpp.

References d, fileName, and load().

+ 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 1047 of file qimage.cpp.

References d.

◆ 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 99 of file qimage.h.

◆ ~QImage()

QImage::~QImage ( )

Destroys the image and cleans up.

Definition at line 1064 of file qimage.cpp.

References d.

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 2880 of file qimage.cpp.

References BufferSize, constScanLine(), d, Format_Alpha8, Format_ARGB32, Format_ARGB32_Premultiplied, Format_Grayscale16, Format_Grayscale8, Format_Indexed8, Format_Mono, Format_MonoLSB, Format_RGB16, Format_RGB32, Format_RGBA8888, Format_RGBA8888_Premultiplied, Format_RGBX8888, i, j, layout, ptr(), qConvertRgb16To32(), qIsGray(), qMin(), qPixelLayouts, and QRgb.

Referenced by isGrayscale(), and Jpeg2000JasperReader::write().

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

◆ applyColorTransform() [1/2]

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

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

Definition at line 5176 of file qimage.cpp.

References QSemaphore::acquire(), QThreadPool::contains(), convertTo(), QThread::currentThread(), d, depth(), detach(), format(), Format_ARGB32, Format_ARGB32_Premultiplied, Format_CMYK8888, Format_Grayscale16, Format_Grayscale8, Format_RGB32, Format_RGBA32FPx4, Format_RGBA32FPx4_Premultiplied, Format_RGBA64, Format_RGBA64_Premultiplied, Format_RGBX32FPx4, Format_RGBX64, QColorTransformPrivate::get(), hasAlphaChannel(), i, QPixelFormat::Indexed, QColorTransformPrivate::InputOpaque, pixelFormat(), QColorTransformPrivate::Premultiplied, QRgb, qt_compatibleColorModel(), qt_fpColorPrecision(), QThreadPoolPrivate::qtGuiInstance(), qWarning, QSemaphore::release(), QThreadPool::start(), QColorTransformPrivate::Unpremultiplied, and void.

Referenced by convertToColorSpace(), and convertToColorSpace().

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

◆ applyColorTransform() [2/2]

void QImage::applyColorTransform ( const QColorTransform & transform,
QImage::Format toFormat,
Qt::ImageConversionFlags flags = Qt::AutoColor )
Since
6.8

Applies the color transformation transform to all pixels in the image, and converts the format of the image to toFormat.

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

Definition at line 5314 of file qimage.cpp.

References colorTransformed(), convertTo(), and d.

+ Here is the call 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 4620 of file qimage.cpp.

References d, Format_ARGB8555_Premultiplied, Format_BGR30, Format_Invalid, Format_RGB30, Format_RGB32, Format_RGB444, Format_RGB555, Format_RGB666, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX64, Format_RGBX8888, and qt_depthForFormat().

+ 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 1701 of file qimage.cpp.

References d, and detach().

Referenced by QFontEngine::addBitmapFontToPath(), QAlphaWidget::alphaBlend(), QXcbGraphicsBuffer::data(), QXcbGraphicsBuffer::data(), QGIFFormat::decode(), QT_BEGIN_NAMESPACE::expblur(), QImageTextureGlyphCache::fillTexture(), grayscale(), QCoreTextFontEngine::imageForGlyph(), QQnxBuffer::invalidateInCache(), QSSGLoadedTexture::loadQImage(), QImageVideoBuffer::map(), AndroidTextureVideoBuffer::map(), operator==(), qt_halfScaled(), qt_x11_drawImage(), and QPlatformCursorImage::set().

+ 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 1721 of file qimage.cpp.

References d.

◆ bytesPerLine()

◆ 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 4515 of file qimage.cpp.

References d.

Referenced by detach(), detachMetadata(), and QPdfEngine::drawImage().

+ 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 1579 of file qimage.cpp.

References colorCount(), d, i, Q_ASSERT, and QRgb.

+ Here is the call graph for this function:

◆ colorCount()

int QImage::colorCount ( ) 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}
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}

Referenced by color(), isGrayscale(), and setColorCount().

+ 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 5164 of file qimage.cpp.

References d.

Referenced by convertedToColorSpace(), convertedToColorSpace(), convertToColorSpace(), convertToColorSpace(), and setColorSpace().

+ 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 1468 of file qimage.cpp.

References d.

Referenced by QVncClient::convertPixels(), and convertToFormat().

+ Here is the caller graph for this function:

◆ colorTransformed() [1/4]

QImage QImage::colorTransformed ( const QColorTransform & transform) &&
Since
6.4 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns the image color transformed using transform on all pixels in the image.

See also
applyColorTransform()

Definition at line 5806 of file qimage.cpp.

References QColorSpace::Cmyk, d, Format_CMYK8888, Format_Grayscale16, Format_Grayscale8, Format_RGB32, Format_RGBX64, QColorTransformPrivate::get(), QColorSpace::Gray, qt_compatibleColorModel(), qt_highColorPrecision(), qWarning, QColorSpace::Rgb, and QColorSpace::Undefined.

+ Here is the call graph for this function:

◆ colorTransformed() [2/4]

QImage QImage::colorTransformed ( const QColorTransform & transform) const &
Since
6.4

Returns the image color transformed using transform on all pixels in the image.

Note
If transform has a source color space which is incompatible with the format of this image, returns a null QImage. If transform has a target color space which is incompatible with the format of this image, the image will also be converted to a compatible format. For more control about the choice of the target pixel format, see the three argument overload of this method.
See also
applyColorTransform()

Definition at line 5336 of file qimage.cpp.

References QColorSpace::Cmyk, copy(), d, Format_CMYK8888, Format_Grayscale16, Format_Grayscale8, Format_RGB32, Format_RGBX64, QColorTransformPrivate::get(), QColorSpace::Gray, qt_compatibleColorModel(), qt_highColorPrecision(), qWarning, QColorSpace::Rgb, and QColorSpace::Undefined.

Referenced by applyColorTransform(), convertedToColorSpace(), and convertedToColorSpace().

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

◆ colorTransformed() [3/4]

QImage QImage::colorTransformed ( const QColorTransform & transform,
QImage::Format format,
Qt::ImageConversionFlags flags = Qt::AutoColor ) &&
Since
6.8 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns the image color transformed using transform on all pixels in the image.

See also
applyColorTransform()

Definition at line 5844 of file qimage.cpp.

◆ colorTransformed() [4/4]

QImage QImage::colorTransformed ( const QColorTransform & transform,
QImage::Format toFormat,
Qt::ImageConversionFlags flags = Qt::AutoColor ) const &
Since
6.8

Returns the image color transformed using transform on all pixels in the image, returning an image of format toFormat.

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

Note
If transform has a source color space which is incompatible with the format of this image, or a target color space that is incompatible with toFormat, returns a null QImage.
See also
applyColorTransform()

Definition at line 5421 of file qimage.cpp.

References QSemaphore::acquire(), bytesPerLine(), QColorSpace::Cmyk, QImageData::colortable, constBits(), QThreadPool::contains(), convertedTo(), convertTo(), copyMetadata(), QThread::currentThread(), d, QImageData::data, format(), Format_A2BGR30_Premultiplied, Format_A2RGB30_Premultiplied, Format_Alpha8, Format_ARGB32, Format_ARGB32_Premultiplied, Format_ARGB4444_Premultiplied, Format_ARGB6666_Premultiplied, Format_ARGB8555_Premultiplied, Format_ARGB8565_Premultiplied, Format_BGR30, Format_BGR888, Format_CMYK8888, Format_Grayscale16, Format_Grayscale8, Format_Indexed8, Format_Invalid, Format_Mono, Format_MonoLSB, Format_RGB16, Format_RGB30, Format_RGB32, Format_RGB444, Format_RGB555, Format_RGB666, Format_RGB888, Format_RGBA16FPx4, Format_RGBA16FPx4_Premultiplied, Format_RGBA32FPx4, Format_RGBA32FPx4_Premultiplied, Format_RGBA64, Format_RGBA64_Premultiplied, Format_RGBA8888, Format_RGBA8888_Premultiplied, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX64, Format_RGBX8888, QColorTransformPrivate::get(), QColorSpace::Gray, hasAlphaChannel(), i, QPixelFormat::Indexed, QColorTransformPrivate::InputOpaque, isRgb32Data(), isRgb32fpx4Data(), isRgb64Data(), NImageFormats, QColorTransformPrivate::Premultiplied, QPixelLayout::premultiplied, Q_ASSERT, qPixelLayouts, QRgb, qt_compatibleColorModel(), qt_csColorData(), qt_fpColorPrecision(), qt_highColorPrecision(), QThreadPoolPrivate::qtGuiInstance(), qWarning, QSemaphore::release(), QColorSpace::Rgb, QThreadPool::start(), QColorTransformPrivate::Unpremultiplied, and void.

+ Here is the call 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 1737 of file qimage.cpp.

References d.

Referenced by QtWaylandClient::QWaylandShmBuffer::~QWaylandShmBuffer(), QEglFSKmsGbmCursor::changeCursor(), colorTransformed(), QWindowsDirect2DBitmap::fromImage(), iconToQXdgDBusImageVector(), QtWaylandClient::QWaylandShmBuffer::imageInsideMargins(), QD3D11CommandBuffer::retainImage(), QGles2CommandBuffer::retainImage(), QOpenGLTextureUploader::textureImage(), and QQuickNinePatchImagePrivate::updatePatches().

+ 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 1681 of file qimage.cpp.

References d, i, and Q_ASSERT.

Referenced by allGray(), QWindowsFontEngineDirectWrite::alphaMapForGlyph(), QFontEngine::alphaMapForGlyph(), QFontEngine::alphaRGBMapForGlyph(), QQuickVisualTestUtils::compareImages(), pixelColor(), and qt_createIconMask().

+ 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 140 of file qimage.h.

◆ convertedTo() [2/2]

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

Definition at line 138 of file qimage.h.

Referenced by colorTransformed(), and convertedToColorSpace().

+ Here is the caller graph for this function:

◆ convertedToColorSpace() [1/2]

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.

Note
If colorSpace is not compatible with the current format, the returned image will also be converted to a format this is. For more control over returned image format, see the three argument overload of this method.
See also
convertToColorSpace(), colorTransformed()

Definition at line 5113 of file qimage.cpp.

References QImage(), colorSpace(), colorTransformed(), d, QColorSpace::isValidTarget(), and qWarning.

Referenced by convertToColorSpace().

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

◆ convertedToColorSpace() [2/2]

QImage QImage::convertedToColorSpace ( const QColorSpace & colorSpace,
QImage::Format format,
Qt::ImageConversionFlags flags = Qt::AutoColor ) const
Since
6.8

Returns the image converted to colorSpace and format.

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

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

See also
colorTransformed()

Definition at line 5140 of file qimage.cpp.

References QImage(), QColorSpace::colorModel(), colorSpace(), colorTransformed(), convertedTo(), d, QColorSpace::isValidTarget(), qt_compatibleColorModel(), qWarning, and toPixelFormat().

+ 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 2407 of file qimage.cpp.

References convertToFormat_helper(), convertToFormat_inplace(), d, detach(), and NImageFormats.

Referenced by applyColorTransform(), applyColorTransform(), colorTransformed(), convertToColorSpace(), setAlphaChannel(), and smoothScaled().

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

◆ convertToColorSpace() [1/2]

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.

Note
If colorSpace is not compatible with the current format, the image will be converted to one that is.
See also
convertedToColorSpace(), setColorSpace()

Definition at line 5047 of file qimage.cpp.

References applyColorTransform(), QColorSpace::colorModel(), colorSpace(), convertedToColorSpace(), d, detachMetadata(), QColorSpace::isValidTarget(), pixelFormat(), qt_compatibleColorModel(), and qWarning.

+ Here is the call graph for this function:

◆ convertToColorSpace() [2/2]

void QImage::convertToColorSpace ( const QColorSpace & colorSpace,
QImage::Format format,
Qt::ImageConversionFlags flags = Qt::AutoColor )
Since
6.8

Converts the image to colorSpace and format.

If the image has no valid color space, the method does nothing, nor if the color space is not compatible with with the format.

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

See also
convertedToColorSpace(), setColorSpace()

Definition at line 5080 of file qimage.cpp.

References applyColorTransform(), QColorSpace::colorModel(), colorSpace(), convertTo(), d, QColorSpace::isValidTarget(), qt_compatibleColorModel(), qWarning, and toPixelFormat().

+ 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 2337 of file qimage.cpp.

References QImage(), colorTable(), convertToFormat(), convertWithPalette(), d, Format_ARGB32, Format_Indexed8, and NImageFormats.

+ 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 127 of file qimage.h.

◆ convertToFormat() [3/3]

◆ convertToFormat_helper()

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

Definition at line 2203 of file qimage.cpp.

References QImage(), convert_generic(), convert_generic_over_rgb64(), convertToFormat(), copyMetadata(), d, format(), Format_ARGB32, Format_Indexed8, Format_Invalid, Format_RGB32, hasAlphaChannel(), NImageFormats, Q_ASSERT, qimage_converter_map, QIMAGE_SANITYCHECK_MEMORY, qPixelLayouts, qt_fpColorPrecision(), and qt_highColorPrecision().

Referenced by convertTo().

+ 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 2249 of file qimage.cpp.

References d.

Referenced by convertTo().

+ 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()

Referenced by QFontEngineFT::bitmapForGlyph(), QSGPlainTexture::commitTextureOperations(), Viewer::createImage(), detach(), detachMetadata(), QWindowsVistaStylePrivate::drawBackgroundThruNativeBuffer(), QQC2::QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QPaintEngine::drawImage(), QXcbBackingStore::endPaint(), QSGRhiTextureGlyphCache::fillTexture(), QRhiWidgetPrivate::grabFramebuffer(), QQuickContext2DImageTexture::grabImage(), QuickTestResult::grabImage(), QOffscreenBackingStore::grabWindow(), load_glyph_image_region_to_texture(), mirrored_inplace(), QImageTextureGlyphCache::resizeTextureData(), QAlphaWidget::run(), QOpenGLTextureUploader::textureImage(), QBlittablePlatformPixmap::toImage(), and QWindowsDirect2DBitmapPrivate::toImage().

+ 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 120 of file qimage.h.

References copy().

+ Here is the call graph for this function:

◆ createAlphaMask()

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

◆ createHeuristicMask()

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

◆ createMaskFromColor()

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

◆ data_ptr()

DataPtr & QImage::data_ptr ( )
inline

Definition at line 315 of file qimage.h.

References d.

Referenced by QBackingStore::beginPaint().

+ Here is the caller graph for this function:

◆ depth()

int QImage::depth ( ) const

◆ detach()

void QImage::detach ( )

If multiple images share common data, this image makes a copy of the data and detaches itself from the sharing mechanism, making sure that this image is the only one referring to the data.

Nothing is done if there is just a single reference.

See also
copy(), {QImage::isDetached()}{isDetached()}, {Implicit Data Sharing}

Definition at line 1129 of file qimage.cpp.

References cacheKey(), copy(), d, and QImagePixmapCleanupHooks::executeImageHooks().

Referenced by applyColorTransform(), QPainter::begin(), bits(), convertTo(), QPixmap::detach(), fill(), fill(), QSGSoftwareRenderLoop::grab(), invertPixels(), mirrored_inplace(), reinterpretAsFormat(), scanLine(), and setAlphaChannel().

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

◆ detachMetadata()

void QImage::detachMetadata ( bool invalidateCache = false)
protected

A variant for metadata-only detach, which will not detach readonly image data, and only invalidate caches of the image data if asked to.

See also
detach(), isDetached()

Definition at line 1152 of file qimage.cpp.

References cacheKey(), copy(), d, and QImagePixmapCleanupHooks::executeImageHooks().

Referenced by convertToColorSpace(), setColor(), setColorCount(), setColorSpace(), setDevicePixelRatio(), setDotsPerMeterX(), setDotsPerMeterY(), setOffset(), and setText().

+ 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 image in device independent pixels.

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

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

Since
6.2

Definition at line 1535 of file qimage.cpp.

References d.

◆ 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 1484 of file qimage.cpp.

References d.

Referenced by QBackingStore::beginPaint(), QWasmBackingStore::beginPaint(), QRasterBackingStore::beginPaint(), QQuickVisualTestUtils::compareImages(), createBitmapCursor(), QuickTestResult::grabImage(), QtWaylandClient::QWaylandShmBuffer::imageInsideMargins(), QRasterBackingStore::scroll(), and QWasmBackingStore::updateTexture().

+ Here is the caller graph for this function:

◆ devType()

int QImage::devType ( ) const
overridevirtual

Reimplemented from QPaintDevice.

Definition at line 1105 of file qimage.cpp.

References QInternal::Image.

◆ 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 4094 of file qimage.cpp.

References d, and qRound().

+ 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 4107 of file qimage.cpp.

References d, and qRound().

+ 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 1872 of file qimage.cpp.

References ARGB2RGBA(), Qt::color1, QPainter::CompositionMode_Source, d, depth(), detach(), fill(), Format_ARGB32, Format_ARGB32_Premultiplied, Format_BGR30, Format_Indexed8, Format_Mono, Format_MonoLSB, Format_RGB16, Format_RGB30, Format_RGB32, Format_RGBA16FPx4, Format_RGBA16FPx4_Premultiplied, Format_RGBA32FPx4, Format_RGBA32FPx4_Premultiplied, Format_RGBA64, Format_RGBA64_Premultiplied, Format_RGBA8888, Format_RGBA8888_Premultiplied, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX64, Format_RGBX8888, hasAlphaChannel(), i, pixel(), QRgbaFloat< F >::premultiplied(), qConvertRgb32To16(), qPremultiply(), rect(), and QRgba64::setAlpha().

+ 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 1848 of file qimage.cpp.

References fill().

+ 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 1762 of file qimage.cpp.

References d, detach(), Format_BGR30, Format_RGB30, Format_RGB32, Format_RGB444, Format_RGB666, Format_RGBA16FPx4_Premultiplied, Format_RGBA32FPx4_Premultiplied, Format_RGBA64_Premultiplied, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX64, Format_RGBX8888, QRgba64::fromArgb32(), QRgbaFloat< F >::fromArgb32(), line, pixel(), and Q_ASSERT.

Referenced by QWaylandMouseTrackerPrivate::QWaylandMouseTrackerPrivate(), QFontEngine::alphaMapForGlyph(), QRasterBackingStore::beginPaint(), QQuickContext2DImageTexture::beginPainting(), QEglFSKmsGbmCursor::changeCursor(), QImageTextureGlyphCache::createTextureData(), QPixmapDropShadowFilter::draw(), QGeoTiledMapNokia::evaluateCopyrights(), fill(), QBlittablePlatformPixmap::fill(), QX11PlatformPixmap::fill(), fill(), iconToQXdgDBusImageVector(), QCoreTextFontEngine::imageForGlyph(), and QDeclarativeGeoMapCopyrightNotice::rasterizeHtmlAndUpdate().

+ 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 2170 of file qimage.cpp.

References d, and Format_Invalid.

Referenced by applyColorTransform(), colorTransformed(), QSGPlainTexture::commitTextureOperations(), QQuickVisualTestUtils::compareImages(), convertToFormat_helper(), QImageTextureGlyphCache::fillTexture(), QXcbBackingStoreImage::flushScrolledRegion(), QtWaylandClient::QWaylandShmBuffer::imageInsideMargins(), invertPixels(), pixelFormat(), QT_BEGIN_NAMESPACE::qt_blurrow(), qt_createIconMask(), reinterpretAsFormat(), and setPixel().

+ 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 259 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 3866 of file qimage.cpp.

References fromData().

+ 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 3849 of file qimage.cpp.

References QByteArray::fromRawData(), QImageReader::read(), QIODeviceBase::ReadOnly, and QBuffer::setData().

Referenced by convertValue(), createImageNode(), fromData(), ICOReader::iconAt(), loadFromData(), QT_BEGIN_NAMESPACE::parseImage(), Q_LOGGING_CATEGORY(), Q_LOGGING_CATEGORY(), QICNSHandler::read(), and QInternalMimeData::retrieveData().

+ 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 4597 of file qimage.cpp.

References d, QPixelFormat::Indexed, pixelFormat(), and QPixelFormat::UsesAlpha.

Referenced by applyColorTransform(), QFbBackingStore::beginPaint(), QWasmBackingStore::beginPaint(), QRasterBackingStore::beginPaint(), QOpenGLCompositorBackingStore::beginPaint(), QtWaylandClient::QWaylandShmBackingStore::beginPaint(), colorTransformed(), convertToFormat_helper(), QFbScreen::doRedraw(), QPixmapColorizeFilter::draw(), fill(), QRhiBackingStore::flush(), QBlittablePlatformPixmap::hasAlphaChannel(), invertPixels(), QBrush::isOpaque(), pixelColor(), setPixel(), setPixelColor(), and Jpeg2000JasperReader::write().

+ 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}

Referenced by QSvgImage::QSvgImage(), QFontEngine::addBitmapFontToPath(), QAlphaWidget::alphaBlend(), QCoreTextFontEngine::alphaMapForGlyph(), QWindowsFontEngineDirectWrite::alphaMapForGlyph(), QFontEngine::alphaMapForGlyph(), QFontEngine::alphaRGBMapForGlyph(), QEglFSKmsGbmCursor::changeCursor(), QSGPlainTexture::commitTextureOperations(), QQuickVisualTestUtils::compareImages(), QQuickMaskExtruder::contains(), QDeclarativeGeoMapCopyrightNotice::copyrightsImageChanged(), Viewer::createImage(), QSGOpenVGRenderContext::createTexture(), darkenPixmap(), QQC2_NAMESPACE::darkenPixmap(), QGIFFormat::decode(), QPdfEngine::drawImage(), QOpenGL2PaintEngineEx::drawImage(), QOpenGL2PaintEngineEx::drawPixmap(), QGeoTiledMapNokia::evaluateCopyrights(), QT_BEGIN_NAMESPACE::expblur(), QImageTextureGlyphCache::fillTexture(), QWindowsDirect2DBitmap::fromImage(), QMacStyle::generatedIconPixmap(), QCommonStyle::generatedIconPixmap(), QQC2_NAMESPACE::QMacStyle::generatedIconPixmap(), QQC2::QCommonStyle::generatedIconPixmap(), QuickTestResult::grabImage(), QBsdFbScreen::grabWindow(), QIntegrityFbScreen::grabWindow(), QLinuxFbScreen::grabWindow(), QVncScreen::grabWindow(), grayscale(), QQuickCanvasPixmap::height(), iconToQXdgDBusImageVector(), QCoreTextFontEngine::imageForGlyph(), imageHasNarrowOutlines(), QQnxBuffer::invalidateInCache(), qt_createIconMask(), qt_halfScaled(), QDeclarativeGeoMapCopyrightNotice::rasterizeHtmlAndUpdate(), QOpenGLTextureUploader::textureImage(), QQuickNinePatchImagePrivate::updatePatches(), QWasmBackingStore::updateTexture(), QTiffHandler::write(), Jpeg2000JasperReader::write(), and QQuick3DPhysicsHeightField::writeSamples().

+ 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 1994 of file qimage.cpp.

References convertToFormat(), d, depth(), detach(), format(), Format_ARGB32, Format_BGR30, Format_RGB30, Format_RGB32, Format_RGBA16FPx4, Format_RGBA16FPx4_Premultiplied, Format_RGBA32FPx4, Format_RGBA32FPx4_Premultiplied, Format_RGBA64, Format_RGBA8888, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX8888, hasAlphaChannel(), InvertRgba, QPixelLayout::premultiplied, Q_FALLTHROUGH, and qPixelLayouts.

Referenced by QCoreTextFontEngine::imageForGlyph(), and qt_createIconMask().

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

◆ isDetached()

bool QImage::isDetached ( ) const

Returns true if the image is detached; otherwise returns false.

See also
detach(), {Implicit Data Sharing}

Definition at line 4531 of file qimage.cpp.

References d.

Referenced by reinterpretAsFormat().

+ 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 2956 of file qimage.cpp.

References allGray(), colorCount(), d, depth(), Format_Alpha8, Format_Grayscale16, Format_Grayscale8, Format_Indexed8, i, Q_ASSERT, and qRgb().

+ Here is the call graph for this function:

◆ isNull()

QImage Q_TRACE_INSTRUMENTbool 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 1337 of file qimage.cpp.

Referenced by QRasterBuffer::colorizeBitmap(), QSGPlainTexture::commitTextureOperations(), QQuickMaskExtruder::contains(), QDeclarativeGeoMapCopyrightNotice::copyrightsImageChanged(), QRhiD3D11::enqueueSubresUpload(), QRhiGles2::enqueueSubresUpload(), QGeoTiledMapNokia::evaluateCopyrights(), QQuickMaskExtruder::extrude(), QTexturedBrushData::image(), QQuickCanvasPixmap::image(), imageHasNarrowOutlines(), QQuickCanvasPixmap::isValid(), load(), load(), loadFromData(), QImageVideoBuffer::map(), QQuickTextNodeEngine::mergeProcessedNodes(), QSGDefaultPainterNode::paint(), QXcbBackingStore::paintDevice(), QSGRhiAtlasTexture::Texture::removedFromAtlas(), QQuickWidgetPrivate::render(), QAlphaWidget::run(), save(), save(), QXcbBackingStoreImage::scroll(), QOffscreenBackingStore::scroll(), QWindowsBackingStore::scroll(), QPlatformCursorImage::set(), setAlphaChannel(), Viewer::setBrightness(), QOpenGL2PaintEngineExPrivate::setBrush(), QDeclarativeGeoMapCopyrightNotice::setCopyrightsVisible(), QDeclarativeGeoMapCopyrightNotice::setMapSource(), QRhiMetal::subresUploadByteSize(), QRhiVulkan::subresUploadByteSize(), QVideoFrame::toImage(), QXcbBackingStore::toImage(), QQuickStyleItem::updatePaintNode(), QQuickNinePatchImagePrivate::updatePatches(), QGeoTiledMapScene::updateSceneGraph(), and QGeoTiledMapRootNode::updateTiles().

+ 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 3775 of file qimage.cpp.

References fileName, isNull(), and QImageReader::read().

+ 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 3788 of file qimage.cpp.

References device, isNull(), and QImageReader::read().

Referenced by QImage().

+ 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 251 of file qimage.h.

◆ loadFromData() [2/3]

bool QImage::loadFromData ( const uchar * buf,
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 3821 of file qimage.cpp.

References loadFromData().

+ 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 3807 of file qimage.cpp.

References fromData(), and isNull().

Referenced by loadFromData().

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

◆ metric()

int QImage::metric ( PaintDeviceMetric metric) const
overrideprotectedvirtual

Returns the size for the specified metric on the device.

Reimplemented from QPaintDevice.

Definition at line 4286 of file qimage.cpp.

References d, QPaintDevice::devicePixelRatioFScale(), metric(), QPaintDevice::PdmDepth, QPaintDevice::PdmDevicePixelRatio, QPaintDevice::PdmDevicePixelRatioScaled, QPaintDevice::PdmDpiX, QPaintDevice::PdmDpiY, QPaintDevice::PdmHeight, QPaintDevice::PdmHeightMM, QPaintDevice::PdmNumColors, QPaintDevice::PdmPhysicalDpiX, QPaintDevice::PdmPhysicalDpiY, QPaintDevice::PdmWidth, QPaintDevice::PdmWidthMM, qRound(), and qWarning.

Referenced by metric().

+ Here is the call graph for this function:
+ Here is the caller 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 227 of file qimage.h.

◆ mirrored() [1/2]

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

Definition at line 221 of file qimage.h.

◆ mirrored() [2/2]

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

Definition at line 219 of file qimage.h.

Referenced by QRhiWidgetPrivate::grabFramebuffer(), QQuickDesignerSupport::renderImageForItem(), QQC2::QCommonStyle::standardPixmap(), QCommonStyle::standardPixmap(), and QSGRhiLayer::toImage().

+ Here is the caller graph for this function:

◆ mirrored_helper()

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

Definition at line 3488 of file qimage.cpp.

References QImage(), copyMetadata(), d, do_mirror(), and QIMAGE_SANITYCHECK_MEMORY.

+ Here is the call graph for this function:

◆ mirrored_inplace()

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

Definition at line 3516 of file qimage.cpp.

References copy(), d, detach(), and do_mirror().

+ 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 4164 of file qimage.cpp.

References d.

◆ operator QVariant()

QImage::operator QVariant ( ) const

Returns the image as a QVariant.

Definition at line 1113 of file qimage.cpp.

References QVariant::fromValue().

+ 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 4078 of file qimage.cpp.

References i.

◆ operator=()

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

Move-assigns other to this QImage instance.

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

Since
5.2

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

See also
copy(), QImage()

Definition at line 1080 of file qimage.cpp.

References d, and operator=().

Referenced by operator=().

+ Here is the call graph for this function:
+ Here is the caller 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 4013 of file qimage.cpp.

References bits(), d, Format_ARGB32, Format_RGB32, i, p1, p2, pixelIndex(), and scanLine().

+ Here is the call graph for this function:

◆ paintEngine()

QPaintEngine * QImage::paintEngine ( ) const
overridevirtual

Used by QPainter to retrieve a paint engine for the image.

Implements QPaintDevice.

Definition at line 4263 of file qimage.cpp.

References QPlatformIntegration::createImagePaintEngine(), d, and QGuiApplicationPrivate::platformIntegration().

Referenced by QWindowsNativeImage::QWindowsNativeImage().

+ Here is the call graph for this function:
+ Here is the caller 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 324 of file qimage.h.

References pixel(), QPoint::x(), and QPoint::y().

+ 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 2501 of file qimage.cpp.

References d, Format_A2BGR30_Premultiplied, Format_A2RGB30_Premultiplied, Format_ARGB32, Format_ARGB32_Premultiplied, Format_BGR30, Format_Indexed8, Format_Mono, Format_MonoLSB, Format_RGB16, Format_RGB30, Format_RGB32, Format_RGBA16FPx4, Format_RGBA16FPx4_Premultiplied, Format_RGBA32FPx4, Format_RGBA32FPx4_Premultiplied, Format_RGBA64, Format_RGBA64_Premultiplied, Format_RGBA8888, Format_RGBA8888_Premultiplied, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX64, Format_RGBX8888, layout, qConvertA2rgb30ToArgb32< PixelOrderBGR >(), qConvertA2rgb30ToArgb32< PixelOrderRGB >(), qConvertRgb16To32(), qPixelLayouts, QRgb, qWarning, RGBA2ARGB(), and toArgb32().

Referenced by QQuickMaskExtruder::contains(), Viewer::createImage(), fill(), fill(), fillUniformArrayFromImage(), QCoreTextFontEngine::fontSmoothing(), QColorDialogPrivate::grabScreenColor(), grabScreenColor(), imageHasNarrowOutlines(), pixel(), and pixelColor().

+ 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 326 of file qimage.h.

References pixelColor(), QPoint::x(), and QPoint::y().

+ 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 2717 of file qimage.cpp.

References constScanLine(), d, Format_A2BGR30_Premultiplied, Format_A2RGB30_Premultiplied, Format_BGR30, Format_Grayscale16, Format_RGB30, Format_RGBA16FPx4, Format_RGBA16FPx4_Premultiplied, Format_RGBA32FPx4, Format_RGBA32FPx4_Premultiplied, Format_RGBA64, Format_RGBA64_Premultiplied, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX64, QRgba64::fromArgb32(), hasAlphaChannel(), pixel(), QPixelLayout::premultiplied, qConvertA2rgb30ToRgb64< PixelOrderBGR >(), qConvertA2rgb30ToRgb64< PixelOrderRGB >(), qPixelLayouts, qRgba64(), qWarning, QColor::setRgbF(), and QRgbaFloat< F >::unpremultiplied().

Referenced by pixelColor(), and QQuick3DPhysicsHeightField::writeSamples().

+ 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 6393 of file qimage.cpp.

References format(), and toPixelFormat().

Referenced by applyColorTransform(), convertToColorSpace(), hasAlphaChannel(), and setColorSpace().

+ 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 323 of file qimage.h.

References pixelIndex(), QPoint::x(), and QPoint::y().

+ 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 2460 of file qimage.cpp.

References d, Format_Indexed8, Format_Mono, Format_MonoLSB, qWarning, and scanLine().

Referenced by operator==(), and pixelIndex().

+ 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}

Referenced by QQuickMaskExtruder::contains(), QPixmapDropShadowFilter::draw(), fill(), QImageTextureGlyphCache::fillTexture(), grayscale(), QHaikuBuffer::rect(), setAlphaChannel(), QSpanData::setup(), QOpenGLTextureUploader::textureImage(), QWasmBackingStore::updateTexture(), and QRfbRawEncoder::write().

+ 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 2373 of file qimage.cpp.

References d, detach(), format(), isDetached(), and qt_depthForFormat().

+ Here is the call 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 229 of file qimage.h.

◆ rgbSwapped() [1/2]

QImage QImage::rgbSwapped ( ) &&
inline

Definition at line 225 of file qimage.h.

◆ rgbSwapped() [2/2]

QImage QImage::rgbSwapped ( ) const &
inline

Definition at line 223 of file qimage.h.

Referenced by QXcbBackingStore::endPaint().

+ Here is the caller graph for this function:

◆ rgbSwapped_helper()

QImage QImage::rgbSwapped_helper ( ) const
protected

◆ rgbSwapped_inplace()

void QImage::rgbSwapped_inplace ( )
protected

◆ 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 3896 of file qimage.cpp.

References d, fileName, and isNull().

Referenced by QImageTextureGlyphCache::fillTexture(), QMinimalBackingStore::flush(), QWindowsBackingStore::flush(), FinalWidget::mouseMoveEvent(), QQuickCanvasItem::save(), and QQuickImageCapture::saveToFile().

+ 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:

image.save(&buffer, "PNG"); // writes image into ba in PNG format

Definition at line 3915 of file qimage.cpp.

References d, device, and isNull().

+ 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}

◆ 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 209 of file qimage.h.

References scaled().

Referenced by QSGPlainTexture::commitTextureOperations(), QSGOpenVGRenderContext::createTexture(), QOpenGL2PaintEngineEx::drawPixmap(), QOpenGL2PaintEngineEx::drawPixmapFragments(), fillUniformArrayFromImage(), QLabel::paintEvent(), QGtk3Storage::standardPixmap(), QOpenGLTextureUploader::textureImage(), and QOpenGL2PaintEngineExPrivate::updateBrushTexture().

+ Here is the call graph for this function:
+ Here is the caller 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}

◆ scaledToWidth()

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

[9]

Returns a scaled copy of the image.

[10]

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 3045 of file qimage.cpp.

◆ 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:

for (int y = 0; y < image.height(); ++y) {
QRgb *line = reinterpret_cast<QRgb*>(image.scanLine(y));
for (int x = 0; x < image.width(); ++x) {
QRgb &rgb = line[x];
}
}
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 1639 of file qimage.cpp.

References d, detach(), and i.

Referenced by QCoreTextFontEngine::alphaMapForGlyph(), QRasterBuffer::colorizeBitmap(), convertWithPalette(), QCommonStyle::generatedIconPixmap(), QQC2::QCommonStyle::generatedIconPixmap(), grayscale(), mygetcanvasline(), operator==(), pixelIndex(), QT_BEGIN_NAMESPACE::qt_blurrow(), QPlatformPixmap::setMask(), setPixel(), setPixelColor(), QRfbRawEncoder::write(), and QTiffHandler::write().

+ 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 1656 of file qimage.cpp.

References d, i, and Q_ASSERT.

◆ 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 4556 of file qimage.cpp.

References QPainter::CompositionMode_DestinationIn, convertTo(), convertToFormat(), d, detach(), QPainter::drawImage(), Format_Alpha8, Format_Grayscale8, isNull(), painter, qt_alphaVersionForPainting(), qWarning, rect(), QPainter::setCompositionMode(), QPainter::setRenderHint(), and QPainter::SmoothPixmapTransform.

+ Here is the call 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 1597 of file qimage.cpp.

References d, detachMetadata(), i, qAlpha(), qWarning, and setColorCount().

Referenced by QWindowsDirect2DPaintEngine::drawPixmap(), and QPlatformCursorImage::set().

+ 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 2140 of file qimage.cpp.

References colorCount(), d, detachMetadata(), i, and qWarning.

Referenced by QPlatformCursorImage::set(), and setColor().

+ 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 5021 of file qimage.cpp.

References QColorSpace::colorModel(), colorSpace(), d, detachMetadata(), QColorSpace::isValid(), pixelFormat(), and qt_compatibleColorModel().

+ Here is the call graph for this function:

◆ setColorTable()

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

Referenced by convertWithPalette().

+ Here is the caller graph for this function:

◆ 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 1512 of file qimage.cpp.

References d, and detachMetadata().

Referenced by QtWaylandClient::QWaylandShmBuffer::QWaylandShmBuffer(), QBackingStore::beginPaint(), QRasterBackingStore::beginPaint(), QQuickContext2DImageTexture::beginPainting(), QPixmapDropShadowFilter::draw(), QT_BEGIN_NAMESPACE::expblur(), QQuickRenderControlPrivate::grab(), QRhiWidgetPrivate::grabFramebuffer(), QtWaylandClient::QWaylandShmBuffer::imageInsideMargins(), qt_halfScaled(), QWasmBackingStore::resize(), and QRasterPlatformPixmap::toImage().

+ 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 4124 of file qimage.cpp.

References d, and detachMetadata().

+ 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 4146 of file qimage.cpp.

References d, and detachMetadata().

+ 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 4178 of file qimage.cpp.

References d, and detachMetadata().

+ 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 325 of file qimage.h.

References setPixel(), QPoint::x(), and QPoint::y().

+ 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 2596 of file qimage.cpp.

References ARGB2RGBA(), d, format(), Format_A2BGR30_Premultiplied, Format_A2RGB30_Premultiplied, Format_ARGB32, Format_ARGB32_Premultiplied, Format_BGR30, Format_Indexed8, Format_Invalid, Format_Mono, Format_MonoLSB, Format_RGB16, Format_RGB30, Format_RGB32, Format_RGBA16FPx4, Format_RGBA16FPx4_Premultiplied, Format_RGBA32FPx4, Format_RGBA32FPx4_Premultiplied, Format_RGBA64, Format_RGBA64_Premultiplied, Format_RGBA8888, Format_RGBA8888_Premultiplied, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX64, Format_RGBX8888, QRgba64::fromArgb32(), QRgbaFloat< F >::fromArgb32(), hasAlphaChannel(), layout, NImageFormats, Q_ASSERT, qConvertArgb32ToA2rgb30< PixelOrderBGR >(), qConvertArgb32ToA2rgb30< PixelOrderRGB >(), qConvertRgb32To16(), qConvertRgb32ToRgb30< PixelOrderBGR >(), qConvertRgb32ToRgb30< PixelOrderRGB >(), qPixelLayouts, qWarning, and scanLine().

Referenced by convertWithPalette(), Viewer::createImage(), QImageTextureGlyphCache::fillTexture(), QTgaFile::readImage(), setPixel(), and setPixelColor().

+ 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 327 of file qimage.h.

References setPixelColor(), QPoint::x(), and QPoint::y().

+ 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 2796 of file qimage.cpp.

References d, Format_A2BGR30_Premultiplied, Format_A2RGB30_Premultiplied, Format_BGR30, Format_Indexed8, Format_Mono, Format_MonoLSB, Format_RGB30, Format_RGBA16FPx4, Format_RGBA16FPx4_Premultiplied, Format_RGBA32FPx4, Format_RGBA32FPx4_Premultiplied, Format_RGBA64, Format_RGBA64_Premultiplied, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX64, hasAlphaChannel(), QPixelLayout::premultiplied, QRgbaFloat< F >::premultiplied(), qConvertRgb64ToRgb30< PixelOrderBGR >(), qConvertRgb64ToRgb30< PixelOrderRGB >(), qPixelLayouts, qWarning, scanLine(), QRgba64::setAlpha(), and setPixel().

Referenced by setPixelColor().

+ 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:

QImageWriter writer;
writer.setFormat("png");
if (writer.supportsOption(QImageIOHandler::Description))
qDebug() << "Png supports embedded text";

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

See also
text(), textKeys()

Definition at line 4248 of file qimage.cpp.

References d, and detachMetadata().

+ Here is the call graph for this function:

◆ size()

◆ 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 1550 of file qimage.cpp.

References d.

Referenced by QtWaylandClient::QWaylandShmBuffer::~QWaylandShmBuffer(), QEglFSKmsGbmCursor::changeCursor(), QGIFFormat::decode(), QRhiMetal::enqueueSubresUpload(), QSharedImageLoaderPrivate::load(), QImageVideoBuffer::map(), AndroidTextureVideoBuffer::map(), QtWaylandClient::QWaylandShmBackingStore::recreateBackBufferIfNeeded(), QRhiMetal::subresUploadByteSize(), and QRhiVulkan::subresUploadByteSize().

+ Here is the caller graph for this function:

◆ smoothScaled()

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

Returns a smoothly scaled copy of the image. The returned image has a size of width w by height h pixels.

The function operates internally on Format_RGB32, Format_ARGB32_Premultiplied, Format_RGBX8888, Format_RGBA8888_Premultiplied, Format_RGBX64, or Format_RGBA64_Premultiplied and will convert to those formats if necessary. To avoid unnecessary conversion the result is returned in the format internally used, and not in the original format.

Definition at line 4673 of file qimage.cpp.

References convertTo(), copyMetadata(), d, Format_ARGB32_Premultiplied, Format_Grayscale16, Format_RGB32, Format_RGBA16FPx4, Format_RGBA16FPx4_Premultiplied, Format_RGBA32FPx4, Format_RGBA32FPx4_Premultiplied, Format_RGBA64, Format_RGBA64_Premultiplied, Format_RGBA8888_Premultiplied, Format_RGBX16FPx4, Format_RGBX32FPx4, Format_RGBX64, Format_RGBX8888, and qSmoothScaleImage().

+ 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 106 of file qimage.h.

References d, other(), and qt_ptr_swap().

+ 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 4208 of file qimage.cpp.

References QSet< T >::begin(), QString::chop(), d, QString::isEmpty(), and it.

+ Here is the call 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 4196 of file qimage.cpp.

References d.

◆ toImageFormat()

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

Converts format into a QImage::Format.

Definition at line 6410 of file qimage.cpp.

References i, and pixelformats.

Referenced by QPlatformGraphicsBufferHelper::bindSWToTexture(), and QBackingStoreDefaultCompositor::flush().

+ Here is the caller graph for this function:

◆ toPixelFormat()

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

Converts format into a QPixelFormat.

Definition at line 6401 of file qimage.cpp.

References pixelformats, and Q_ASSERT.

Referenced by QXcbNativeBackingStore::QXcbNativeBackingStore(), convertedToColorSpace(), convertToColorSpace(), QRhiBackingStore::format(), pixelFormat(), and QWindowsBackingStore::resize().

+ Here is the caller graph for this function:

◆ transformed()

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

Referenced by overview_viewfinder_orientation().

+ Here is the caller graph for this function:

◆ trueMatrix()

QImage Q_TRACE_INSTRUMENTQTransform QImage::trueMatrix ( const QTransform & ,
int w,
int h )
static

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}

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 4986 of file qimage.cpp.

Referenced by QPixmap::trueMatrix().

+ 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 322 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 2437 of file qimage.cpp.

References d.

◆ width()

int QImage::width ( ) const

Returns the width of the image.

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

Referenced by QSvgImage::QSvgImage(), QFontEngine::addBitmapFontToPath(), QAlphaWidget::alphaBlend(), QCoreTextFontEngine::alphaMapForGlyph(), QWindowsFontEngineDirectWrite::alphaMapForGlyph(), QFontEngine::alphaMapForGlyph(), QFontEngine::alphaRGBMapForGlyph(), QEglFSKmsGbmCursor::changeCursor(), QSGPlainTexture::commitTextureOperations(), QQuickVisualTestUtils::compareImages(), QQuickMaskExtruder::contains(), QDeclarativeGeoMapCopyrightNotice::copyrightsImageChanged(), Viewer::createImage(), QSGOpenVGRenderContext::createTexture(), QGIFFormat::decode(), QPdfEngine::drawImage(), QOpenGL2PaintEngineEx::drawImage(), QOpenGL2PaintEngineEx::drawPixmap(), QGeoTiledMapNokia::evaluateCopyrights(), QT_BEGIN_NAMESPACE::expblur(), QImageTextureGlyphCache::fillTexture(), QWindowsDirect2DBitmap::fromImage(), QCommonStyle::generatedIconPixmap(), QQC2::QCommonStyle::generatedIconPixmap(), QuickTestResult::grabImage(), QBsdFbScreen::grabWindow(), QIntegrityFbScreen::grabWindow(), QLinuxFbScreen::grabWindow(), QVncScreen::grabWindow(), grayscale(), iconToQXdgDBusImageVector(), QCoreTextFontEngine::imageForGlyph(), imageHasNarrowOutlines(), QSpanData::initTexture(), QSSGLoadedTexture::loadCompressedImage(), qSmoothScaleImage(), QT_BEGIN_NAMESPACE::qt_blurrow(), qt_createIconMask(), qt_halfScaled(), QDeclarativeGeoMapCopyrightNotice::rasterizeHtmlAndUpdate(), QOpenGLTextureUploader::textureImage(), QQuickNinePatchImagePrivate::updatePatches(), QWasmBackingStore::updateTexture(), QQuickCanvasPixmap::width(), Jpeg2000JasperReader::write(), and QQuick3DPhysicsHeightField::writeSamples().

+ Here is the caller graph for this function:

Friends And Related Symbol 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 309 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);
QHostInfo info
[0]

◆ QImageData

friend struct QImageData
friend

Definition at line 311 of file qimage.h.

◆ QPixmapCacheEntry

friend class QPixmapCacheEntry
friend

Definition at line 310 of file qimage.h.

◆ QRasterPlatformPixmap

friend class QRasterPlatformPixmap
friend

Definition at line 308 of file qimage.h.


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