Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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 ,
  PdmDevicePixelRatioF_EncodedA , PdmDevicePixelRatioF_EncodedB
}
 

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
 \memberswap{image}
 
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
 Returns the number of bit planes in the image.
 
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)
 Resizes the color table to contain colorCount entries.
 
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.Fills the image with the given color, described as a standard global color.
 
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 &
 
QImage convertedToColorSpace (const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags=Qt::AutoColor) &&
 
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 ()
 
static int encodeMetricF (PaintDeviceMetric metric, double value)
 

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
 
double getDecodedMetricF (PaintDeviceMetric metricA, PaintDeviceMetric metricB) 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 317 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 789 of file qimage.cpp.

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

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

◆ QImage() [5/11]

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

Constructs an image with the given width, height and format, that uses an existing read-only memory buffer, data.

The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.

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

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

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

Definition at line 917 of file qimage.cpp.

◆ QImage() [6/11]

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

Constructs an image with the given width, height and format, that uses an existing memory buffer, data.

The width and height must be specified in pixels. bytesPerLine specifies the number of bytes per line (stride).

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

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

Definition at line 941 of file qimage.cpp.

◆ QImage() [7/11]

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

Constructs an image with the given width, height and format, that uses an existing memory buffer, data.

The width and height must be specified in pixels. bytesPerLine specifies the number of bytes per line (stride).

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

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

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

Definition at line 972 of file qimage.cpp.

◆ QImage() [8/11]

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

Constructs an image from the given xpm image.

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

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

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

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

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

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

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

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

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

◆ bitPlaneCount()

int QImage::bitPlaneCount ( ) const

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

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

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

◆ bytesPerLine()

qsizetype QImage::bytesPerLine ( ) const

Returns the number of bytes per image scanline.

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

See also
scanLine()

Definition at line 1556 of file qimage.cpp.

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

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

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

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}

◆ colorSpace()

QColorSpace QImage::colorSpace ( ) const
Since
5.14

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

Definition at line 5187 of file qimage.cpp.

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

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

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

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

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

Definition at line 1729 of file qimage.cpp.

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

Definition at line 1674 of file qimage.cpp.

◆ convertedTo() [1/2]

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

Definition at line 140 of file qimage.h.

◆ convertedTo() [2/2]

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

Definition at line 138 of file qimage.h.

◆ convertedToColorSpace() [1/3]

QImage QImage::convertedToColorSpace ( const QColorSpace & colorSpace) const
nodiscard
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 5114 of file qimage.cpp.

◆ convertedToColorSpace() [2/3]

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

Definition at line 5163 of file qimage.cpp.

◆ convertedToColorSpace() [3/3]

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

Definition at line 5143 of file qimage.cpp.

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

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

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

◆ convertToFormat() [1/3]

QImage QImage::convertToFormat ( Format format,
const QList< QRgb > & colorTable,
Qt::ImageConversionFlags flags = Qt::AutoColor ) const
nodiscard

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

◆ convertToFormat() [2/3]

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

Definition at line 127 of file qimage.h.

◆ convertToFormat() [3/3]

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

Definition at line 125 of file qimage.h.

◆ convertToFormat_helper()

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

Definition at line 2191 of file qimage.cpp.

◆ convertToFormat_inplace()

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

Definition at line 2237 of file qimage.cpp.

◆ copy() [1/2]

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

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

◆ copy() [2/2]

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

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.

◆ createAlphaMask()

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

◆ createHeuristicMask()

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

◆ createMaskFromColor()

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

◆ data_ptr()

DataPtr & QImage::data_ptr ( )
inline

Definition at line 318 of file qimage.h.

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

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

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

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

◆ devType()

int QImage::devType ( ) const
overridevirtual

Reimplemented from QPaintDevice.

Definition at line 1100 of file qimage.cpp.

◆ dotsPerMeterX()

int QImage::dotsPerMeterX ( ) const

Returns the number of pixels that fit horizontally in a physical meter.

Together with dotsPerMeterY(), this number defines the intended scale and aspect ratio of the image.

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

Definition at line 4082 of file qimage.cpp.

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

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

Definition at line 1861 of file qimage.cpp.

◆ 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.Fills the image with the given color, described as a standard global color.

