Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtGui More...
#include <qimage.h>
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. | |
QImage & | operator= (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(). | |
uchar * | bits () |
Returns a pointer to the first pixel data. | |
const uchar * | 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. | |
const uchar * | constBits () const |
Returns a pointer to the first pixel data. | |
qsizetype | sizeInBytes () const |
uchar * | scanLine (int) |
Returns a pointer to the pixel data at the scanline with index i. | |
const uchar * | scanLine (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 uchar * | constScanLine (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< QRgb > | 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. | |
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. | |
QPaintEngine * | paintEngine () 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. | |
DataPtr & | data_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 QPaintDevice * | redirected (QPoint *offset) const |
virtual QPainter * | sharedPainter () 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 | |
QDataStream & | operator<< (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. | |
QDataStream & | operator>> (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 |
\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.
enum QImage::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.
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
formatsenum QImage::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.
Enumerator | |
---|---|
InvertRgb | |
InvertRgba |
|
noexcept |
Constructs an image with the given size and format.
A \l{isNull()}{null} image is returned if memory cannot be allocated.
Definition at line 819 of file qimage.cpp.
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.
Definition at line 805 of file qimage.cpp.
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::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::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::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.
|
explicit |
Constructs an image from the given xpm image.
Make sure that the image is a valid XPM image. Errors are silently ignored.
Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:
The extra const
makes the entire definition read-only, which is slightly more efficient (e.g., when the code is in a shared library) and able to be stored in ROM with the application.
Definition at line 1024 of file qimage.cpp.
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.
Definition at line 998 of file qimage.cpp.
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.
Definition at line 1045 of file qimage.cpp.
|
inlinenoexcept |
QImage::~QImage | ( | ) |
Destroys the image and cleans up.
Definition at line 1062 of file qimage.cpp.
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.
Definition at line 2868 of file qimage.cpp.
void QImage::applyColorTransform | ( | const QColorTransform & | transform | ) |
Applies the color transformation transform to all pixels in the image.
Definition at line 5199 of file qimage.cpp.
void QImage::applyColorTransform | ( | const QColorTransform & | transform, |
QImage::Format | toFormat, | ||
Qt::ImageConversionFlags | flags = Qt::AutoColor ) |
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.
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.
Definition at line 4613 of file qimage.cpp.
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.
Definition at line 1694 of file qimage.cpp.
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.
qsizetype QImage::bytesPerLine | ( | ) | const |
Returns the number of bytes per image scanline.
This is equivalent to sizeInBytes() / height() if height() is non-zero.
Definition at line 1556 of file qimage.cpp.
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.
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.
Definition at line 1573 of file qimage.cpp.
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.
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.
QColorSpace QImage::colorSpace | ( | ) | const |
Returns the color space of the image if a color space is defined.
Definition at line 5187 of file qimage.cpp.
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.
Definition at line 1462 of file qimage.cpp.
QImage QImage::colorTransformed | ( | const QColorTransform & | transform | ) | && |
Returns the image color transformed using transform on all pixels in the image.
Definition at line 5830 of file qimage.cpp.
QImage QImage::colorTransformed | ( | const QColorTransform & | transform | ) | const & |
Returns the image color transformed using transform on all pixels in the image.
Definition at line 5360 of file qimage.cpp.
QImage QImage::colorTransformed | ( | const QColorTransform & | transform, |
QImage::Format | format, | ||
Qt::ImageConversionFlags | flags = Qt::AutoColor ) && |
Returns the image color transformed using transform on all pixels in the image.
Definition at line 5868 of file qimage.cpp.
QImage QImage::colorTransformed | ( | const QColorTransform & | transform, |
QImage::Format | toFormat, | ||
Qt::ImageConversionFlags | flags = Qt::AutoColor ) const & |
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.
Definition at line 5445 of file qimage.cpp.
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.
Definition at line 1729 of file qimage.cpp.
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.
Definition at line 1674 of file qimage.cpp.
|
inlinenodiscard |
|
inlinenodiscard |
|
nodiscard |
Returns the image converted to colorSpace.
If the image has no valid color space, a null QImage is returned.
Definition at line 5114 of file qimage.cpp.
|
nodiscard |
Definition at line 5163 of file qimage.cpp.
|
nodiscard |
Definition at line 5143 of file qimage.cpp.
void QImage::convertTo | ( | Format | format, |
Qt::ImageConversionFlags | flags = Qt::AutoColor ) |
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.
Definition at line 2395 of file qimage.cpp.
void QImage::convertToColorSpace | ( | const QColorSpace & | colorSpace | ) |
Converts the image to colorSpace.
If the image has no valid color space, the method does nothing.
Definition at line 5046 of file qimage.cpp.
void QImage::convertToColorSpace | ( | const QColorSpace & | colorSpace, |
QImage::Format | format, | ||
Qt::ImageConversionFlags | flags = Qt::AutoColor ) |
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.
Definition at line 5080 of file qimage.cpp.
|
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.
|
inlinenodiscard |
|
inlinenodiscard |
|
protected |
Definition at line 2191 of file qimage.cpp.
|
protected |
Definition at line 2237 of file qimage.cpp.
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.
|
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.
|
nodiscard |
|
nodiscard |
|
nodiscard |
int QImage::depth | ( | ) | const |
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.
Definition at line 1124 of file qimage.cpp.
A variant for metadata-only detach, which will not detach readonly image data, and only invalidate caches of the image data if asked to.
Definition at line 1147 of file qimage.cpp.
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().
Definition at line 1529 of file qimage.cpp.
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.
Definition at line 1478 of file qimage.cpp.
|
overridevirtual |
Reimplemented from QPaintDevice.
Definition at line 1100 of file qimage.cpp.
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.
Definition at line 4082 of file qimage.cpp.
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.
Definition at line 4095 of file qimage.cpp.
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.
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.
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.
Definition at line 1754 of file qimage.cpp.
QImage::Format QImage::format | ( | ) | const |
Returns the format of the image.
Definition at line 2158 of file qimage.cpp.
|
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.
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.
|
static |
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.
Definition at line 3837 of file qimage.cpp.
bool QImage::hasAlphaChannel | ( | ) | const |
Returns true
if the image has a format that respects the alpha channel, otherwise returns false
.
Definition at line 4591 of file qimage.cpp.
int QImage::height | ( | ) | const |
Returns the height of the image.
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.
Definition at line 1983 of file qimage.cpp.
bool QImage::isDetached | ( | ) | const |
Returns true
if the image is detached; otherwise returns false
.
Definition at line 4525 of file qimage.cpp.
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
.
Definition at line 2944 of file qimage.cpp.
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.
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.
Definition at line 3763 of file qimage.cpp.
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.
|
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.
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.
bool QImage::loadFromData | ( | QByteArrayView | data, |
const char * | format = nullptr ) |
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.
Definition at line 3795 of file qimage.cpp.
|
overrideprotectedvirtual |
Returns the size for the specified metric on the device.
Reimplemented from QPaintDevice.
Definition at line 4274 of file qimage.cpp.
Mirrors of the image in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false.
|
protected |
Definition at line 3476 of file qimage.cpp.
|
protected |
Definition at line 3504 of file qimage.cpp.
QPoint QImage::offset | ( | ) | const |
Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images.
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().
QImage::operator QVariant | ( | ) | const |
Returns the image as a QVariant.
Definition at line 1108 of file qimage.cpp.
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.
Definition at line 4066 of file qimage.cpp.
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.
For more information about shallow copies, see the \l {Implicit Data Sharing} documentation.
Definition at line 1078 of file qimage.cpp.
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.
Definition at line 4001 of file qimage.cpp.
|
overridevirtual |
Used by QPainter to retrieve a paint engine for the image.
Implements QPaintDevice.
Definition at line 4251 of file qimage.cpp.
Returns the color of the pixel at the given position.
If the position is not valid, the results are undefined.
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.
Returns the color of the pixel at the given position as a QColor.
If the position is not valid, an invalid QColor is returned.
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.
Returns the color of the pixel at coordinates (x, y) as a QColor.
Definition at line 2705 of file qimage.cpp.
|
noexcept |
Returns the QImage::Format as a QPixelFormat.
Definition at line 6417 of file qimage.cpp.
|
inline |
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.
QRect QImage::rect | ( | ) | const |
bool QImage::reinterpretAsFormat | ( | Format | format | ) |
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.
true
if the depths are compatible. Operations on an image with invalid data are undefined.Definition at line 2361 of file qimage.cpp.
|
inline |
Swaps the values of the red and blue components of all pixels, effectively converting an RGB image to an BGR image.
|
protected |
|
protected |
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
.
Definition at line 3884 of file qimage.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function writes a QImage to the given device.
This can, for example, be used to save an image directly into a QByteArray:
Definition at line 3903 of file qimage.cpp.
|
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 the given size is empty, this function returns a null image.
|
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.
|
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.
|
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.
Definition at line 3033 of file qimage.cpp.
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:
{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.Definition at line 1633 of file qimage.cpp.
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.
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
.
Definition at line 4550 of file qimage.cpp.
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().
Definition at line 1591 of file qimage.cpp.
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.
Definition at line 2128 of file qimage.cpp.
void QImage::setColorSpace | ( | const QColorSpace & | colorSpace | ) |
Sets the image color space to colorSpace without performing any conversions on image data.
Definition at line 5020 of file qimage.cpp.
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}).
Definition at line 1506 of file qimage.cpp.
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.
Definition at line 4112 of file qimage.cpp.
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.
Definition at line 4134 of file qimage.cpp.
Sets the number of pixels by which the image is intended to be offset by when positioning relative to other images, to offset.
Definition at line 4166 of file qimage.cpp.
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.
{detach()} function called within; if performance is a concern, we recommend the use of scanLine() or bits() to access pixel data directly.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.
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.
{detach()} function called within; if performance is a concern, we recommend the use of scanLine() or bits() to access pixel data directly.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 color at (x, y) to color.
Definition at line 2784 of file qimage.cpp.
Sets the image text to the given text and associate it with the given key.
If you just want to store a single text block (i.e., a "comment" or just a description), you can either pass an empty key, or use a generic key like "Description".
The image text is embedded into the image data when you call save() or QImageWriter::write().
Not all image formats support embedded text. You can find out if a specific image or format supports embedding text by using QImageWriter::supportsOption(). We give an example:
You can use QImageWriter::supportedImageFormats() to find out which image formats are available to you.
Definition at line 4236 of file qimage.cpp.
QSize QImage::size | ( | ) | const |
Returns the size of the image, i.e.
qsizetype QImage::sizeInBytes | ( | ) | const |
Definition at line 1544 of file qimage.cpp.
|
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.
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.
Definition at line 4196 of file qimage.cpp.
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.
Definition at line 4184 of file qimage.cpp.
|
staticnoexcept |
Converts format into a QImage::Format.
Definition at line 6434 of file qimage.cpp.
|
staticnoexcept |
Converts format into a QPixelFormat.
Definition at line 6425 of file qimage.cpp.
|
nodiscard |
|
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.
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.
Definition at line 4985 of file qimage.cpp.
|
inline |
Returns true
if pos is a valid coordinate pair within the image; otherwise returns false
.
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.
int QImage::width | ( | ) | const |
Returns the width of the 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.
|
related |
Reads an image from the given stream and stores it in the given image.
|
friend |
|
related |
A function with the following signature that can be used to implement basic image memory management:
|
friend |
|
friend |
|
friend |