Definition at line 1839 of file qimage.cpp.

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

◆ format()

QImage::Format QImage::format ( ) const

Returns the format of the image.

See also
{QImage#Image Formats}{Image Formats}

Definition at line 2158 of file qimage.cpp.

◆ fromData() [1/3]

static 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 262 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 3854 of file qimage.cpp.

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

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

◆ height()

int QImage::height ( ) const

Returns the height of the image.

See also
{QImage#Image Information}{Image Information}

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

◆ isDetached()

bool QImage::isDetached ( ) const

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

See also
detach(), {Implicit Data Sharing}

Definition at line 4525 of file qimage.cpp.

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

◆ isNull()

bool QImage::isNull ( ) const

Returns true if it is a null image, otherwise returns false.

A null image has all parameters set to zero and no allocated data.

Definition at line 1332 of file qimage.cpp.

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

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

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

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

◆ metric()

int QImage::metric ( PaintDeviceMetric metric) const
overrideprotectedvirtual

Returns the size for the specified metric on the device.

Reimplemented from QPaintDevice.

Definition at line 4274 of file qimage.cpp.

◆ 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 ) &&
inlinenodiscard

Definition at line 221 of file qimage.h.

◆ mirrored() [2/2]

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

Definition at line 219 of file qimage.h.

◆ mirrored_helper()

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

Definition at line 3476 of file qimage.cpp.

◆ mirrored_inplace()

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

Definition at line 3504 of file qimage.cpp.

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

Referenced by testing.tools.fixup_pdf_template.TemplateProcessor::insert_xref_entry(), and testing.tools.fixup_pdf_template.TemplateProcessor::process_line().

+ Here is the caller graph for this function:

◆ operator QVariant()

QImage::operator QVariant ( ) const

Returns the image as a QVariant.

Definition at line 1108 of file qimage.cpp.

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

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

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

◆ paintEngine()

QPaintEngine * QImage::paintEngine ( ) const
overridevirtual

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

Implements QPaintDevice.

Definition at line 4251 of file qimage.cpp.

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

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

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

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

◆ pixelFormat()

QPixelFormat QImage::pixelFormat ( ) const
noexcept

Returns the QImage::Format as a QPixelFormat.

Definition at line 6417 of file qimage.cpp.

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

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

◆ rect()

QRect QImage::rect ( ) const

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

See also
{QImage#Image Information}{Image Information}

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

◆ 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 ( ) &&
inlinenodiscard

Definition at line 225 of file qimage.h.

◆ rgbSwapped() [2/2]

QImage QImage::rgbSwapped ( ) const &
inlinenodiscard

Definition at line 223 of file qimage.h.

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

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

◆ scaled() [1/2]

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

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
inlinenodiscard

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.

◆ scaledToHeight()

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

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 QImage::scaledToWidth ( int width,
Qt::TransformationMode mode = Qt::FastTransformation ) const
nodiscard

[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 3033 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 1633 of file qimage.cpp.

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

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

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

◆ setColorCount()

void QImage::setColorCount ( int colorCount)

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

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

◆ setColorTable()

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

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

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

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

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

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

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

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

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

◆ 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");
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 4236 of file qimage.cpp.

◆ size()

QSize QImage::size ( ) const

Returns the size of the image, i.e.

its width() and height().

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

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

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

◆ swap()

void QImage::swap ( QImage & other)
inlinenoexcept

\memberswap{image}

Definition at line 106 of file qimage.h.

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

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

◆ toImageFormat()

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

Converts format into a QImage::Format.

Definition at line 6434 of file qimage.cpp.

◆ toPixelFormat()

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

Converts format into a QPixelFormat.

Definition at line 6425 of file qimage.cpp.

◆ transformed()

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

◆ trueMatrix()

static QTransform 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 4985 of file qimage.cpp.

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

◆ width()

int QImage::width ( ) const

Returns the width of the image.

See also
{QImage#Image Information}{Image Information}

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 312 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 314 of file qimage.h.

◆ QPixmapCacheEntry

friend class QPixmapCacheEntry
friend

Definition at line 313 of file qimage.h.

◆ QRasterPlatformPixmap

friend class QRasterPlatformPixmap
friend

Definition at line 311 of file qimage.h.


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