Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Functions | Properties | Friends | Related Functions | List of all members
QImage Class Reference

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

#include <qimage.h>

Inheritance diagram for QImage:
QPaintDevice

Public Types

typedef QImageDataDataPtr
 
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
}
 The following image formats are available in Qt. More...
 
enum  InvertMode { InvertRgb, InvertRgba }
 This enum type is used to describe how pixel values should be inverted in the invertPixels() function. More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 

Public Functions

bool allGray () const
 Returns true if all the colors in the image are shades of gray (i.e. More...
 
QImage alphaChannel () const
 Returns the alpha channel of the image as a new grayscale QImage in which each pixel's red, green, and blue values are given the alpha value of the original image. More...
 
int bitPlaneCount () const
 Returns the number of bit planes in the image. More...
 
ucharbits ()
 Returns a pointer to the first pixel data. More...
 
const ucharbits () const
 Note that QImage uses 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. More...
 
int byteCount () const
 Returns the number of bytes occupied by the image data. More...
 
int bytesPerLine () const
 Returns the number of bytes per image scanline. More...
 
qint64 cacheKey () const
 Returns a number that identifies the contents of this QImage object. More...
 
QRgb color (int i) const
 Returns the color in the color table at index i. More...
 
int colorCount () const
 Returns the size of the color table for the image. More...
 
QVector< 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. More...
 
const ucharconstBits () const
 Returns a pointer to the first pixel data. More...
 
const ucharconstScanLine (int) const
 Returns a pointer to the pixel data at the scanline with index i. More...
 
QImage convertToFormat (Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
 Returns a copy of the image in the given format. More...
 
QImage convertToFormat (Format f, const QVector< QRgb > &colorTable, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
 Returns a copy of the image converted to the given format, using the specified colorTable. More...
 
QImage copy (const QRect &rect=QRect()) const
 Returns a sub-area of the image as a new image. More...
 
QImage copy (int x, int y, int w, int h) const
 The returned image is copied from the position (x, y) in this image, and will always have the given width and height. More...
 
QImage createAlphaMask (Qt::ImageConversionFlags flags=Qt::AutoColor) const
 Builds and returns a 1-bpp mask from the alpha buffer in this image. More...
 
QImage createHeuristicMask (bool clipTight=true) const
 Creates and returns a 1-bpp heuristic mask for this image. More...
 
QImage createMaskFromColor (QRgb color, Qt::MaskMode mode=Qt::MaskInColor) const
 Creates and returns a mask for this image based on the given color value. More...
 
DataPtrdata_ptr ()
 
int depth () const
 Returns the depth of the image. More...
 
void 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. More...
 
int devType () const
 
int dotsPerMeterX () const
 Returns the number of pixels that fit horizontally in a physical meter. More...
 
int dotsPerMeterY () const
 Returns the number of pixels that fit vertically in a physical meter. More...
 
void fill (uint pixel)
 Fills the entire image with the given pixelValue. More...
 
void fill (const QColor &color)
 Fills the entire image with the given color. More...
 
void fill (Qt::GlobalColor color)
 Fills the image with the given color, described as a standard global color. More...
 
Format format () const
 Returns the format of the image. More...
 
bool hasAlphaChannel () const
 Returns true if the image has a format that respects the alpha channel, otherwise returns false. More...
 
int height () const
 Returns the height of the image. More...
 
void invertPixels (InvertMode=InvertRgb)
 Inverts all pixel values in the image. More...
 
bool isDetached () const
 Returns true if the image is detached; otherwise returns false. More...
 
bool isGrayscale () const
 For 32-bit images, this function is equivalent to allGray(). More...
 
bool isNull () const
 Returns true if it is a null image, otherwise returns false. More...
 
bool load (QIODevice *device, const char *format)
 This function reads a QImage from the given device. More...
 
bool load (const QString &fileName, const char *format=0)
 Loads an image from the file with the given fileName. More...
 
bool loadFromData (const uchar *buf, int len, const char *format=0)
 Loads an image from the first len bytes of the given binary data. More...
 
bool loadFromData (const QByteArray &data, const char *aformat=0)
 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. More...
 
QImage mirrored (bool horizontally=false, bool vertically=true) const
 Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false. More...
 
QT_DEPRECATED int numBytes () const
 Returns the number of bytes occupied by the image data. More...
 
QT_DEPRECATED int numColors () const
 Returns the size of the color table for the image. More...
 
QPoint offset () const
 Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images. More...
 
 operator QVariant () const
 Returns the image as a QVariant. More...
 
bool operator!= (const QImage &) const
 Returns true if this image and the given image have different contents; otherwise returns false. More...
 
QImageoperator= (const QImage &)
 Assigns a shallow copy of the given image to this image and returns a reference to this image. More...
 
bool operator== (const QImage &) const
 Returns true if this image and the given image have the same contents; otherwise returns false. More...
 
QPaintEnginepaintEngine () const
 Used by QPainter to retrieve a paint engine for the image. More...
 
QRgb pixel (int x, int y) const
 Returns the color of the pixel at coordinates (x, y). More...
 
QRgb pixel (const QPoint &pt) const
 Returns the color of the pixel at the given position. More...
 
int pixelIndex (int x, int y) const
 Returns the pixel index at (x, y). More...
 
int pixelIndex (const QPoint &pt) const
 Returns the pixel index at the given position. More...
 
 QImage ()
 Constructs a null image. More...
 
 QImage (const QSize &size, Format format)
 Constructs an image with the given size and format. More...
 
 QImage (int width, int height, Format format)
 Constructs an image with the given width, height and format. More...
 
 QImage (uchar *data, int width, int height, Format format)
 Constructs an image with the given width, height and format, that uses an existing memory buffer, data. More...
 
 QImage (const uchar *data, int width, int height, Format format)
 Constructs an image with the given width, height and format, that uses an existing read-only memory buffer, data. More...
 
 QImage (uchar *data, int width, int height, int bytesPerLine, Format format)
 Constructs an image with the given width, height and format, that uses an existing memory buffer, data. More...
 
 QImage (const uchar *data, int width, int height, int bytesPerLine, Format format)
 Constructs an image with the given width, height and format, that uses an existing memory buffer, data. More...
 
 QImage (const char *const xpm[])
 Constructs an image from the given xpm image. More...
 
 QImage (const QString &fileName, const char *format=0)
 Constructs an image and tries to load the image from the file with the given fileName. More...
 
 QImage (const char *fileName, const char *format=0)
 Constructs an image and tries to load the image from the file with the given fileName. More...
 
 QImage (const QImage &)
 Constructs a shallow copy of the given image. More...
 
QRect rect () const
 Returns the enclosing rectangle (0, 0, width(), height()) of the image. More...
 
QImage rgbSwapped () const
 Returns a QImage in which the values of the red and blue components of all pixels have been swapped, effectively converting an RGB image to an BGR image. More...
 
bool save (const QString &fileName, const char *format=0, int quality=-1) const
 Saves the image to the file with the given fileName, using the given image file format and quality factor. More...
 
bool save (QIODevice *device, const char *format=0, int quality=-1) const
 This function writes a QImage to the given device. More...
 
QImage scaled (int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QImage scaled (const QSize &s, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QImage scaledToHeight (int h, Qt::TransformationMode mode=Qt::FastTransformation) const
 Returns a scaled copy of the image. More...
 
QImage scaledToWidth (int w, Qt::TransformationMode mode=Qt::FastTransformation) const
 Returns a scaled copy of the image. More...
 
ucharscanLine (int)
 Returns a pointer to the pixel data at the scanline with index i. More...
 
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. More...
 
int serialNumber () const
 Returns a number that identifies the contents of this QImage object. More...
 
void setAlphaChannel (const QImage &alphaChannel)
 Sets the alpha channel of this image to the given alphaChannel. More...
 
void setColor (int i, QRgb c)
 Sets the color at the given index in the color table, to the given to colorValue. More...
 
void setColorCount (int)
 Resizes the color table to contain colorCount entries. More...
 
void setColorTable (const QVector< QRgb > colors)
 Sets the color table used to translate color indexes to QRgb values, to the specified colors. More...
 
void setDotsPerMeterX (int)
 Sets the number of pixels that fit horizontally in a physical meter, to x. More...
 
void setDotsPerMeterY (int)
 Sets the number of pixels that fit vertically in a physical meter, to y. More...
 
QT_DEPRECATED void setNumColors (int)
 Resizes the color table to contain numColors entries. More...
 
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. More...
 
void setPixel (int x, int y, uint index_or_rgb)
 Sets the pixel index or color at (x, y) to index_or_rgb. More...
 
void setPixel (const QPoint &pt, uint index_or_rgb)
 Sets the pixel index or color at the given position to index_or_rgb. More...
 
void setText (const QString &key, const QString &value)
 Sets the image text to the given text and associate it with the given key. More...
 
QT_DEPRECATED void setText (const char *key, const char *lang, const QString &)
 
QSize size () const
 Returns the size of the image, i. More...
 
void swap (QImage &other)
 Swaps image other with this image. More...
 
QString text (const QString &key=QString()) const
 Returns the image text associated with the given key. More...
 
QT_DEPRECATED QString text (const char *key, const char *lang=0) const
 
QT_DEPRECATED QString text (const QImageTextKeyLang &) const
 Returns the text recorded for the given keywordAndLanguage. More...
 
QStringList textKeys () const
 Returns the text keys for this image. More...
 
QT_DEPRECATED QStringList textLanguages () const
 Returns the language identifiers for which some texts are recorded. More...
 
QT_DEPRECATED QList< QImageTextKeyLangtextList () const
 Returns a list of QImageTextKeyLang objects that enumerate all the texts key/language pairs set for this image. More...
 
QImage transformed (const QMatrix &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const
 Returns a copy of the image that is transformed using the given transformation matrix and transformation mode. More...
 
QImage transformed (const QTransform &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const
 Returns a copy of the image that is transformed using the given transformation matrix and transformation mode. More...
 
bool valid (int x, int y) const
 Returns true if QPoint(x, y) is a valid coordinate pair within the image; otherwise returns false. More...
 
bool valid (const QPoint &pt) const
 Returns true if pos is a valid coordinate pair within the image; otherwise returns false. More...
 
int width () const
 Returns the width of the image. More...
 
 ~QImage ()
 Destroys the image and cleans up. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
virtual HDC getDC () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
virtual void releaseDC (HDC hdc) const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Static Public Functions

static QImage fromData (const uchar *data, int size, const char *format=0)
 Constructs a QImage from the first size bytes of the given binary data. More...
 
static QImage fromData (const QByteArray &data, const char *format=0)
 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. More...
 
static QMatrix trueMatrix (const QMatrix &, int w, int h)
 Returns the actual matrix used for transforming an image with the given width, height and matrix. More...
 
static QTransform trueMatrix (const QTransform &, int w, int h)
 Returns the actual matrix used for transforming an image with the given width, height and matrix. More...
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 

Protected Functions

virtual int metric (PaintDeviceMetric metric) const
 Returns the size for the specified metric on the device. More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

QImageDatad
 

Friends

class QBlittablePixmapData
 
class QPixmapCacheEntry
 
class QRasterPixmapData
 
const QVector< QRgb > * qt_image_colortable (const QImage &image)
 
Q_GUI_EXPORT qint64 qt_image_id (const QImage &image)
 
class QWSOnScreenSurface
 

Related Functions

(Note that these are not member functions.)

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. More...
 
QDataStreamoperator>> (QDataStream &stream, QImage &image)
 Reads an image from the given stream and stores it in the given image. More...
 

Additional Inherited Members

- Protected Variables inherited from QPaintDevice
ushort painters
 

Detailed Description

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

Note
This class or function is reentrant.

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

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

The QImage class supports several image formats described by the 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 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 How To Create Qt Plugins::Static Plugins{Plugin HowTo}.
Warning
Painting on a QImage with the format QImage::Format_Indexed8 is not supported.

Reading and Writing Image Files

QImage provides several ways of loading an image file: The file can be loaded when constructing the QImage object, or by using the load() or loadFromData() functions later on. QImage also provides the static fromData() function, constructing a QImage from the given data. When loading an image, the file name can either refer to an actual file on disk or to one of the application's embedded resources. See The Qt Resource System overview for details on how to embed images and other resource files in the application's executable.

Simply call the save() function to save a QImage object.

The complete list of supported file formats are available through the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions. New file formats can be added as plugins. By default, Qt supports the following formats:

Format Description Qt's support
BMP Windows Bitmap Read/write
GIF Graphic Interchange Format (optional) Read
JPG Joint Photographic Experts Group Read/write
JPEG Joint Photographic Experts Group Read/write
PNG Portable Network Graphics Read/write
PBM Portable Bitmap Read
PGM Portable Graymap Read
PPM Portable Pixmap Read/write
TIFF Tagged Image File Format Read/write
XBM X11 Bitmap Read/write
XPM X11 Pixmap Read/write

Image Information

QImage provides a collection of functions that can be used to obtain a variety of information about the image:

Available Functions

Geometry

The size(), width(), height(), dotsPerMeterX(), and dotsPerMeterY() functions provide information about the image size and aspect ratio.

The rect() function returns the image's enclosing rectangle. The valid() function tells if a given pair of coordinates is within this rectangle. The offset() function returns the number of pixels by which the image is intended to be offset by when positioned relative to other images, which also can be manipulated using the setOffset() function.

Colors

The color of a pixel can be retrieved by passing its coordinates to the pixel() function. The pixel() function returns the color as a QRgb value indepedent of the image's format.

In case of monochrome and 8-bit images, the colorCount() and colorTable() functions provide information about the color components used to store the image data: The colorTable() function returns the image's entire color table. To obtain a single entry, use the pixelIndex() function to retrieve the pixel index for a given pair of coordinates, then use the color() function to retrieve the color. Note that if you create an 8-bit image manually, you have to set a valid color table on the image as well.

The hasAlphaChannel() function tells if the image's format respects the alpha channel, or not. The allGray() and isGrayscale() functions tell whether an image's colors are all shades of gray.

See also the Pixel Manipulation and Image Transformations sections.

Text

The text() function returns the image text associated with the given text key. An image's text keys can be retrieved using the textKeys() function. Use the setText() function to alter an image's text.

Low-level information

The depth() function returns the depth of the image. The supported depths are 1 (monochrome), 8, 16, 24 and 32 bits. The bitPlaneCount() function tells how many of those bits that are used. For more information see the Image Formats section.

The format(), bytesPerLine(), and byteCount() functions provide low-level information about the data stored in the image.

The cacheKey() function returns a number that uniquely identifies the contents of this QImage object.

Pixel Manipulation

The functions used to manipulate an image's pixels depend on the image format. The reason is that monochrome and 8-bit images are index-based and use a color lookup table, while 32-bit images store ARGB values directly. For more information on image formats, see the Image Formats section.

In case of a 32-bit image, the setPixel() function can be used to alter the color of the pixel at the given coordinates to any other color specified as an ARGB quadruplet. To make a suitable QRgb value, use the qRgb() (adding a default alpha component to the given RGB values, i.e. creating an opaque color) or qRgba() function. For example:

32-bit
qimage-32bit_scaled.png
QRgb value;
value = qRgb(189, 149, 39); // 0xffbd9527
image.setPixel(1, 1, value);
value = qRgb(122, 163, 39); // 0xff7aa327
image.setPixel(0, 1, value);
image.setPixel(1, 0, value);
value = qRgb(237, 187, 51); // 0xffedba31
image.setPixel(2, 1, value);

In case of a 8-bit and monchrome images, the pixel value is only an index from the image's color table. So the setPixel() function can only be used to alter the color of the pixel at the given coordinates to a predefined color from the image's color table, i.e. it can only change the pixel's index value. To alter or add a color to an image's color table, use the setColor() function.

An entry in the color table is an ARGB quadruplet encoded as an QRgb value. Use the qRgb() and qRgba() functions to make a suitable QRgb value for use with the setColor() function. For example:

8-bit
qimage-8bit_scaled.png
QRgb value;
value = qRgb(122, 163, 39); // 0xff7aa327
image.setColor(0, value);
value = qRgb(237, 187, 51); // 0xffedba31
image.setColor(1, value);
value = qRgb(189, 149, 39); // 0xffbd9527
image.setColor(2, value);
image.setPixel(0, 1, 0);
image.setPixel(1, 0, 0);
image.setPixel(1, 1, 2);
image.setPixel(2, 1, 1);

QImage also provide the scanLine() function which returns a pointer to the pixel data at the scanline with the given index, and the bits() function which returns a pointer to the first pixel data (this is equivalent to scanLine(0)).

Image Formats

Each pixel stored in a QImage is represented by an integer. The size of the integer varies depending on the format. QImage supports several image formats described by the Format enum.

Monochrome images are stored using 1-bit indexes into a color table with at most two colors. There are two different types of monochrome images: big endian (MSB first) or little endian (LSB first) bit order.

8-bit images are stored using 8-bit indexes into a color table, i.e. they have a single byte per pixel. The color table is a QVector<QRgb>, and the QRgb typedef is equivalent to an unsigned int containing an ARGB quadruplet on the format 0xAARRGGBB.

32-bit images have no color table; instead, each pixel contains an QRgb value. There are three different types of 32-bit images storing RGB (i.e. 0xffRRGGBB), ARGB and premultiplied ARGB values respectively. In the premultiplied format the red, green, and blue channels are multiplied by the alpha component divided by 255.

An image's format can be retrieved using the format() function. Use the convertToFormat() functions to convert an image into another format. The allGray() and isGrayscale() functions tell whether a color image can safely be converted to a grayscale image.

Image Transformations

QImage supports a number of functions for creating a new image that is a transformed version of the original: The createAlphaMask() function builds and returns a 1-bpp mask from the alpha buffer in this image, and the createHeuristicMask() function creates and returns a 1-bpp heuristic mask for this image. The latter function works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges.

The mirrored() function returns a mirror of the image in the desired direction, the scaled() returns a copy of the image scaled to a rectangle of the desired measures, and the rgbSwapped() function constructs a BGR image from a RGB image.

The scaledToWidth() and scaledToHeight() functions return scaled copies of the image.

The transformed() function returns a copy of the image that is transformed with the given transformation matrix and transformation mode: Internally, the transformation matrix is adjusted to compensate for unwanted translation, i.e. transformed() returns the smallest image containing all transformed points of the original image. The static trueMatrix() function returns the actual matrix used for transforming the image.

There are also functions for changing attributes of an image in-place:

Function Description
setDotsPerMeterX() Defines the aspect ratio by setting the number of pixels that fit horizontally in a physical meter.
setDotsPerMeterY() Defines the aspect ratio by setting the number of pixels that fit vertically in a physical meter.
fill() Fills the entire image with the given pixel value.
invertPixels() Inverts all pixel values in the image using the given InvertMode value.
setColorTable() Sets the color table used to translate color indexes. Only monochrome and 8-bit formats.
setColorCount()

Resizes the color table. Only monochrome and 8-bit formats.

Legal Information

For smooth scaling, the transformed() functions use code based on smooth scaling algorithm by Daniel M. Duley.

Copyright (C) 2004, 2005 Daniel M. Duley

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

See also
QImageReader, QImageWriter, QPixmap, QSvgRenderer, {Image Composition Example}, {Image Viewer Example}, {Scribble Example}, {Pixelator Example}

Definition at line 87 of file qimage.h.

Typedefs

◆ DataPtr

Warning
This function is not part of the public interface.

Definition at line 345 of file qimage.h.

Enumerations

◆ Format

The following image formats are available in Qt.

Values greater than QImage::Format_RGB16 were added in Qt 4.4. See the notes after the table.

  • Format_Invalid The image is invalid.
  • Format_Mono The image is stored using 1-bit per pixel. Bytes are packed with the most significant bit (MSB) first.
  • Format_MonoLSB The image is stored using 1-bit per pixel. Bytes are packed with the less significant bit (LSB) first.
  • Format_Indexed8 The image is stored using 8-bit indexes into a colormap.
  • Format_RGB32 The image is stored using a 32-bit RGB format (0xffRRGGBB).
  • Format_ARGB32 The image is stored using a 32-bit ARGB format (0xAARRGGBB).
  • 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.
  • Format_RGB16 The image is stored using a 16-bit RGB format (5-6-5).
  • Format_ARGB8565_Premultiplied The image is stored using a premultiplied 24-bit ARGB format (8-5-6-5).
  • Format_RGB666 The image is stored using a 24-bit RGB format (6-6-6). The unused most significant bits is always zero.
  • Format_ARGB6666_Premultiplied The image is stored using a premultiplied 24-bit ARGB format (6-6-6-6).
  • Format_RGB555 The image is stored using a 16-bit RGB format (5-5-5). The unused most significant bit is always zero.
  • Format_ARGB8555_Premultiplied The image is stored using a premultiplied 24-bit ARGB format (8-5-5-5).
  • Format_RGB888 The image is stored using a 24-bit RGB format (8-8-8).
  • Format_RGB444 The image is stored using a 16-bit RGB format (4-4-4). The unused bits are always zero.
  • Format_ARGB4444_Premultiplied The image is stored using a premultiplied 16-bit ARGB format (4-4-4-4).
Note
Drawing into a QImage with QImage::Format_Indexed8 is not supported.
Do not render into ARGB32 images using QPainter. Using QImage::Format_ARGB32_Premultiplied is significantly faster.
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 

Definition at line 91 of file qimage.h.

91  {
108 #if 0
109  // reserved for future use
110  Format_RGB15,
111  Format_Grayscale16,
112  Format_Grayscale8,
113  Format_Grayscale4,
114  Format_Grayscale4LSB,
115  Format_Grayscale2,
116  Format_Grayscale2LSB
117 #endif
118 #ifndef qdoc
119  NImageFormats
120 #endif
121  };

◆ InvertMode

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

  • InvertRgb Invert only the RGB values and leave the alpha channel unchanged.
  • InvertRgba Invert all channels, including the alpha channel.
See also
invertPixels()
Enumerator
InvertRgb 
InvertRgba 

Definition at line 90 of file qimage.h.

Constructors and Destructors

◆ QImage() [1/11]

QImage::QImage ( )

Constructs a null image.

See also
isNull()

Definition at line 798 of file qimage.cpp.

Referenced by alphaChannel(), convertToFormat(), copy(), createAlphaMask(), createHeuristicMask(), createMaskFromColor(), mirrored(), operator>>(), QImage(), rgbSwapped(), scaled(), scaledToHeight(), scaledToWidth(), setPixel(), and transformed().

799  : QPaintDevice()
800 {
801  d = 0;
802 }
QImageData * d
Definition: qimage.h:336

◆ QImage() [2/11]

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

Constructs an image with the given size and format.

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

830  : QPaintDevice()
831 {
832  d = QImageData::create(size, format, 0);
833 }
QImageData * d
Definition: qimage.h:336
static QImageData * create(const QSize &size, QImage::Format format, int numColors=0)
Definition: qimage.cpp:151

◆ QImage() [3/11]

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

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

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

815  : QPaintDevice()
816 {
818 }
QImageData * d
Definition: qimage.h:336
static QImageData * create(const QSize &size, QImage::Format format, int numColors=0)
Definition: qimage.cpp:151
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ QImage() [4/11]

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

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. The image does not delete the buffer at destruction.

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

897  : QPaintDevice()
898 {
899  d = QImageData::create(data, width, height, 0, format, false);
900 }
QImageData * d
Definition: qimage.h:336
static QImageData * create(const QSize &size, QImage::Format format, int numColors=0)
Definition: qimage.cpp:151
static const char * data(const QByteArray &arr)
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

◆ QImage() [5/11]

QImage::QImage ( const uchar data,
int  width,
int  height,
Format  format 
)

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.

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

926  : QPaintDevice()
927 {
928  d = QImageData::create(const_cast<uchar*>(data), width, height, 0, format, true);
929 }
QImageData * d
Definition: qimage.h:336
static QImageData * create(const QSize &size, QImage::Format format, int numColors=0)
Definition: qimage.cpp:151
static const char * data(const QByteArray &arr)
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

◆ QImage() [6/11]

QImage::QImage ( uchar data,
int  width,
int  height,
int  bytesPerLine,
Format  format 
)

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. The image does not delete the buffer at destruction.

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

945  :QPaintDevice()
946 {
948 }
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
QImageData * d
Definition: qimage.h:336
static QImageData * create(const QSize &size, QImage::Format format, int numColors=0)
Definition: qimage.cpp:151
static const char * data(const QByteArray &arr)
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

◆ QImage() [7/11]

QImage::QImage ( const uchar data,
int  width,
int  height,
int  bytesPerLine,
Format  format 
)

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. The image does not delete the buffer at destruction.

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.

973  :QPaintDevice()
974 {
975  d = QImageData::create(const_cast<uchar*>(data), width, height, bytesPerLine, format, true);
976 }
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
QImageData * d
Definition: qimage.h:336
static QImageData * create(const QSize &size, QImage::Format format, int numColors=0)
Definition: qimage.cpp:151
static const char * data(const QByteArray &arr)
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

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

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

1058  : QPaintDevice()
1059 {
1060  d = 0;
1061  if (!xpm)
1062  return;
1063  if (!qt_read_xpm_image_or_array(0, xpm, *this))
1064  // Issue: Warning because the constructor may be ambigious
1065  qWarning("QImage::QImage(), XPM is not supported");
1066 }
QImageData * d
Definition: qimage.h:336
Q_CORE_EXPORT void qWarning(const char *,...)
bool qt_read_xpm_image_or_array(QIODevice *device, const char *const *source, QImage &image)

◆ QImage() [9/11]

QImage::QImage ( const QString fileName,
const char *  format = 0 
)
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), the loader probes the file for a header to guess the file format.

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 Resource System overview for details on how to embed images and other resource files in the application's executable.

See also
isNull(), Reading and Writing Image Files

Definition at line 996 of file qimage.cpp.

997  : QPaintDevice()
998 {
999  d = 0;
1000  load(fileName, format);
1001 }
QImageData * d
Definition: qimage.h:336
bool load(QIODevice *device, const char *format)
This function reads a QImage from the given device.
Definition: qimage.cpp:5251

◆ QImage() [10/11]

QImage::QImage ( const char *  fileName,
const char *  format = 0 
)
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), the loader probes the file for a header to guess the file format.

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 Resource System overview for details on how to embed images and other resource files in the application's executable.

You can disable this constructor by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful, for example, if you want to ensure that all user-visible strings go through QObject::tr().

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

Definition at line 1027 of file qimage.cpp.

1028  : QPaintDevice()
1029 {
1030  // ### Qt 5: if you remove the QImage(const QByteArray &) QT3_SUPPORT
1031  // constructor, remove this constructor as well. The constructor here
1032  // exists so that QImage("foo.png") compiles without ambiguity.
1033  d = 0;
1035 }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QImageData * d
Definition: qimage.h:336
bool load(QIODevice *device, const char *format)
This function reads a QImage from the given device.
Definition: qimage.cpp:5251
static QString fileName(const QString &fileUrl)

◆ QImage() [11/11]

QImage::QImage ( const QImage image)

Constructs a shallow copy of the given image.

For more information about shallow copies, see the Implicit Data Sharing documentation.

See also
copy()

Definition at line 1097 of file qimage.cpp.

1098  : QPaintDevice()
1099 {
1100  if (image.paintingActive()) {
1101  d = 0;
1102  operator=(image.copy());
1103  } else {
1104  d = image.d;
1105  if (d)
1106  d->ref.ref();
1107  }
1108 }
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
bool ref()
Atomically increments the value of this QAtomicInt.
QImageData * d
Definition: qimage.h:336
bool paintingActive() const
Definition: qpaintdevice.h:170
QImage & operator=(const QImage &)
Assigns a shallow copy of the given image to this image and returns a reference to this image...
Definition: qimage.cpp:1304
QAtomicInt ref
Definition: qimage_p.h:74

◆ ~QImage()

QImage::~QImage ( )

Destroys the image and cleans up.

Definition at line 1289 of file qimage.cpp.

1290 {
1291  if (d && !d->ref.deref())
1292  delete d;
1293 }
QImageData * d
Definition: qimage.h:336
bool deref()
Atomically decrements the value of this QAtomicInt.
QAtomicInt ref
Definition: qimage_p.h:74

Functions

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

Referenced by QPSPrintEnginePrivate::drawImage(), and isGrayscale().

4436 {
4437  if (!d)
4438  return true;
4439 
4440  if (d->depth == 32) {
4441  int p = width()*height();
4442  const QRgb* b = (const QRgb*)bits();
4443  while (p--)
4444  if (!qIsGray(*b++))
4445  return false;
4446  } else if (d->depth == 16) {
4447  int p = width()*height();
4448  const ushort* b = (const ushort *)bits();
4449  while (p--)
4450  if (!qIsGray(qt_colorConvert<quint32, quint16>(*b++, 0)))
4451  return false;
4452  } else if (d->format == QImage::Format_RGB888) {
4453  int p = width()*height();
4454  const qrgb888* b = (const qrgb888 *)bits();
4455  while (p--)
4456  if (!qIsGray(qt_colorConvert<quint32, qrgb888>(*b++, 0)))
4457  return false;
4458  } else {
4459  if (d->colortable.isEmpty())
4460  return true;
4461  for (int i = 0; i < colorCount(); i++)
4462  if (!qIsGray(d->colortable.at(i)))
4463  return false;
4464  }
4465  return true;
4466 }
unsigned int QRgb
Definition: qrgb.h:53
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656
unsigned short ushort
Definition: qglobal.h:995
QImage::Format format
Definition: qimage_p.h:85
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
int depth
Definition: qimage_p.h:78
Q_GUI_EXPORT_INLINE bool qIsGray(QRgb rgb)
Definition: qrgb.h:81

◆ alphaChannel()

QImage QImage::alphaChannel ( ) const

Returns the alpha channel of the image as a new grayscale QImage in which each pixel's red, green, and blue values are given the alpha value of the original image.

The color depth of the returned image is 8-bit.

You can see an example of use of this function in QPixmap's QPixmap::alphaChannel(), which works in the same way as this function on QPixmaps.

Most usecases for this function can be replaced with QPainter and using composition modes.

Warning
This is an expensive function.
See also
setAlphaChannel(), hasAlphaChannel(), {QPixmap::Pixmap Information}{Pixmap}, {QImage::Image Transformations}{Image Transformations}

Definition at line 6430 of file qimage.cpp.

Referenced by QX11PixmapData::alphaChannel(), QPixmapColorizeFilter::draw(), QImageTextureGlyphCache::fillTexture(), and QGLPixmapDropShadowFilter::processGL().

6431 {
6432  if (!d)
6433  return QImage();
6434 
6435  int w = d->width;
6436  int h = d->height;
6437 
6438  QImage image(w, h, Format_Indexed8);
6440  image.setColorCount(256);
6441 
6442  // set up gray scale table.
6443  for (int i=0; i<256; ++i)
6444  image.setColor(i, qRgb(i, i, i));
6445 
6446  if (!hasAlphaChannel()) {
6447  image.fill(255);
6448  return image;
6449  }
6450 
6451  if (d->format == Format_Indexed8) {
6452  const uchar *src_data = d->data;
6453  uchar *dest_data = image.d->data;
6454  for (int y=0; y<h; ++y) {
6455  const uchar *src = src_data;
6456  uchar *dest = dest_data;
6457  for (int x=0; x<w; ++x) {
6458  *dest = qAlpha(d->colortable.at(*src));
6459  ++dest;
6460  ++src;
6461  }
6462  src_data += d->bytes_per_line;
6463  dest_data += image.d->bytes_per_line;
6464  }
6465  } else {
6466  QImage alpha32 = *this;
6468  alpha32 = convertToFormat(Format_ARGB32);
6469  QIMAGE_SANITYCHECK_MEMORY(alpha32);
6470 
6471  const uchar *src_data = alpha32.d->data;
6472  uchar *dest_data = image.d->data;
6473  for (int y=0; y<h; ++y) {
6474  const QRgb *src = (const QRgb *) src_data;
6475  uchar *dest = dest_data;
6476  for (int x=0; x<w; ++x) {
6477  *dest = qAlpha(*src);
6478  ++dest;
6479  ++src;
6480  }
6481  src_data += alpha32.d->bytes_per_line;
6482  dest_data += image.d->bytes_per_line;
6483  }
6484  }
6485 
6486  return image;
6487 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
QImage()
Constructs a null image.
Definition: qimage.cpp:798
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int bytes_per_line
Definition: qimage_p.h:86
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
QImage::Format format
Definition: qimage_p.h:85
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
Definition: qrgb.h:69
uchar * data
Definition: qimage_p.h:81
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105

◆ bitPlaneCount()

int QImage::bitPlaneCount ( ) const

Returns the number of bit planes in the image.

Since
4.7

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

6524 {
6525  if (!d)
6526  return 0;
6527  int bpc = 0;
6528  switch (d->format) {
6530  break;
6531  case QImage::Format_RGB32:
6532  bpc = 24;
6533  break;
6534  case QImage::Format_RGB666:
6535  bpc = 18;
6536  break;
6537  case QImage::Format_RGB555:
6538  bpc = 15;
6539  break;
6541  bpc = 23;
6542  break;
6543  case QImage::Format_RGB444:
6544  bpc = 12;
6545  break;
6546  default:
6547  bpc = qt_depthForFormat(d->format);
6548  break;
6549  }
6550  return bpc;
6551 }
QImageData * d
Definition: qimage.h:336
QImage::Format format
Definition: qimage_p.h:85
int qt_depthForFormat(QImage::Format format)
Definition: qimage_p.h:116

◆ bits() [1/2]

uchar * QImage::bits ( )

Returns a pointer to the first pixel data.

This is equivalent to scanLine(0).

Note that QImage uses 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(), byteCount(), constBits()

Definition at line 1946 of file qimage.cpp.

Referenced by QFontEngine::addBitmapFontToPath(), QFontEngineXLFD::addOutlineToPath(), allGray(), QAlphaWidget::alphaBlend(), QProxyFontEngine::alphaMapForGlyph(), QFontEngineFT::alphaRGBMapForGlyph(), QVNCScreen::base(), QGLPixmapData::bind(), QVolatileImage::bits(), QAhiScreen::blit(), QProxyFontEngine::canRender(), checkForAlphaPixels(), copy(), QVolatileImage::copyFrom(), QX11PixmapData::createBitmapFromImage(), QXlibCursor::createCursorBitmap(), QDirectFBScreen::createDFBSurface(), createMaskFromColor(), QGIFFormat::decode(), QWSDisplay::defineCursor(), QGIFFormat::disposePrevious(), QRasterPaintEngine::drawCachedGlyphs(), QRasterPaintEngine::drawImage(), QRasterPaintEnginePrivate::drawImage(), QRasterPaintEngine::drawTextItem(), QGLPixmapData::ensureCreated(), expblur(), QGLTextureGlyphCache::fillTexture(), QBlittablePixmapData::fromImage(), QX11PixmapData::fromImage(), QGtkPainter::getIcon(), grayscale(), QFontEngineMac::imageForGlyph(), QMeeGoPixmapData::imageToEGLSharedImage(), QBBBuffer::invalidateInCache(), QFontEngineQPF::loadGlyph(), operator==(), QRasterBuffer::prepare(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), QTestLiteStaticInfoPrivate::qimageFromXImage(), QMacCGContext::QMacCGContext(), qt_mac_cg_context(), qt_mac_create_iconref(), qt_mac_image_to_cgimage(), qt_read_dibv5(), qt_x11_drawImage(), QVNCDirtyMap::QVNCDirtyMap(), QPixmap::qwsBits(), QTiffHandler::read(), read_dib_body(), QPngHandlerPrivate::readPngImage(), rotate_right_mirror_horizontal(), rotate_right_mirror_vertical(), rotated270(), rotated90(), QAhiScreenCursor::set(), QMacStyle::styleHint(), QWaylandReadbackGlxContext::swapBuffers(), QWaylandReadbackEglContext::swapBuffers(), swapPixel01(), QNativeImage::systemFormat(), QX11PixmapData::takeQImageFromXImage(), transformed(), QRfbRawEncoder::write(), and QRfbHextileEncoder< SRC >::write().

1947 {
1948  if (!d)
1949  return 0;
1950  detach();
1951 
1952  // In case detach ran out of memory...
1953  if (!d)
1954  return 0;
1955 
1956  return d->data;
1957 }
QImageData * d
Definition: qimage.h:336
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
uchar * data
Definition: qimage_p.h:81

◆ bits() [2/2]

const uchar * QImage::bits ( ) const

Note that QImage uses 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.

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

1970 {
1971  return d ? d->data : 0;
1972 }
QImageData * d
Definition: qimage.h:336
uchar * data
Definition: qimage_p.h:81

◆ byteCount()

int QImage::byteCount ( ) const

◆ bytesPerLine()

int QImage::bytesPerLine ( ) const

Returns the number of bytes per image scanline.

This is equivalent to byteCount() / height().

See also
scanLine()

Definition at line 1812 of file qimage.cpp.

Referenced by QFontEngine::addBitmapFontToPath(), QFontEngineXLFD::addOutlineToPath(), QAlphaWidget::alphaBlend(), QProxyFontEngine::alphaMapForGlyph(), QAhiScreen::blit(), blit180(), blit270(), blit90(), blit_template(), QWindowSurface::buffer(), QVolatileImage::bytesPerLine(), QProxyFontEngine::canRender(), checkForAlphaPixels(), convolute(), copy(), QVolatileImage::copyFrom(), QX11PixmapData::createBitmapFromImage(), QXlibCursor::createCursorBitmap(), QDirectFBScreen::createDFBSurface(), createMaskFromColor(), QGIFFormat::decode(), QWSDisplay::defineCursor(), QRasterPaintEngine::drawCachedGlyphs(), QVGCompositionHelper::drawCursorPixmap(), QPSPrintEnginePrivate::drawImage(), QVGPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QRasterPaintEnginePrivate::drawImage(), drawImageTiled(), QRasterPaintEngine::drawTextItem(), expblur(), QGLTextureGlyphCache::fillTexture(), QXlibWindowSurface::flush(), QRasterWindowSurface::flush(), QVGFontEngineCleaner::fontEngineDestroyed(), QBlittablePixmapData::fromImage(), QMacPixmapData::fromImage(), QWindowSurface::grabWidget(), QVNCIntegration::grabWindow(), QFontEngineMac::imageForGlyph(), QMeeGoPixmapData::imageToEGLSharedImage(), QBBBuffer::invalidateInCache(), QVNCScreen::linestep(), QFontEngineQPF::loadGlyph(), QPixmapData::mask(), QRasterBuffer::prepare(), QRasterWindowSurface::prepareBuffer(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), QImageScale::qimageCalcScaleInfo(), QMacCGContext::QMacCGContext(), qSmoothScaleImage(), qt_halfScaled(), qt_mac_cg_context(), qt_mac_create_iconref(), qt_mac_createCGImageFromQImage(), qt_mac_image_to_cgimage(), qt_mac_read_fontsmoothing_settings(), qt_read_dibv5(), qt_scrollRectInImage(), qt_write_dib(), qt_x11_drawImage(), QVNCDirtyMap::QVNCDirtyMap(), QPixmap::qwsBytesPerLine(), ICOReader::read16_24_32BMP(), ICOReader::read1BitBMP(), ICOReader::read8BitBMP(), read_dib_body(), QPngHandlerPrivate::readPngImage(), rotated270(), rotated90(), QAhiScreenCursor::set(), QRasterPixmapData::setMask(), QPixmapData::setMask(), QMacStyle::styleHint(), QNativeImage::systemFormat(), QRasterPixmapData::toImage(), QX11PixmapData::toImage(), toVGImage(), toVGImageSubRect(), QPixmap::toWinHICON(), transformed(), QBmpHandler::write(), QRfbRawEncoder::write(), QRfbHextileEncoder< SRC >::write(), and write_pbm_image().

1813 {
1814  return (d && d->height) ? d->nbytes / d->height : 0;
1815 }
QImageData * d
Definition: qimage.h:336
int height
Definition: qimage_p.h:77
int nbytes
Definition: qimage_p.h:79

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

Referenced by detach(), QPdfEngine::drawImage(), QTextHtmlExporter::emitBackgroundAttribute(), QDirectFBScreen::exposeRegion(), QDirectFBPaintEnginePrivate::getSurface(), operator<<(), and qt_image_id().

6283 {
6284  if (!d)
6285  return 0;
6286  else
6287  return (((qint64) d->ser_no) << 32) | ((qint64) d->detach_no);
6288 }
QImageData * d
Definition: qimage.h:336
int detach_no
Definition: qimage_p.h:88
int ser_no
Definition: qimage_p.h:87
__int64 qint64
Definition: qglobal.h:942

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

Referenced by compressHelper(), create32BitCursor(), QX11PixmapData::createBitmapFromImage(), QRasterPixmapData::fill(), QVGPixmapData::fill(), QMacPixmapData::fromImage(), QBitmap::fromImage(), QX11PixmapData::fromImage(), get_index(), QDirectFBScreen::getSurfaceDescription(), makeBitmapCompliantIfNeeded(), read_dib_body(), QGtkStyle::standardPixmap(), swapPixel01(), write_pbm_image(), write_xbm_image(), and QPNGImageWriter::writeImage().

1830 {
1831  Q_ASSERT(i < colorCount());
1832  return d ? d->colortable.at(i) : QRgb(uint(-1));
1833 }
unsigned int QRgb
Definition: qrgb.h:53
QImageData * d
Definition: qimage.h:336
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
unsigned int uint
Definition: qglobal.h:996
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656

◆ colorCount()

int QImage::colorCount ( ) const

Returns the size of the color table for the image.

Since
4.6

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

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

Definition at line 1656 of file qimage.cpp.

Referenced by allGray(), color(), QPixmap::colorCount(), create32BitCursor(), QDirectFBScreen::createDFBSurface(), QMacPixmapData::fromImage(), QX11PixmapData::fromImage(), get_index(), QDirectFBScreen::getSurfaceDescription(), isGrayscale(), QDirectFBPaintDevice::metric(), QImage(), qt_write_dib(), QPngHandlerPrivate::readPngImage(), rotated270(), rotated90(), setColorCount(), swapPixel01(), QBmpHandler::write(), write_jpeg_image(), write_pbm_image(), and QPNGImageWriter::writeImage().

1657 {
1658  return d ? d->colortable.size() : 0;
1659 }
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ colorTable()

QVector< QRgb > QImage::colorTable ( ) const

◆ constBits()

const uchar * QImage::constBits ( ) const

Returns a pointer to the first pixel data.

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

See also
bits(), constScanLine()
Since
4.7

Definition at line 1985 of file qimage.cpp.

Referenced by QVolatileImage::constBits(), QVGCompositionHelper::drawCursorPixmap(), QVGPaintEngine::drawImage(), drawImageTiled(), QGLTextureGlyphCache::fillTexture(), QVGFontEngineCleaner::fontEngineDestroyed(), toVGImage(), toVGImageSubRect(), and QWaylandShmBuffer::~QWaylandShmBuffer().

1986 {
1987  return d ? d->data : 0;
1988 }
QImageData * d
Definition: qimage.h:336
uchar * data
Definition: qimage_p.h:81

◆ 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 aligned on a 32-bit boundary.

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

See also
scanLine(), constBits()
Since
4.7

Definition at line 1926 of file qimage.cpp.

Referenced by colorizeBitmap(), rgbSwapped(), write_jpeg_image(), and QPNGImageWriter::writeImage().

1927 {
1928  if (!d)
1929  return 0;
1930 
1931  Q_ASSERT(i >= 0 && i < height());
1932  return d->data + i * d->bytes_per_line;
1933 }
QImageData * d
Definition: qimage.h:336
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int bytes_per_line
Definition: qimage_p.h:86
uchar * data
Definition: qimage_p.h:81
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

◆ convertToFormat() [1/2]

QImage QImage::convertToFormat ( Format  format,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
) const

Returns a copy of the image in the given format.

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

See also
{QImage::Image Format}{Image Format}

Definition at line 3966 of file qimage.cpp.

Referenced by QPdfEnginePrivate::addImage(), QFontEngineXLFD::addOutlineToPath(), alphaChannel(), QFontEngineXLFD::alphaMapForGlyph(), QFontEngine::alphaMapForGlyph(), QFontEngineDirectWrite::alphaRGBMapForGlyph(), QFontEngineWin::alphaRGBMapForGlyph(), QAhiScreen::blit(), QRasterBuffer::colorizeBitmap(), colorizeBitmap(), QWindowsMimeImage::convertFromMime(), convertToFormat(), convolute(), create32BitCursor(), createAlphaMask(), QX11PixmapData::createBitmapFromImage(), QXlibCursor::createCursorBitmap(), QDirectFBScreen::createDFBSurface(), createHeuristicMask(), createImageNode(), QPixmap::createMaskFromColor(), QRasterPixmapData::createPixmapForImage(), QVGPixmapData::createPixmapForImage(), QGLPixmapData::createPixmapForImage(), darkenPixmap(), QWSDisplay::defineCursor(), QPixmapColorizeFilter::draw(), QVGCompositionHelper::drawCursorPixmap(), QPSPrintEnginePrivate::drawImage(), QPSPrintEngine::drawImageInternal(), QGLPixmapData::ensureCreated(), QVolatileImageData::ensureFormat(), QGLTextureGlyphCache::fillTexture(), QImageTextureGlyphCache::fillTexture(), QVGFontEngineCleaner::fontEngineDestroyed(), QBlittablePixmapData::fromImage(), QDirectFBPixmapData::fromImage(), QMacPixmapData::fromImage(), QBitmap::fromImage(), QX11PixmapData::fromImage(), QWindowsMobileStyle::generatedIconPixmap(), QCommonStyle::generatedIconPixmap(), QMacStyle::generatedIconPixmap(), QFontEngineQPF::loadGlyph(), makeBitmapCompliantIfNeeded(), QPixmapData::mask(), operator>>(), QCursor::QCursor(), qstring_to_xtp(), qt_blurImage(), qt_createIconMask(), qt_halfScaled(), qt_mac_createCGImageFromQImage(), qt_write_dib(), qt_write_dibv5(), QItemDelegate::selected(), QVNCCursor::sendClientCursor(), QAhiScreenCursor::set(), QScreenCursor::set(), QDirectFBScreenCursor::set(), setAlphaChannel(), QRasterPixmapData::setMask(), QPixmapData::setMask(), QCursor::setPos(), smoothScaled(), QCommonStyle::standardPixmap(), toVGImage(), toVGImageSubRect(), QPixmap::toWinHBITMAP(), QTiffHandler::write(), QBmpHandler::write(), QVNCClientCursor::write(), ICOReader::write(), write_jpeg_image(), write_pbm_image(), write_xbm_image(), write_xpm_image(), QMngHandlerPrivate::writeImage(), QPNGImageWriter::writeImage(), and QX11Data::xdndMimeDataForAtom().

3967 {
3968  if (!d || d->format == format)
3969  return *this;
3970 
3972  return QImage();
3973 
3974  const Image_Converter *converterPtr = &converter_map[d->format][format];
3975  Image_Converter converter = *converterPtr;
3976  if (converter) {
3977  QImage image(d->width, d->height, format);
3978 
3980 
3981  image.setDotsPerMeterY(dotsPerMeterY());
3982  image.setDotsPerMeterX(dotsPerMeterX());
3983 
3984 #if !defined(QT_NO_IMAGE_TEXT)
3985  image.d->text = d->text;
3986 #endif // !QT_NO_IMAGE_TEXT
3987 
3988  converter(image.d, d, flags);
3989  return image;
3990  }
3991 
3994 
3995  QImage image = convertToFormat(Format_ARGB32, flags);
3996  return image.convertToFormat(format, flags);
3997 }
int width
Definition: qimage_p.h:76
int dotsPerMeterY() const
Returns the number of pixels that fit vertically in a physical meter.
Definition: qimage.cpp:5628
QImageData * d
Definition: qimage.h:336
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
QImage()
Constructs a null image.
Definition: qimage.cpp:798
int height
Definition: qimage_p.h:77
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
QImage::Format format
Definition: qimage_p.h:85
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105
void(* Image_Converter)(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
Definition: qimage.cpp:2432
int dotsPerMeterX() const
Returns the number of pixels that fit horizontally in a physical meter.
Definition: qimage.cpp:5615
QMap< QString, QString > text
Definition: qimage_p.h:106
static Image_Converter converter_map[QImage::NImageFormats][QImage::NImageFormats]
Definition: qimage.cpp:3513

◆ convertToFormat() [2/2]

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

Returns a copy of the image converted to the given format, using the specified colorTable.

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

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

Definition at line 4095 of file qimage.cpp.

4096 {
4097  if (d->format == format)
4098  return *this;
4099 
4100  if (format <= QImage::Format_Indexed8 && depth() == 32) {
4101  return convertWithPalette(*this, format, colorTable);
4102  }
4103 
4104  const Image_Converter *converterPtr = &converter_map[d->format][format];
4105  Image_Converter converter = *converterPtr;
4106  if (!converter)
4107  return QImage();
4108 
4109  QImage image(d->width, d->height, format);
4111 
4112 #if !defined(QT_NO_IMAGE_TEXT)
4113  image.d->text = d->text;
4114 #endif // !QT_NO_IMAGE_TEXT
4115 
4116  converter(image.d, d, flags);
4117  return image;
4118 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
QImage()
Constructs a null image.
Definition: qimage.cpp:798
int height
Definition: qimage_p.h:77
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
QImage::Format format
Definition: qimage_p.h:85
static QImage convertWithPalette(const QImage &src, QImage::Format format, const QVector< QRgb > &clut)
Definition: qimage.cpp:4028
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105
void(* Image_Converter)(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
Definition: qimage.cpp:2432
QMap< QString, QString > text
Definition: qimage_p.h:106
static Image_Converter converter_map[QImage::NImageFormats][QImage::NImageFormats]
Definition: qimage.cpp:3513

◆ copy() [1/2]

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

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

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

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

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

See also
QImage()

Definition at line 1410 of file qimage.cpp.

Referenced by QGLWindowSurface::buffer(), QMeeGoRasterPixmapData::copy(), QRasterPixmapData::copy(), QX11PixmapData::copy(), create32BitCursor(), QWSCursor::createDropShadow(), detach(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QPSPrintEngine::drawImage(), QPdfEngine::drawImage(), QPaintEngine::drawImage(), QXlibScreen::grabWindow(), operator=(), QImage(), QTestLiteStaticInfoPrivate::qimageFromXImage(), qpaintbuffer_storable_image(), qt_x11_drawImage(), QVNCDirtyMap::QVNCDirtyMap(), QImageReader::read(), rgbSwapped(), QAlphaWidget::run(), QBlittablePixmapData::toImage(), QDirectFBPixmapData::toImage(), QRasterPixmapData::toImage(), QVolatileImage::toImage(), QPixmapData::toImage(), QX11PixmapData::toImage(), QGLPixmapData::toImage(), QTiffHandler::write(), QRfbRawEncoder::write(), QRfbHextileEncoder< SRC >::write(), write_jpeg_image(), and QPNGImageWriter::writeImage().

1411 {
1412  if (!d)
1413  return QImage();
1414 
1415  if (r.isNull()) {
1416  QImage image(d->width, d->height, d->format);
1417  if (image.isNull())
1418  return image;
1419 
1420  // Qt for Embedded Linux can create images with non-default bpl
1421  // make sure we don't crash.
1422  if (image.d->nbytes != d->nbytes) {
1423  int bpl = qMin(bytesPerLine(), image.bytesPerLine());
1424  for (int i = 0; i < height(); i++)
1425  memcpy(image.scanLine(i), scanLine(i), bpl);
1426  } else
1427  memcpy(image.bits(), bits(), d->nbytes);
1428  image.d->colortable = d->colortable;
1429  image.d->dpmx = d->dpmx;
1430  image.d->dpmy = d->dpmy;
1431  image.d->offset = d->offset;
1432  image.d->has_alpha_clut = d->has_alpha_clut;
1433 #ifndef QT_NO_IMAGE_TEXT
1434  image.d->text = d->text;
1435 #endif
1436  return image;
1437  }
1438 
1439  int x = r.x();
1440  int y = r.y();
1441  int w = r.width();
1442  int h = r.height();
1443 
1444  int dx = 0;
1445  int dy = 0;
1446  if (w <= 0 || h <= 0)
1447  return QImage();
1448 
1449  QImage image(w, h, d->format);
1450  if (image.isNull())
1451  return image;
1452 
1453  if (x < 0 || y < 0 || x + w > d->width || y + h > d->height) {
1454  // bitBlt will not cover entire image - clear it.
1455  image.fill(0);
1456  if (x < 0) {
1457  dx = -x;
1458  x = 0;
1459  }
1460  if (y < 0) {
1461  dy = -y;
1462  y = 0;
1463  }
1464  }
1465 
1466  image.d->colortable = d->colortable;
1467 
1468  int pixels_to_copy = qMax(w - dx, 0);
1469  if (x > d->width)
1470  pixels_to_copy = 0;
1471  else if (pixels_to_copy > d->width - x)
1472  pixels_to_copy = d->width - x;
1473  int lines_to_copy = qMax(h - dy, 0);
1474  if (y > d->height)
1475  lines_to_copy = 0;
1476  else if (lines_to_copy > d->height - y)
1477  lines_to_copy = d->height - y;
1478 
1479  bool byteAligned = true;
1480  if (d->format == Format_Mono || d->format == Format_MonoLSB)
1481  byteAligned = !(dx & 7) && !(x & 7) && !(pixels_to_copy & 7);
1482 
1483  if (byteAligned) {
1484  const uchar *src = d->data + ((x * d->depth) >> 3) + y * d->bytes_per_line;
1485  uchar *dest = image.d->data + ((dx * d->depth) >> 3) + dy * image.d->bytes_per_line;
1486  const int bytes_to_copy = (pixels_to_copy * d->depth) >> 3;
1487  for (int i = 0; i < lines_to_copy; ++i) {
1488  memcpy(dest, src, bytes_to_copy);
1489  src += d->bytes_per_line;
1490  dest += image.d->bytes_per_line;
1491  }
1492  } else if (d->format == Format_Mono) {
1493  const uchar *src = d->data + y * d->bytes_per_line;
1494  uchar *dest = image.d->data + dy * image.d->bytes_per_line;
1495  for (int i = 0; i < lines_to_copy; ++i) {
1496  for (int j = 0; j < pixels_to_copy; ++j) {
1497  if (src[(x + j) >> 3] & (0x80 >> ((x + j) & 7)))
1498  dest[(dx + j) >> 3] |= (0x80 >> ((dx + j) & 7));
1499  else
1500  dest[(dx + j) >> 3] &= ~(0x80 >> ((dx + j) & 7));
1501  }
1502  src += d->bytes_per_line;
1503  dest += image.d->bytes_per_line;
1504  }
1505  } else { // Format_MonoLSB
1507  const uchar *src = d->data + y * d->bytes_per_line;
1508  uchar *dest = image.d->data + dy * image.d->bytes_per_line;
1509  for (int i = 0; i < lines_to_copy; ++i) {
1510  for (int j = 0; j < pixels_to_copy; ++j) {
1511  if (src[(x + j) >> 3] & (0x1 << ((x + j) & 7)))
1512  dest[(dx + j) >> 3] |= (0x1 << ((dx + j) & 7));
1513  else
1514  dest[(dx + j) >> 3] &= ~(0x1 << ((dx + j) & 7));
1515  }
1516  src += d->bytes_per_line;
1517  dest += image.d->bytes_per_line;
1518  }
1519  }
1520 
1521  image.d->dpmx = dotsPerMeterX();
1522  image.d->dpmy = dotsPerMeterY();
1523  image.d->offset = offset();
1524  image.d->has_alpha_clut = d->has_alpha_clut;
1525 #ifndef QT_NO_IMAGE_TEXT
1526  image.d->text = d->text;
1527 #endif
1528  return image;
1529 }
int width
Definition: qimage_p.h:76
qreal dpmy
Definition: qimage_p.h:91
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
uint has_alpha_clut
Definition: qimage_p.h:96
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
int dotsPerMeterY() const
Returns the number of pixels that fit vertically in a physical meter.
Definition: qimage.cpp:5628
QVectorData * d
Definition: qvector.h:109
QImageData * d
Definition: qimage.h:336
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
QPoint offset() const
Returns the number of pixels by which the image is intended to be offset by when positioning relative...
Definition: qimage.cpp:5688
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QImage()
Constructs a null image.
Definition: qimage.cpp:798
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
qreal dpmx
Definition: qimage_p.h:90
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int nbytes
Definition: qimage_p.h:79
int bytes_per_line
Definition: qimage_p.h:86
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
QImage::Format format
Definition: qimage_p.h:85
QPoint offset
Definition: qimage_p.h:92
uchar * data
Definition: qimage_p.h:81
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int depth
Definition: qimage_p.h:78
int dotsPerMeterX() const
Returns the number of pixels that fit horizontally in a physical meter.
Definition: qimage.cpp:5615
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
QMap< QString, QString > text
Definition: qimage_p.h:106

◆ copy() [2/2]

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

The returned image is copied from the position (x, y) in this image, and will always have the given width and height.

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

In areas beyond this image, pixels are set to 0.

Definition at line 160 of file qimage.h.

161  { return copy(QRect(x, y, w, h)); }
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ createAlphaMask()

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

Builds and returns a 1-bpp mask from the alpha buffer in this image.

Returns a null image if the image's format is QImage::Format_RGB32.

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

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

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

Definition at line 4720 of file qimage.cpp.

Referenced by createAlphaMask(), QPSPrintEngine::drawImageInternal(), QX11PixmapData::fromImage(), QFileSystemModel::headerData(), QCursor::QCursor(), QVNCCursor::sendClientCursor(), QVNCClientCursor::write(), and ICOReader::write().

4721 {
4722  if (!d || d->format == QImage::Format_RGB32)
4723  return QImage();
4724 
4725  if (d->depth == 1) {
4726  // A monochrome pixmap, with alpha channels on those two colors.
4727  // Pretty unlikely, so use less efficient solution.
4728  return convertToFormat(Format_Indexed8, flags).createAlphaMask(flags);
4729  }
4730 
4731  QImage mask(d->width, d->height, Format_MonoLSB);
4732  if (!mask.isNull())
4733  dither_to_Mono(mask.d, d, flags, true);
4734  return mask;
4735 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336
QImage()
Constructs a null image.
Definition: qimage.cpp:798
static void dither_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags, bool fromalpha)
Definition: qimage.cpp:2774
int height
Definition: qimage_p.h:77
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage createAlphaMask(Qt::ImageConversionFlags flags=Qt::AutoColor) const
Builds and returns a 1-bpp mask from the alpha buffer in this image.
Definition: qimage.cpp:4720
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
QImage::Format format
Definition: qimage_p.h:85
int depth
Definition: qimage_p.h:78

◆ createHeuristicMask()

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

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

The function works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges. The four corners vote for which color is to be masked away. In case of a draw (this generally means that this function is not applicable to the image), the result is arbitrary.

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

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

Note that this function disregards the alpha buffer.

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

Definition at line 4762 of file qimage.cpp.

Referenced by createHeuristicMask().

4763 {
4764  if (!d)
4765  return QImage();
4766 
4767  if (d->depth != 32) {
4769  return img32.createHeuristicMask(clipTight);
4770  }
4771 
4772 #define PIX(x,y) (*((QRgb*)scanLine(y)+x) & 0x00ffffff)
4773 
4774  int w = width();
4775  int h = height();
4776  QImage m(w, h, Format_MonoLSB);
4778  m.setColorCount(2);
4779  m.setColor(0, QColor(Qt::color0).rgba());
4780  m.setColor(1, QColor(Qt::color1).rgba());
4781  m.fill(0xff);
4782 
4783  QRgb background = PIX(0,0);
4784  if (background != PIX(w-1,0) &&
4785  background != PIX(0,h-1) &&
4786  background != PIX(w-1,h-1)) {
4787  background = PIX(w-1,0);
4788  if (background != PIX(w-1,h-1) &&
4789  background != PIX(0,h-1) &&
4790  PIX(0,h-1) == PIX(w-1,h-1)) {
4791  background = PIX(w-1,h-1);
4792  }
4793  }
4794 
4795  int x,y;
4796  bool done = false;
4797  uchar *ypp, *ypc, *ypn;
4798  while(!done) {
4799  done = true;
4800  ypn = m.scanLine(0);
4801  ypc = 0;
4802  for (y = 0; y < h; y++) {
4803  ypp = ypc;
4804  ypc = ypn;
4805  ypn = (y == h-1) ? 0 : m.scanLine(y+1);
4806  QRgb *p = (QRgb *)scanLine(y);
4807  for (x = 0; x < w; x++) {
4808  // slowness here - it's possible to do six of these tests
4809  // together in one go. oh well.
4810  if ((x == 0 || y == 0 || x == w-1 || y == h-1 ||
4811  !(*(ypc + ((x-1) >> 3)) & (1 << ((x-1) & 7))) ||
4812  !(*(ypc + ((x+1) >> 3)) & (1 << ((x+1) & 7))) ||
4813  !(*(ypp + (x >> 3)) & (1 << (x & 7))) ||
4814  !(*(ypn + (x >> 3)) & (1 << (x & 7)))) &&
4815  ( (*(ypc + (x >> 3)) & (1 << (x & 7)))) &&
4816  ((*p & 0x00ffffff) == background)) {
4817  done = false;
4818  *(ypc + (x >> 3)) &= ~(1 << (x & 7));
4819  }
4820  p++;
4821  }
4822  }
4823  }
4824 
4825  if (!clipTight) {
4826  ypn = m.scanLine(0);
4827  ypc = 0;
4828  for (y = 0; y < h; y++) {
4829  ypp = ypc;
4830  ypc = ypn;
4831  ypn = (y == h-1) ? 0 : m.scanLine(y+1);
4832  QRgb *p = (QRgb *)scanLine(y);
4833  for (x = 0; x < w; x++) {
4834  if ((*p & 0x00ffffff) != background) {
4835  if (x > 0)
4836  *(ypc + ((x-1) >> 3)) |= (1 << ((x-1) & 7));
4837  if (x < w-1)
4838  *(ypc + ((x+1) >> 3)) |= (1 << ((x+1) & 7));
4839  if (y > 0)
4840  *(ypp + (x >> 3)) |= (1 << (x & 7));
4841  if (y < h-1)
4842  *(ypn + (x >> 3)) |= (1 << (x & 7));
4843  }
4844  p++;
4845  }
4846  }
4847  }
4848 
4849 #undef PIX
4850 
4851  return m;
4852 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
unsigned int QRgb
Definition: qrgb.h:53
QImageData * d
Definition: qimage.h:336
QImage()
Constructs a null image.
Definition: qimage.cpp:798
#define PIX(x, y)
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105
QImage createHeuristicMask(bool clipTight=true) const
Creates and returns a 1-bpp heuristic mask for this image.
Definition: qimage.cpp:4762
int depth
Definition: qimage_p.h:78
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ createMaskFromColor()

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

Creates and returns a mask for this image based on the given color value.

If the mode is MaskInColor (the default value), all pixels matching color will be opaque pixels in the mask. If mode is MaskOutColor, all pixels matching the given color will be transparent.

See also
createAlphaMask(), createHeuristicMask()

Definition at line 4865 of file qimage.cpp.

Referenced by QPixmap::createMaskFromColor().

4866 {
4867  if (!d)
4868  return QImage();
4869  QImage maskImage(size(), QImage::Format_MonoLSB);
4870  QIMAGE_SANITYCHECK_MEMORY(maskImage);
4871  maskImage.fill(0);
4872  uchar *s = maskImage.bits();
4873 
4874  if (depth() == 32) {
4875  for (int h = 0; h < d->height; h++) {
4876  const uint *sl = (uint *) scanLine(h);
4877  for (int w = 0; w < d->width; w++) {
4878  if (sl[w] == color)
4879  *(s + (w >> 3)) |= (1 << (w & 7));
4880  }
4881  s += maskImage.bytesPerLine();
4882  }
4883  } else {
4884  for (int h = 0; h < d->height; h++) {
4885  for (int w = 0; w < d->width; w++) {
4886  if ((uint) pixel(w, h) == color)
4887  *(s + (w >> 3)) |= (1 << (w & 7));
4888  }
4889  s += maskImage.bytesPerLine();
4890  }
4891  }
4892  if (mode == Qt::MaskOutColor)
4893  maskImage.invertPixels();
4894  return maskImage;
4895 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336
QRgb pixel(int x, int y) const
Returns the color of the pixel at coordinates (x, y).
Definition: qimage.cpp:4240
QImage()
Constructs a null image.
Definition: qimage.cpp:798
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105
QRgb color(int i) const
Returns the color in the color table at index i.
Definition: qimage.cpp:1829
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ data_ptr()

DataPtr & QImage::data_ptr ( )
inline

◆ depth()

int QImage::depth ( ) const

Returns the depth of the image.

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

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

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

Definition at line 1620 of file qimage.cpp.

Referenced by QFontEngine::addBitmapFontToPath(), QPdfEnginePrivate::addImage(), QAlphaWidget::alphaBlend(), QFontEngine::alphaMapForGlyph(), QFontEngineDirectWrite::alphaRGBMapForGlyph(), QFontEngineWin::alphaRGBMapForGlyph(), QPainter::begin(), QTransformedScreen::blit(), QWindowSurface::buffer(), QVGPaintEngine::canVgWritePixels(), QRasterBuffer::colorizeBitmap(), compressHelper(), convert_indexed8_to_ARGB_PM_inplace(), convert_indexed8_to_RGB16_inplace(), convert_indexed8_to_RGB_inplace(), convert_RGB_to_RGB16_inplace(), convertToFormat(), QImageData::create(), QDirectFBScreen::createDFBSurface(), createMaskFromColor(), QRasterPixmapData::createPixmapForImage(), QGLPixmapData::createPixmapForImage(), QVolatileImage::depth(), QRasterPaintEngine::drawBitmap(), QRasterPaintEngine::drawCachedGlyphs(), QX11PaintEngine::drawImage(), QVGPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QRasterPaintEnginePrivate::drawImage(), QPSPrintEnginePrivate::drawImageHelper(), QPSPrintEngine::drawImageInternal(), drawImageTiled(), QRasterPaintEngine::drawPixmap(), QRasterPaintEngine::drawTextItem(), QRasterPaintEngine::drawTiledPixmap(), expblur(), QRasterPixmapData::fill(), QGLPixmapData::fill(), QImageTextureGlyphCache::fillTexture(), QRasterWindowSurface::flush(), format(), QDirectFBPixmapData::fromImage(), QMacPixmapData::fromImage(), QX11PixmapData::fromImage(), QWindowSurface::grabWidget(), QVNCIntegration::grabWindow(), QDirectFBPixmapData::hasAlphaChannel(), QVGPixmapData::idealFormat(), invertPixels(), is_brush_transparent(), isGrayscale(), QFontEngineQPF::loadGlyph(), QPixmapData::mask(), mirrored(), QRasterBuffer::prepare(), QRasterWindowSurface::prepareBuffer(), QImage(), qt_blurrow(), qt_mac_createCGImageFromQImage(), qt_mac_image_to_cgimage(), qt_scrollRectInImage(), qt_toRasterPixmap(), qt_toX11Pixmap(), qt_write_dib(), qt_x11_drawImage(), QVNCDirtyMap::QVNCDirtyMap(), read_xpm_body(), QPngHandlerPrivate::readPngImage(), QRasterPixmapData::resize(), QVNCCursor::sendClientCursor(), setColor(), QRasterPixmapData::setMask(), QPixmapData::setMask(), smoothScaled(), swapPixel01(), transformed(), QBmpHandler::write(), QVNCClientCursor::write(), QRfbRawEncoder::write(), QRfbHextileEncoder< SRC >::write(), write_pbm_image(), write_xpm_image(), and QPNGImageWriter::writeImage().

1621 {
1622  return d ? d->depth : 0;
1623 }
QImageData * d
Definition: qimage.h:336
int depth
Definition: qimage_p.h:78

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

Warning
This function is not part of the public interface.

Nothing is done if there is just a single reference.

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

Definition at line 1359 of file qimage.cpp.

Referenced by bits(), colorCount(), QRasterPixmapData::createPixmapForImage(), QVGPixmapData::createPixmapForImage(), QGLPixmapData::createPixmapForImage(), QGIFFormat::decode(), QPixmap::detach(), QRasterPixmapData::fill(), fill(), format(), QWindowSurface::grabWidget(), invertPixels(), QVolatileImageData::QVolatileImageData(), scanLine(), setAlphaChannel(), setColor(), setColorCount(), setColorTable(), setDotsPerMeterX(), setDotsPerMeterY(), setOffset(), setText(), and write_pbm_image().

1360 {
1361  if (d) {
1362  if (d->is_cached && d->ref == 1)
1364 
1365  if (d->ref != 1 || d->ro_data)
1366  *this = copy();
1367 
1368  if (d)
1369  ++d->detach_no;
1370  }
1371 }
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
QImageData * d
Definition: qimage.h:336
static void executeImageHooks(qint64 key)
int detach_no
Definition: qimage_p.h:88
uint ro_data
Definition: qimage_p.h:95
QAtomicInt ref
Definition: qimage_p.h:74
qint64 cacheKey() const
Returns a number that identifies the contents of this QImage object.
Definition: qimage.cpp:6282
uint is_cached
Definition: qimage_p.h:97

◆ devType()

int QImage::devType ( ) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 1332 of file qimage.cpp.

1333 {
1334  return QInternal::Image;
1335 }

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

Referenced by convertToFormat(), copy(), qt_write_dib(), setPixel(), transformed(), QTiffHandler::write(), write_jpeg_image(), and QPNGImageWriter::writeImage().

5616 {
5617  return d ? qRound(d->dpmx) : 0;
5618 }
QImageData * d
Definition: qimage.h:336
qreal dpmx
Definition: qimage_p.h:90
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

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

Referenced by convertToFormat(), copy(), qt_write_dib(), setPixel(), transformed(), QTiffHandler::write(), write_jpeg_image(), and QPNGImageWriter::writeImage().

5629 {
5630  return d ? qRound(d->dpmy) : 0;
5631 }
qreal dpmy
Definition: qimage_p.h:91
QImageData * d
Definition: qimage.h:336
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ fill() [1/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.

Note: QImage::pixel() returns the color of the pixel at the given coordinates while QColor::pixel() returns the pixel value of the underlying window system (essentially an index value), so normally you will want to use QImage::pixel() to use a color from an existing image or QColor::rgb() to use a specific color.

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

Definition at line 2032 of file qimage.cpp.

Referenced by alphaChannel(), QFontEngine::alphaMapForGlyph(), QFontEngineBox::alphaMapForGlyph(), alphaMapFromPath(), QGLPixmapData::bind(), copy(), create32BitCursor(), createHeuristicMask(), createMaskFromColor(), QPixmapDropShadowFilter::draw(), QPainterPrivate::draw_helper(), QAlphaPaintEnginePrivate::drawAlphaImage(), QWindowsVistaStyle::drawControl(), drawEllipse_midpoint_i(), QFontEngineWin::drawGDIGlyph(), QWindowsStyle::drawPrimitive(), QBlittablePixmapData::fill(), QRasterPixmapData::fill(), QX11PixmapData::fill(), QVolatileImage::fill(), QGLPixmapData::fill(), fill(), QGLPixmapData::fillImage(), QX11PaintEnginePrivate::fillPolygon_dev(), QFileSystemModel::headerData(), QFontEngineMac::imageForGlyph(), QFontEngineDirectWrite::imageForGlyph(), QGLPixmapData::paintEngine(), QSvgIconEngine::pixmap(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), QMngHandlerPrivate::processHeader(), qt_mac_read_fontsmoothing_settings(), qt_patternForAlpha(), QSvgIOHandler::read(), QWSYellowSurface::setPermanentState(), QMacPixmapData::toImage(), toVGImageWithOpacity(), toVGImageWithOpacitySubRect(), and ICOReader::write().

2033 {
2034  if (!d)
2035  return;
2036 
2037  detach();
2038 
2039  // In case detach() ran out of memory
2040  if (!d)
2041  return;
2042 
2043  if (d->depth == 1 || d->depth == 8) {
2044  int w = d->width;
2045  if (d->depth == 1) {
2046  if (pixel & 1)
2047  pixel = 0xffffffff;
2048  else
2049  pixel = 0;
2050  w = (w + 7) / 8;
2051  } else {
2052  pixel &= 0xff;
2053  }
2054  qt_rectfill<quint8>(d->data, pixel, 0, 0,
2055  w, d->height, d->bytes_per_line);
2056  return;
2057  } else if (d->depth == 16) {
2058  qt_rectfill<quint16>(reinterpret_cast<quint16*>(d->data), pixel,
2059  0, 0, d->width, d->height, d->bytes_per_line);
2060  return;
2061  } else if (d->depth == 24) {
2062  qt_rectfill<quint24>(reinterpret_cast<quint24*>(d->data), pixel,
2063  0, 0, d->width, d->height, d->bytes_per_line);
2064  return;
2065  }
2066 
2067  if (d->format == Format_RGB32)
2068  pixel |= 0xff000000;
2069 
2070  qt_rectfill<uint>(reinterpret_cast<uint*>(d->data), pixel,
2071  0, 0, d->width, d->height, d->bytes_per_line);
2072 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336
QRgb pixel(int x, int y) const
Returns the color of the pixel at coordinates (x, y).
Definition: qimage.cpp:4240
int height
Definition: qimage_p.h:77
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
unsigned short quint16
Definition: qglobal.h:936
unsigned int uint
Definition: qglobal.h:996
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
int depth
Definition: qimage_p.h:78

◆ fill() [2/3]

void QImage::fill ( const QColor color)

Fills the entire image with the given color.

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

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

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

Since
4.8

Definition at line 2114 of file qimage.cpp.

2115 {
2116  if (!d)
2117  return;
2118  detach();
2119 
2120  // In case we run out of memory
2121  if (!d)
2122  return;
2123 
2124  if (d->depth == 32) {
2125  uint pixel = color.rgba();
2127  pixel = PREMUL(pixel);
2128  fill((uint) pixel);
2129 
2130  } else if (d->depth == 16 && d->format == QImage::Format_RGB16) {
2131  qrgb565 p(color.rgba());
2132  fill((uint) p.rawValue());
2133 
2134  } else if (d->depth == 1) {
2135  if (color == Qt::color1)
2136  fill((uint) 1);
2137  else
2138  fill((uint) 0);
2139 
2140  } else if (d->depth == 8) {
2141  uint pixel = 0;
2142  for (int i=0; i<d->colortable.size(); ++i) {
2143  if (color.rgba() == d->colortable.at(i)) {
2144  pixel = i;
2145  break;
2146  }
2147  }
2148  fill(pixel);
2149 
2150  } else {
2151  QPainter p(this);
2152  p.setCompositionMode(QPainter::CompositionMode_Source);
2153  p.fillRect(rect(), color);
2154  }
2155 
2156 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
Definition: qimage.cpp:1603
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
QRgb pixel(int x, int y) const
Returns the color of the pixel at coordinates (x, y).
Definition: qimage.cpp:4240
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
unsigned int uint
Definition: qglobal.h:996
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QImage::Format format
Definition: qimage_p.h:85
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
int depth
Definition: qimage_p.h:78
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ fill() [3/3]

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

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

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

Since
4.8

Definition at line 2087 of file qimage.cpp.

2088 {
2089  fill(QColor(color));
2090 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
QRgb color(int i) const
Returns the color in the color table at index i.
Definition: qimage.cpp:1829

◆ format()

QImage::Format QImage::format ( ) const

Returns the format of the image.

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

Definition at line 2305 of file qimage.cpp.

Referenced by QPdfEnginePrivate::addBrushPattern(), QPdfEnginePrivate::addImage(), QFontEngineWin::alphaMapForGlyph(), QPainter::begin(), QRasterWindowSurface::beginPaint(), QAhiScreen::blit(), QTransformedScreen::blit(), blit_template(), QWindowSurface::buffer(), QProxyFontEngine::canRender(), QVGPaintEngine::canVgWritePixels(), checkForAlphaPixels(), compressHelper(), QWindowsMimeImage::convertFromMime(), QImageData::convertInPlace(), convertToFormat(), convertWithPalette(), convolute(), QImageData::create(), QDirectFBScreen::createDFBSurface(), createImageNode(), QRasterPixmapData::createPixmapForImage(), QGLPixmapData::createPixmapForImage(), QPixmapColorizeFilter::draw(), QRasterPaintEngine::drawBitmap(), QDirectFBPaintEngine::drawImage(), QPSPrintEnginePrivate::drawImage(), QX11PaintEngine::drawImage(), QVGPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QPSPrintEngine::drawImageInternal(), drawImageTiled(), QVolatileImageData::ensureFormat(), ensureValidImage(), expblur(), QDirectFBScreen::exposeRegion(), QRasterPixmapData::fill(), QGLTextureGlyphCache::fillTexture(), QRasterWindowSurface::flush(), QVGFontEngineCleaner::fontEngineDestroyed(), QVolatileImage::format(), QBlittablePixmapData::fromImage(), QDirectFBPixmapData::fromImage(), QMacPixmapData::fromImage(), QX11PixmapData::fromImage(), QDirectFBPaintEnginePrivate::getSurface(), QWindowSurface::grabWidget(), QVNCIntegration::grabWindow(), QWSMemorySurface::isValid(), QFontEngineQPF::loadGlyph(), mirrored(), QWSLocalMemSurface::permanentState(), QWSSharedMemSurface::permanentState(), QMeeGoGraphicsSystem::pixmapDataFromEGLSharedImage(), QRasterBuffer::prepare(), qSmoothScaleImage(), qt_bitmapToRegion(), qt_blurImage(), qt_blurrow(), qt_halfScaled(), qt_mac_createCGImageFromQImage(), qt_read_dibv5(), qt_write_dib(), qt_write_dibv5(), qt_x11_drawImage(), QTiffHandler::read(), read_dib_body(), read_pbm_body(), read_xbm_body(), read_xpm_body(), QPngHandlerPrivate::readPngImage(), QMeeGoPixmapData::registerSharedImage(), rotate_right_mirror_horizontal(), rotate_right_mirror_vertical(), rotated270(), rotated90(), QAhiScreenCursor::set(), QRasterPixmapData::setMask(), QPixmapData::setMask(), setPixel(), setup_qt(), smoothScaled(), QRasterPixmapData::toImage(), QX11PixmapData::toImage(), toVGImage(), toVGImageSubRect(), transformed(), QTiffHandler::write(), QBmpHandler::write(), write_jpeg_image(), write_pbm_image(), write_xbm_image(), write_xpm_image(), and QPNGImageWriter::writeImage().

2306 {
2307  return d ? d->format : Format_Invalid;
2308 }
QImageData * d
Definition: qimage.h:336
QImage::Format format
Definition: qimage_p.h:85

◆ fromData() [1/2]

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

Constructs a QImage from the first size bytes of the given binary 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 file for a header to guess the file format. binary data. The loader attempts to read the image, either using the optional image format specified or by determining the image format from the data.

If format is not specified (which is the default), the loader probes the file for a header to determine 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 5313 of file qimage.cpp.

Referenced by createImageNode(), fromData(), ICOReader::iconAt(), loadFromData(), and QInternalMimeData::retrieveData().

5314 {
5315  QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(data), size);
5316  QBuffer b;
5317  b.setData(a);
5319  return QImageReader(&b, format).read();
5320 }
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
Definition: qbuffer.cpp:315
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
long ASN1_INTEGER_get ASN1_INTEGER * a
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
static const char * data(const QByteArray &arr)
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
QImage read()
Reads an image from the device.

◆ fromData() [2/2]

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

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

259  { return fromData(reinterpret_cast<const uchar *>(data.constData()), data.size(), format); }
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static QImage fromData(const uchar *data, int size, const char *format=0)
Constructs a QImage from the first size bytes of the given binary data.
Definition: qimage.cpp:5313

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

Referenced by alphaChannel(), QXcbWindowSurface::beginPaint(), QXlibWindowSurface::beginPaint(), QWindowsMimeImage::canConvertFromMime(), QRasterPaintEnginePrivate::canUseFastImageBlending(), QVGPaintEngine::canVgWritePixels(), checkForAlphaPixels(), QRasterPixmapData::createPixmapForImage(), QGLPixmapData::createPixmapForImage(), QPixmapColorizeFilter::draw(), QDirectFBPaintEngine::drawImage(), QAlphaPaintEngine::drawImage(), QGL2PaintEngineEx::drawImage(), QPSPrintEngine::drawImageInternal(), QRasterPixmapData::fill(), QWindowsMimeImage::formatsForMime(), QMeeGoPixmapData::fromEGLSharedImage(), QBlittablePixmapData::fromImage(), QMacPixmapData::fromImage(), QBlittablePixmapData::hasAlphaChannel(), QVolatileImage::hasAlphaChannel(), QRasterPixmapData::hasAlphaChannel(), QDirectFBPixmapData::hasAlphaChannel(), QVGPixmapData::idealFormat(), QMeeGoPixmapData::imageToEGLSharedImage(), QSpanData::initTexture(), QBrush::isOpaque(), smoothScaled(), transformed(), QPainterPrivate::updateEmulationSpecifier(), QVNCClientCursor::write(), and QPNGImageWriter::writeImage().

◆ height()

int QImage::height ( ) const

Returns the height of the image.

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

Definition at line 1572 of file qimage.cpp.

Referenced by QFontEngine::addBitmapFontToPath(), QPdfEnginePrivate::addBrushPattern(), QPdfEnginePrivate::addImage(), QFontEngineXLFD::addOutlineToPath(), allGray(), QAlphaWidget::alphaBlend(), QProxyFontEngine::alphaMapForGlyph(), QFontEngineMac::alphaMapForGlyph(), QFontEngineDirectWrite::alphaMapForGlyph(), QFontEngineXLFD::alphaMapForGlyph(), QFontEngine::alphaMapForGlyph(), alphaMapFromPath(), QFontEngine::alphaRGBMapForGlyph(), QX11PixmapData::bitmapFromImage(), QAhiScreen::blit(), QProxyFontEngine::canRender(), checkForAlphaPixels(), colorCount(), colorizeBitmap(), compressHelper(), constScanLine(), QMacPasteboardMimeTiff::convertFromMime(), convertWithPalette(), convolute(), copy(), QImageData::create(), create32BitCursor(), QX11PixmapData::createBitmapFromImage(), QDirectFBScreen::createDFBSurface(), createHeuristicMask(), QVGPixmapData::createPixmapForImage(), QGLPixmapData::createPixmapForImage(), darkenPixmap(), QGIFFormat::decode(), QRasterPaintEngine::drawBitmap(), QCleanlooksStyle::drawComplexControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QVGCompositionHelper::drawCursorPixmap(), QPdfEngine::drawImage(), QCoreGraphicsPaintEngine::drawImage(), QPSPrintEnginePrivate::drawImage(), QGL2PaintEngineEx::drawImage(), QOpenGLPaintEngine::drawImage(), QVGPaintEngine::drawImage(), QPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QRasterPaintEnginePrivate::drawImage(), QPainter::drawImage(), QPSPrintEnginePrivate::drawImageHelper(), QPSPrintEngine::drawImageInternal(), drawImageTiled(), QPdfEngine::drawPixmap(), QPlastiqueStyle::drawPrimitive(), QRasterPaintEngine::drawTextItem(), QOpenGLPaintEngine::drawTiledPixmap(), expblur(), QRasterPixmapData::fill(), QGLTextureGlyphCache::fillTexture(), QImageTextureGlyphCache::fillTexture(), QXlibWindowSurface::flush(), QRasterBuffer::flushToARGBImage(), QVGFontEngineCleaner::fontEngineDestroyed(), format(), QBlittablePixmapData::fromImage(), QDirectFBPixmapData::fromImage(), QMacPixmapData::fromImage(), QX11PixmapData::fromImage(), QWindowsMobileStyle::generatedIconPixmap(), QCommonStyle::generatedIconPixmap(), QMacStyle::generatedIconPixmap(), getImageSize(), QVNCIntegration::grabWindow(), grayscale(), QVolatileImage::height(), QNativeImage::height(), ICOReader::iconAt(), QFontEngineMac::imageForGlyph(), QMeeGoPixmapData::imageToEGLSharedImage(), QBBBuffer::invalidateInCache(), QFontEngineQPF::loadGlyph(), QPixmapData::mask(), operator==(), QWSLocalMemSurface::permanentState(), QWSSharedMemSurface::permanentState(), pixel(), pixelIndex(), QRasterBuffer::prepare(), QRasterWindowSurface::prepareBuffer(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), qGamma_correct_back_to_linear_cs(), qgl_byteSwapImage(), QImageScale::qimageCalcScaleInfo(), QTestLiteStaticInfoPrivate::qimageFromXImage(), QMacCGContext::QMacCGContext(), qSmoothScaleImage(), qstring_to_xtp(), QSvgImage::QSvgImage(), qt_bitmapToRegion(), qt_blurImage(), qt_createIconMask(), qt_halfScaled(), qt_mac_cg_context(), qt_mac_createCGImageFromQImage(), qt_mac_image_to_cgimage(), qt_scrollRectInImage(), qt_write_dib(), qt_write_dibv5(), ICOReader::read1BitBMP(), rotate_right_mirror_horizontal(), rotate_right_mirror_vertical(), rotated270(), rotated90(), scaled(), scaledToHeight(), scanLine(), QItemDelegate::selected(), QVNCCursor::sendClientCursor(), QAhiScreenCursor::set(), QRasterPixmapData::setMask(), QPixmapData::setMask(), setPixel(), QMacStyle::styleHint(), QX11PixmapData::takeQImageFromXImage(), toVGImage(), QPixmap::toWinHBITMAP(), transformed(), QMeeGoPixmapData::updateFromSoftImage(), QTiffHandler::write(), QBmpHandler::write(), QVNCClientCursor::write(), ICOReader::write(), write_jpeg_image(), write_pbm_image(), write_xbm_image(), write_xpm_image(), QMngHandlerPrivate::writeImage(), QPNGImageWriter::writeImage(), and QTextOdfWriter::writeInlineCharacter().

1573 {
1574  return d ? d->height : 0;
1575 }
QImageData * d
Definition: qimage.h:336
int height
Definition: qimage_p.h:77

◆ invertPixels()

void QImage::invertPixels ( InvertMode  mode = InvertRgb)

Inverts all pixel values in the image.

Use the invertPixels() function that takes a QImage::InvertMode parameter instead.

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.

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

Definition at line 2179 of file qimage.cpp.

Referenced by QX11PixmapData::createBitmapFromImage(), createMaskFromColor(), QImageTextureGlyphCache::fillTexture(), QBitmap::fromImage(), makeBitmapCompliantIfNeeded(), qt_createIconMask(), and toVGImage().

2180 {
2181  if (!d)
2182  return;
2183 
2184  detach();
2185 
2186  // In case detach() ran out of memory
2187  if (!d)
2188  return;
2189 
2190  if (depth() != 32) {
2191  // number of used bytes pr line
2192  int bpl = (d->width * d->depth + 7) / 8;
2193  int pad = d->bytes_per_line - bpl;
2194  uchar *sl = d->data;
2195  for (int y=0; y<d->height; ++y) {
2196  for (int x=0; x<bpl; ++x)
2197  *sl++ ^= 0xff;
2198  sl += pad;
2199  }
2200  } else {
2201  quint32 *p = (quint32*)d->data;
2202  quint32 *end = (quint32*)(d->data + d->nbytes);
2203  uint xorbits = (mode == InvertRgba) ? 0xffffffff : 0x00ffffff;
2204  while (p < end)
2205  *p++ ^= xorbits;
2206  }
2207 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
unsigned int uint
Definition: qglobal.h:996
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
int nbytes
Definition: qimage_p.h:79
int bytes_per_line
Definition: qimage_p.h:86
unsigned int quint32
Definition: qglobal.h:938
uchar * data
Definition: qimage_p.h:81
int depth
Definition: qimage_p.h:78
static const KeyPair *const end

◆ isDetached()

bool QImage::isDetached ( ) const

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

Warning
This function is not part of the public interface.
See also
detach(), {Implicit Data Sharing}

Definition at line 6301 of file qimage.cpp.

6302 {
6303  return d && d->ref == 1;
6304 }
QImageData * d
Definition: qimage.h:336
QAtomicInt ref
Definition: qimage_p.h:74

◆ isGrayscale()

bool QImage::isGrayscale ( ) const

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

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

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

Definition at line 4477 of file qimage.cpp.

Referenced by setAlphaChannel().

4478 {
4479  if (!d)
4480  return false;
4481 
4482  switch (depth()) {
4483  case 32:
4484  case 24:
4485  case 16:
4486  return allGray();
4487  case 8: {
4488  for (int i = 0; i < colorCount(); i++)
4489  if (d->colortable.at(i) != qRgb(i,i,i))
4490  return false;
4491  return true;
4492  }
4493  }
4494  return false;
4495 }
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
Definition: qrgb.h:69
bool allGray() const
Returns true if all the colors in the image are shades of gray (i.e.
Definition: qimage.cpp:4435

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

Referenced by QPdfEnginePrivate::addImage(), QFontEngineXLFD::addOutlineToPath(), QPainter::begin(), QScreen::blit(), QDirectFBPixmapData::buffer(), QGLWindowSurface::buffer(), QWindowsMimeImage::canConvertFromMime(), QProxyFontEngine::canRender(), QPixmap::convertFromImage(), QWindowsMimeImage::convertFromMime(), copy(), QVolatileImage::copyFrom(), createAlphaMask(), QDirectFBScreen::createDFBSurface(), createImageNode(), createPixmapDataSync(), QVGPixmapData::createPixmapForImage(), QGIFFormat::decode(), QPdfEngine::drawImage(), QCoreGraphicsPaintEngine::drawImage(), QPSPrintEnginePrivate::drawImage(), QVGPaintEngine::drawImage(), QPainter::drawImage(), QPSPrintEnginePrivate::drawImageHelper(), QCleanlooksStyle::drawPrimitive(), QOpenGLPaintEngine::drawTiledPixmap(), QGLPixmapData::ensureCreated(), ensureValidImage(), QScreen::exposeRegion(), QRasterPixmapData::fill(), QGLPixmapData::fill(), QXlibWindowSurface::flush(), QVGFontEngineCleaner::fontEngineDestroyed(), QWindowsMimeImage::formatsForMime(), QRasterPixmapData::fromData(), QVGPixmapData::fromData(), QGLPixmapData::fromData(), QMeeGoPixmapData::fromEGLSharedImage(), QVGPixmapData::fromFile(), QPixmapData::fromFile(), QGLPixmapData::fromFile(), QBitmap::fromImage(), QVGPixmapData::fromImage(), QPixmap::fromImage(), QRasterPixmapData::fromImageReader(), QVGPixmapData::fromImageReader(), QGLPixmapData::fromImageReader(), QPixmap::fromWinHBITMAP(), QPixmap::fromWinHICON(), getImage(), getImageSize(), getPixmap(), QWindowSurface::grabWidget(), ICOReader::iconAt(), QTextCursor::insertImage(), QVolatileImage::isNull(), QWSMemorySurface::isValid(), QWSOnScreenSurface::isValid(), load(), loadFromData(), QTextDocument::loadResource(), QPixmapData::mask(), QDirectFBPaintDevice::metric(), operator<<(), operator>>(), QDeclarativePixmapReader::processJob(), QPixmap::QPixmap(), QPixmapCacheEntry::QPixmapCacheEntry(), qSmoothScaleImage(), qt_read_dibv5(), QTiffHandler::read(), QtIcoHandler::read(), QTgaHandler::read(), read_dib_body(), read_pbm_body(), read_xbm_body(), read_xpm_body(), QPngHandlerPrivate::readPngImage(), QRasterPixmapData::resize(), rgbSwapped(), QAlphaWidget::run(), save(), QMeeGoLivePixmapData::scroll(), QXcbWindowSurface::scroll(), QXlibWindowSurface::scroll(), QRasterPixmapData::scroll(), QVNCCursor::sendClientCursor(), QAhiScreenCursor::set(), QDirectFBScreenCursor::set(), setAlphaChannel(), QWSServer::setBackground(), setPixel(), QBrush::setTextureImage(), setup_qt(), QMacPixmapData::toImage(), QRasterPixmapData::toImage(), QX11PixmapData::toImage(), QGLPixmapData::toImage(), QPixmap::toWinHICON(), QVNCClientCursor::write(), and QTextOdfWriter::writeInlineCharacter().

1543 {
1544  return !d;
1545 }
QImageData * d
Definition: qimage.h:336

◆ load() [1/2]

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

This function reads a QImage from the given device.

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

This can, for example, be used to load an image directly into a QByteArray.

Definition at line 5251 of file qimage.cpp.

Referenced by getImage(), getPixmap(), QImage(), and QTextOdfWriter::writeInlineCharacter().

5252 {
5253  QImage image = QImageReader(device, format).read();
5254  if(!image.isNull()) {
5255  operator=(image);
5256  return true;
5257  }
5258  return false;
5259 }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage & operator=(const QImage &)
Assigns a shallow copy of the given image to this image and returns a reference to this image...
Definition: qimage.cpp:1304
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
QImage read()
Reads an image from the device.

◆ load() [2/2]

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

Loads an image from the file with the given fileName.

Returns true if the image was successfully loaded; otherwise 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.

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

See also
Reading and Writing Image Files

Definition at line 5228 of file qimage.cpp.

5229 {
5230  if (fileName.isEmpty())
5231  return false;
5232 
5233  QImage image = QImageReader(fileName, format).read();
5234  if (!image.isNull()) {
5235  operator=(image);
5236  return true;
5237  }
5238  return false;
5239 }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage & operator=(const QImage &)
Assigns a shallow copy of the given image to this image and returns a reference to this image...
Definition: qimage.cpp:1304
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
QImage read()
Reads an image from the device.

◆ loadFromData() [1/2]

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

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

Returns true if the image was successfully loaded; otherwise 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 5275 of file qimage.cpp.

Referenced by QTextHtmlParserNode::applyBackgroundImage(), QWindowsMimeImage::convertToMime(), getImage(), QTextDocument::loadResource(), and QTextOdfWriter::writeInlineCharacter().

5276 {
5277  QImage image = fromData(data, len, format);
5278  if (!image.isNull()) {
5279  operator=(image);
5280  return true;
5281  }
5282  return false;
5283 }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
QImage & operator=(const QImage &)
Assigns a shallow copy of the given image to this image and returns a reference to this image...
Definition: qimage.cpp:1304
static QImage fromData(const uchar *data, int size, const char *format=0)
Constructs a QImage from the first size bytes of the given binary data.
Definition: qimage.cpp:5313

◆ loadFromData() [2/2]

bool QImage::loadFromData ( const QByteArray data,
const char *  aformat = 0 
)
inline

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

Definition at line 251 of file qimage.h.

252  { return loadFromData(reinterpret_cast<const uchar *>(data.constData()), data.size(), aformat); }
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
bool loadFromData(const uchar *buf, int len, const char *format=0)
Loads an image from the first len bytes of the given binary data.
Definition: qimage.cpp:5275

◆ metric()

int QImage::metric ( PaintDeviceMetric  metric) const
protectedvirtual

Returns the size for the specified metric on the device.

Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 5995 of file qimage.cpp.

5996 {
5997  if (!d)
5998  return 0;
5999 
6000  switch (metric) {
6001  case PdmWidth:
6002  return d->width;
6003  break;
6004 
6005  case PdmHeight:
6006  return d->height;
6007  break;
6008 
6009  case PdmWidthMM:
6010  return qRound(d->width * 1000 / d->dpmx);
6011  break;
6012 
6013  case PdmHeightMM:
6014  return qRound(d->height * 1000 / d->dpmy);
6015  break;
6016 
6017  case PdmNumColors:
6018  return d->colortable.size();
6019  break;
6020 
6021  case PdmDepth:
6022  return d->depth;
6023  break;
6024 
6025  case PdmDpiX:
6026  return qRound(d->dpmx * 0.0254);
6027  break;
6028 
6029  case PdmDpiY:
6030  return qRound(d->dpmy * 0.0254);
6031  break;
6032 
6033  case PdmPhysicalDpiX:
6034  return qRound(d->dpmx * 0.0254);
6035  break;
6036 
6037  case PdmPhysicalDpiY:
6038  return qRound(d->dpmy * 0.0254);
6039  break;
6040 
6041  default:
6042  qWarning("QImage::metric(): Unhandled metric type %d", metric);
6043  break;
6044  }
6045  return 0;
6046 }
int width
Definition: qimage_p.h:76
qreal dpmy
Definition: qimage_p.h:91
virtual int metric(PaintDeviceMetric metric) const
Returns the size for the specified metric on the device.
Definition: qimage.cpp:5995
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
int height
Definition: qimage_p.h:77
qreal dpmx
Definition: qimage_p.h:90
Q_CORE_EXPORT void qWarning(const char *,...)
int depth
Definition: qimage_p.h:78
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ mirrored()

QImage QImage::mirrored ( bool  horizontal = false,
bool  vertical = true 
) const

Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false.

Note that the original image is not changed.

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

Definition at line 4922 of file qimage.cpp.

Referenced by QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QGLPixmapData::ensureCreated(), QWindowsMobileStylePrivate::QWindowsMobileStylePrivate(), QTiffHandler::read(), rotated180(), QCommonStyle::standardPixmap(), QWaylandReadbackEglContext::swapBuffers(), QWaylandReadbackGlxContext::swapBuffers(), and transformed().

4923 {
4924  if (!d)
4925  return QImage();
4926 
4927  if ((d->width <= 1 && d->height <= 1) || (!horizontal && !vertical))
4928  return *this;
4929 
4930  int w = d->width;
4931  int h = d->height;
4932  // Create result image, copy colormap
4933  QImage result(d->width, d->height, d->format);
4934  QIMAGE_SANITYCHECK_MEMORY(result);
4935 
4936  // check if we ran out of of memory..
4937  if (!result.d)
4938  return QImage();
4939 
4940  result.d->colortable = d->colortable;
4941  result.d->has_alpha_clut = d->has_alpha_clut;
4942 
4943  if (depth() == 1)
4944  w = (w+7)/8;
4945  int dxi = horizontal ? -1 : 1;
4946  int dxs = horizontal ? w-1 : 0;
4947  int dyi = vertical ? -1 : 1;
4948  int dy = vertical ? h-1: 0;
4949 
4950  // 1 bit, 8 bit
4951  if (d->depth == 1 || d->depth == 8) {
4952  for (int sy = 0; sy < h; sy++, dy += dyi) {
4953  quint8* ssl = (quint8*)(d->data + sy*d->bytes_per_line);
4954  quint8* dsl = (quint8*)(result.d->data + dy*result.d->bytes_per_line);
4955  int dx = dxs;
4956  for (int sx = 0; sx < w; sx++, dx += dxi)
4957  dsl[dx] = ssl[sx];
4958  }
4959  }
4960  // 16 bit
4961  else if (d->depth == 16) {
4962  for (int sy = 0; sy < h; sy++, dy += dyi) {
4963  quint16* ssl = (quint16*)(d->data + sy*d->bytes_per_line);
4964  quint16* dsl = (quint16*)(result.d->data + dy*result.d->bytes_per_line);
4965  int dx = dxs;
4966  for (int sx = 0; sx < w; sx++, dx += dxi)
4967  dsl[dx] = ssl[sx];
4968  }
4969  }
4970  // 24 bit
4971  else if (d->depth == 24) {
4972  for (int sy = 0; sy < h; sy++, dy += dyi) {
4973  quint24* ssl = (quint24*)(d->data + sy*d->bytes_per_line);
4974  quint24* dsl = (quint24*)(result.d->data + dy*result.d->bytes_per_line);
4975  int dx = dxs;
4976  for (int sx = 0; sx < w; sx++, dx += dxi)
4977  dsl[dx] = ssl[sx];
4978  }
4979  }
4980  // 32 bit
4981  else if (d->depth == 32) {
4982  for (int sy = 0; sy < h; sy++, dy += dyi) {
4983  quint32* ssl = (quint32*)(d->data + sy*d->bytes_per_line);
4984  quint32* dsl = (quint32*)(result.d->data + dy*result.d->bytes_per_line);
4985  int dx = dxs;
4986  for (int sx = 0; sx < w; sx++, dx += dxi)
4987  dsl[dx] = ssl[sx];
4988  }
4989  }
4990 
4991  // special handling of 1 bit images for horizontal mirroring
4992  if (horizontal && d->depth == 1) {
4993  int shift = width() % 8;
4994  for (int y = h-1; y >= 0; y--) {
4995  quint8* a0 = (quint8*)(result.d->data + y*d->bytes_per_line);
4996  // Swap bytes
4997  quint8* a = a0+dxs;
4998  while (a >= a0) {
4999  *a = bitflip[*a];
5000  a--;
5001  }
5002  // Shift bits if unaligned
5003  if (shift != 0) {
5004  a = a0+dxs;
5005  quint8 c = 0;
5006  if (format() == Format_MonoLSB) {
5007  while (a >= a0) {
5008  quint8 nc = *a << shift;
5009  *a = (*a >> (8-shift)) | c;
5010  --a;
5011  c = nc;
5012  }
5013  } else {
5014  while (a >= a0) {
5015  quint8 nc = *a >> shift;
5016  *a = (*a << (8-shift)) | c;
5017  --a;
5018  c = nc;
5019  }
5020  }
5021  }
5022  }
5023  }
5024 
5025  return result;
5026 }
int width
Definition: qimage_p.h:76
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
Definition: qbezier.cpp:289
unsigned char c[8]
Definition: qnumeric_p.h:62
uint has_alpha_clut
Definition: qimage_p.h:96
long ASN1_INTEGER_get ASN1_INTEGER * a
unsigned char quint8
Definition: qglobal.h:934
QVectorData * d
Definition: qvector.h:109
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
QImage()
Constructs a null image.
Definition: qimage.cpp:798
int height
Definition: qimage_p.h:77
unsigned short quint16
Definition: qglobal.h:936
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
int bytes_per_line
Definition: qimage_p.h:86
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
static const uchar bitflip[256]
Definition: qimage.cpp:736
QImage::Format format
Definition: qimage_p.h:85
unsigned int quint32
Definition: qglobal.h:938
uchar * data
Definition: qimage_p.h:81
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105
int depth
Definition: qimage_p.h:78

◆ numBytes()

int QImage::numBytes ( ) const

Returns the number of bytes occupied by the image data.

See also
byteCount()

Definition at line 1785 of file qimage.cpp.

1786 {
1787  return d ? d->nbytes : 0;
1788 }
QImageData * d
Definition: qimage.h:336
int nbytes
Definition: qimage_p.h:79

◆ numColors()

int QImage::numColors ( ) const

Returns the size of the color table for the image.

See also
setColorCount()

Definition at line 1636 of file qimage.cpp.

Referenced by convert_RGB_to_Indexed8(), format(), QMacPixmapData::fromImage(), and QImage().

1637 {
1638  return d ? d->colortable.size() : 0;
1639 }
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

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

Referenced by copy(), and QPNGImageWriter::writeImage().

5689 {
5690  return d ? d->offset : QPoint();
5691 }
QImageData * d
Definition: qimage.h:336
QPoint offset
Definition: qimage_p.h:92
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ operator QVariant()

QImage::operator QVariant ( ) const

Returns the image as a QVariant.

Definition at line 1340 of file qimage.cpp.

1341 {
1342  return QVariant(QVariant::Image, this);
1343 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

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

5600 {
5601  return !(*this == i);
5602 }

◆ operator=()

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

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 Implicit Data Sharing documentation.

See also
copy(), QImage()

Definition at line 1304 of file qimage.cpp.

Referenced by load(), loadFromData(), and QImage().

1305 {
1306  if (image.paintingActive()) {
1307  operator=(image.copy());
1308  } else {
1309  if (image.d)
1310  image.d->ref.ref();
1311  if (d && !d->ref.deref())
1312  delete d;
1313  d = image.d;
1314  }
1315  return *this;
1316 }
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
bool ref()
Atomically increments the value of this QAtomicInt.
QImageData * d
Definition: qimage.h:336
bool paintingActive() const
Definition: qpaintdevice.h:170
bool deref()
Atomically decrements the value of this QAtomicInt.
QImage & operator=(const QImage &)
Assigns a shallow copy of the given image to this image and returns a reference to this image...
Definition: qimage.cpp:1304
QAtomicInt ref
Definition: qimage_p.h:74

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

5532 {
5533  // same object, or shared?
5534  if (i.d == d)
5535  return true;
5536  if (!i.d || !d)
5537  return false;
5538 
5539  // obviously different stuff?
5540  if (i.d->height != d->height || i.d->width != d->width || i.d->format != d->format)
5541  return false;
5542 
5543  if (d->format != Format_RGB32) {
5544  if (d->format >= Format_ARGB32) { // all bits defined
5545  const int n = d->width * d->depth / 8;
5546  if (n == d->bytes_per_line && n == i.d->bytes_per_line) {
5547  if (memcmp(bits(), i.bits(), d->nbytes))
5548  return false;
5549  } else {
5550  for (int y = 0; y < d->height; ++y) {
5551  if (memcmp(scanLine(y), i.scanLine(y), n))
5552  return false;
5553  }
5554  }
5555  } else {
5556  const int w = width();
5557  const int h = height();
5558  const QVector<QRgb> &colortable = d->colortable;
5559  const QVector<QRgb> &icolortable = i.d->colortable;
5560  for (int y=0; y<h; ++y) {
5561  for (int x=0; x<w; ++x) {
5562  if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)])
5563  return false;
5564  }
5565  }
5566  }
5567  } else {
5568  //alpha channel undefined, so we must mask it out
5569  for(int l = 0; l < d->height; l++) {
5570  int w = d->width;
5571  const uint *p1 = reinterpret_cast<const uint*>(scanLine(l));
5572  const uint *p2 = reinterpret_cast<const uint*>(i.scanLine(l));
5573  while (w--) {
5574  if ((*p1++ & 0x00ffffff) != (*p2++ & 0x00ffffff))
5575  return false;
5576  }
5577  }
5578  }
5579  return true;
5580 }
int width
Definition: qimage_p.h:76
QVectorData * d
Definition: qvector.h:109
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
int pixelIndex(int x, int y) const
Returns the pixel index at (x, y).
Definition: qimage.cpp:4194
int height
Definition: qimage_p.h:77
unsigned int uint
Definition: qglobal.h:996
int nbytes
Definition: qimage_p.h:79
int bytes_per_line
Definition: qimage_p.h:86
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage::Format format
Definition: qimage_p.h:85
QFactoryLoader * l
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int depth
Definition: qimage_p.h:78
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ paintEngine()

QPaintEngine * QImage::paintEngine ( ) const
virtual

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

Warning
This function is not part of the public interface.

Implements QPaintDevice.

Definition at line 5970 of file qimage.cpp.

Referenced by QRasterPixmapData::paintEngine(), QGLPixmapData::paintEngine(), QNativeImage::QNativeImage(), and QNativeImage::systemFormat().

5971 {
5972  if (!d)
5973  return 0;
5974 
5975  if (!d->paintEngine) {
5976 #ifdef Q_OS_SYMBIAN
5977  d->paintEngine = new QSymbianRasterPaintEngine(const_cast<QImage *>(this));
5978 #else
5979  d->paintEngine = new QRasterPaintEngine(const_cast<QImage *>(this));
5980 #endif
5981  }
5982 
5983  return d->paintEngine;
5984 }
QImageData * d
Definition: qimage.h:336
QPaintEngine * paintEngine
Definition: qimage_p.h:110
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...

◆ pixel() [1/2]

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

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

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

Referenced by createMaskFromColor(), darkenPixmap(), QRasterPaintEngine::drawImage(), fill(), QWindowsMobileStyle::generatedIconPixmap(), QMacStyle::generatedIconPixmap(), qcolorForThemeTextColor(), rotated270(), and rotated90().

4241 {
4242  if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) {
4243  qWarning("QImage::pixel: coordinate (%d,%d) out of range", x, y);
4244  return 12345;
4245  }
4246  const uchar * s = scanLine(y);
4247  switch(d->format) {
4248  case Format_Mono:
4249  return d->colortable.at((*(s + (x >> 3)) >> (7- (x & 7))) & 1);
4250  case Format_MonoLSB:
4251  return d->colortable.at((*(s + (x >> 3)) >> (x & 7)) & 1);
4252  case Format_Indexed8:
4253  return d->colortable.at((int)s[x]);
4255  return qt_colorConvert<quint32, qargb8565>(reinterpret_cast<const qargb8565*>(s)[x], 0);
4256  case Format_RGB666:
4257  return qt_colorConvert<quint32, qrgb666>(reinterpret_cast<const qrgb666*>(s)[x], 0);
4259  return qt_colorConvert<quint32, qargb6666>(reinterpret_cast<const qargb6666*>(s)[x], 0);
4260  case Format_RGB555:
4261  return qt_colorConvert<quint32, qrgb555>(reinterpret_cast<const qrgb555*>(s)[x], 0);
4263  return qt_colorConvert<quint32, qargb8555>(reinterpret_cast<const qargb8555*>(s)[x], 0);
4264  case Format_RGB888:
4265  return qt_colorConvert<quint32, qrgb888>(reinterpret_cast<const qrgb888*>(s)[x], 0);
4266  case Format_RGB444:
4267  return qt_colorConvert<quint32, qrgb444>(reinterpret_cast<const qrgb444*>(s)[x], 0);
4269  return qt_colorConvert<quint32, qargb4444>(reinterpret_cast<const qargb4444*>(s)[x], 0);
4270  case Format_RGB16:
4271  return qt_colorConvert<quint32, quint16>(reinterpret_cast<const quint16*>(s)[x], 0);
4272  default:
4273  return ((QRgb*)s)[x];
4274  }
4275 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
unsigned char uchar
Definition: qglobal.h:994
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QImage::Format format
Definition: qimage_p.h:85
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ pixel() [2/2]

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

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.
See also
setPixel(), valid(), {QImage::Pixel Manipulation}{Pixel Manipulation}

Definition at line 356 of file qimage.h.

356 { return pixel(pt.x(), pt.y()); }
QRgb pixel(int x, int y) const
Returns the color of the pixel at coordinates (x, y).
Definition: qimage.cpp:4240

◆ pixelIndex() [1/2]

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

Returns the pixel index at (x, y).

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

Referenced by QWSCursor::createDropShadow(), operator==(), rotated270(), and rotated90().

4195 {
4196  if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) {
4197  qWarning("QImage::pixelIndex: coordinate (%d,%d) out of range", x, y);
4198  return -12345;
4199  }
4200  const uchar * s = scanLine(y);
4201  switch(d->format) {
4202  case Format_Mono:
4203  return (*(s + (x >> 3)) >> (7- (x & 7))) & 1;
4204  case Format_MonoLSB:
4205  return (*(s + (x >> 3)) >> (x & 7)) & 1;
4206  case Format_Indexed8:
4207  return (int)s[x];
4208  default:
4209  qWarning("QImage::pixelIndex: Not applicable for %d-bpp images (no palette)", d->depth);
4210  }
4211  return 0;
4212 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336
unsigned char uchar
Definition: qglobal.h:994
Q_CORE_EXPORT void qWarning(const char *,...)
QImage::Format format
Definition: qimage_p.h:85
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int depth
Definition: qimage_p.h:78
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ pixelIndex() [2/2]

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

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

355 { return pixelIndex(pt.x(), pt.y());}
int pixelIndex(int x, int y) const
Returns the pixel index at (x, y).
Definition: qimage.cpp:4194

◆ rect()

QRect QImage::rect ( ) const

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

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

Definition at line 1603 of file qimage.cpp.

Referenced by convolute(), QPixmapColorizeFilter::draw(), QWindowsVistaStyle::drawControl(), QDirectFBPaintEngine::drawImage(), QBlitterPaintEngine::drawImage(), QPdfEngine::drawImage(), QRasterPaintEngine::drawImage(), QPaintEngineEx::drawImage(), QPainter::drawImage(), QTextImageHandler::drawObject(), fill(), QRasterWindowSurface::flush(), QPlatformSoftwareCursor::getCurrentRect(), grayscale(), QGLPixmapDropShadowFilter::processGL(), QBBBuffer::rect(), and trueMatrix().

1604 {
1605  return d ? QRect(0, 0, d->width, d->height) : QRect();
1606 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336
int height
Definition: qimage_p.h:77
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ rgbSwapped()

QImage QImage::rgbSwapped ( ) const

Returns a QImage in which the values of the red and blue components of all pixels have been swapped, effectively converting an RGB image to an BGR image.

The original QImage is not changed.

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

Definition at line 5052 of file qimage.cpp.

5053 {
5054  if (isNull())
5055  return *this;
5056  QImage res;
5057  switch (d->format) {
5058  case Format_Invalid:
5059  case NImageFormats:
5060  Q_ASSERT(false);
5061  break;
5062  case Format_Mono:
5063  case Format_MonoLSB:
5064  case Format_Indexed8:
5065  res = copy();
5067  for (int i = 0; i < res.d->colortable.size(); i++) {
5068  QRgb c = res.d->colortable.at(i);
5069  res.d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00));
5070  }
5071  break;
5072  case Format_RGB32:
5073  case Format_ARGB32:
5075  res = QImage(d->width, d->height, d->format);
5077  for (int i = 0; i < d->height; i++) {
5078  uint *q = (uint*)res.scanLine(i);
5079  uint *p = (uint*)constScanLine(i);
5080  uint *end = p + d->width;
5081  while (p < end) {
5082  *q = ((*p << 16) & 0xff0000) | ((*p >> 16) & 0xff) | (*p & 0xff00ff00);
5083  p++;
5084  q++;
5085  }
5086  }
5087  break;
5088  case Format_RGB16:
5089  res = QImage(d->width, d->height, d->format);
5091  for (int i = 0; i < d->height; i++) {
5092  ushort *q = (ushort*)res.scanLine(i);
5093  const ushort *p = (const ushort*)constScanLine(i);
5094  const ushort *end = p + d->width;
5095  while (p < end) {
5096  *q = ((*p << 11) & 0xf800) | ((*p >> 11) & 0x1f) | (*p & 0x07e0);
5097  p++;
5098  q++;
5099  }
5100  }
5101  break;
5103  res = QImage(d->width, d->height, d->format);
5105  for (int i = 0; i < d->height; i++) {
5106  const quint8 *p = constScanLine(i);
5107  quint8 *q = res.scanLine(i);
5108  const quint8 *end = p + d->width * sizeof(qargb8565);
5109  while (p < end) {
5110  q[0] = p[0];
5111  q[1] = (p[1] & 0xe0) | (p[2] >> 3);
5112  q[2] = (p[2] & 0x07) | (p[1] << 3);
5113  p += sizeof(qargb8565);
5114  q += sizeof(qargb8565);
5115  }
5116  }
5117  break;
5118  case Format_RGB666:
5119  res = QImage(d->width, d->height, d->format);
5121  for (int i = 0; i < d->height; i++) {
5122  qrgb666 *q = reinterpret_cast<qrgb666*>(res.scanLine(i));
5123  const qrgb666 *p = reinterpret_cast<const qrgb666*>(constScanLine(i));
5124  const qrgb666 *end = p + d->width;
5125  while (p < end) {
5126  const QRgb rgb = quint32(*p++);
5127  *q++ = qRgb(qBlue(rgb), qGreen(rgb), qRed(rgb));
5128  }
5129  }
5130  break;
5132  res = QImage(d->width, d->height, d->format);
5134  for (int i = 0; i < d->height; i++) {
5135  const quint8 *p = constScanLine(i);
5136  const quint8 *end = p + d->width * sizeof(qargb6666);
5137  quint8 *q = res.scanLine(i);
5138  while (p < end) {
5139  q[0] = (p[1] >> 4) | ((p[2] & 0x3) << 4) | (p[0] & 0xc0);
5140  q[1] = (p[1] & 0xf) | (p[0] << 4);
5141  q[2] = (p[2] & 0xfc) | ((p[0] >> 4) & 0x3);
5142  p += sizeof(qargb6666);
5143  q += sizeof(qargb6666);
5144  }
5145  }
5146  break;
5147  case Format_RGB555:
5148  res = QImage(d->width, d->height, d->format);
5150  for (int i = 0; i < d->height; i++) {
5151  quint16 *q = (quint16*)res.scanLine(i);
5152  const quint16 *p = (const quint16*)constScanLine(i);
5153  const quint16 *end = p + d->width;
5154  while (p < end) {
5155  *q = ((*p << 10) & 0x7c00) | ((*p >> 10) & 0x1f) | (*p & 0x3e0);
5156  p++;
5157  q++;
5158  }
5159  }
5160  break;
5162  res = QImage(d->width, d->height, d->format);
5164  for (int i = 0; i < d->height; i++) {
5165  const quint8 *p = constScanLine(i);
5166  quint8 *q = res.scanLine(i);
5167  const quint8 *end = p + d->width * sizeof(qargb8555);
5168  while (p < end) {
5169  q[0] = p[0];
5170  q[1] = (p[1] & 0xe0) | (p[2] >> 2);
5171  q[2] = (p[2] & 0x03) | ((p[1] << 2) & 0x7f);
5172  p += sizeof(qargb8555);
5173  q += sizeof(qargb8555);
5174  }
5175  }
5176  break;
5177  case Format_RGB888:
5178  res = QImage(d->width, d->height, d->format);
5180  for (int i = 0; i < d->height; i++) {
5181  quint8 *q = res.scanLine(i);
5182  const quint8 *p = constScanLine(i);
5183  const quint8 *end = p + d->width * sizeof(qrgb888);
5184  while (p < end) {
5185  q[0] = p[2];
5186  q[1] = p[1];
5187  q[2] = p[0];
5188  q += sizeof(qrgb888);
5189  p += sizeof(qrgb888);
5190  }
5191  }
5192  break;
5193  case Format_RGB444:
5195  res = QImage(d->width, d->height, d->format);
5197  for (int i = 0; i < d->height; i++) {
5198  quint16 *q = reinterpret_cast<quint16*>(res.scanLine(i));
5199  const quint16 *p = reinterpret_cast<const quint16*>(constScanLine(i));
5200  const quint16 *end = p + d->width;
5201  while (p < end) {
5202  *q = (*p & 0xf0f0) | ((*p & 0x0f) << 8) | ((*p & 0xf00) >> 8);
5203  p++;
5204  q++;
5205  }
5206  }
5207  break;
5208  }
5209  return res;
5210 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
unsigned char c[8]
Definition: qnumeric_p.h:62
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
unsigned char quint8
Definition: qglobal.h:934
QImageData * d
Definition: qimage.h:336
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
QImage()
Constructs a null image.
Definition: qimage.cpp:798
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
int height
Definition: qimage_p.h:77
unsigned short quint16
Definition: qglobal.h:936
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
const uchar * constScanLine(int) const
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1926
unsigned short ushort
Definition: qglobal.h:995
QImage::Format format
Definition: qimage_p.h:85
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
Definition: qrgb.h:69
unsigned int quint32
Definition: qglobal.h:938
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ save() [1/2]

bool QImage::save ( const QString fileName,
const char *  format = 0,
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 0, 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 5346 of file qimage.cpp.

Referenced by drawEllipse_midpoint_i(), QSvgPaintEngine::drawImage(), QMimeDataWrapper::encodedData(), QMinimalWindowSurface::flush(), QInternalMimeData::renderDataHelper(), and xdndObtainData().

5347 {
5348  if (isNull())
5349  return false;
5350  QImageWriter writer(fileName, format);
5351  return d->doImageIO(this, &writer, quality);
5352 }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QImageData * d
Definition: qimage.h:336
The QImageWriter class provides a format independent interface for writing images to files or other d...
Definition: qimagewriter.h:59
bool doImageIO(const QImage *image, QImageWriter *io, int quality) const
Definition: qimage.cpp:5379

◆ save() [2/2]

bool QImage::save ( QIODevice device,
const char *  format = 0,
int  quality = -1 
) const

This function writes a QImage to the given device.

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

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

QImage image;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG"); // writes image into ba in PNG format

Definition at line 5368 of file qimage.cpp.

5369 {
5370  if (isNull())
5371  return false; // nothing to save
5372  QImageWriter writer(device, format);
5373  return d->doImageIO(this, &writer, quality);
5374 }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QImageData * d
Definition: qimage.h:336
The QImageWriter class provides a format independent interface for writing images to files or other d...
Definition: qimagewriter.h:59
bool doImageIO(const QImage *image, QImageWriter *io, int quality) const
Definition: qimage.cpp:5379

◆ scaled() [1/2]

QImage QImage::scaled ( int  w,
int  h,
Qt::AspectRatioMode  aspectMode = Qt::IgnoreAspectRatio,
Qt::TransformationMode  mode = Qt::FastTransformation 
) const
inline

Definition at line 232 of file qimage.h.

Referenced by QGL2PaintEngineEx::drawImage(), QOpenGLPaintEngine::drawImage(), QPSPrintEngine::drawImageInternal(), QWindowsMobileStylePrivate::drawPanelItemViewSelected(), QOpenGLPaintEngine::drawTiledPixmap(), QMoviePrivate::next(), qt_mac_create_iconref(), QImageReader::read(), and ICOReader::write().

234  { return scaled(QSize(w, h), aspectMode, mode); }
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qimage.h:232

◆ scaled() [2/2]

QImage QImage::scaled ( const QSize s,
Qt::AspectRatioMode  aspectMode = Qt::IgnoreAspectRatio,
Qt::TransformationMode  mode = Qt::FastTransformation 
) const

Definition at line 4577 of file qimage.cpp.

4578 {
4579  if (!d) {
4580  qWarning("QImage::scaled: Image is a null image");
4581  return QImage();
4582  }
4583  if (s.isEmpty())
4584  return QImage();
4585 
4586  QSize newSize = size();
4587  newSize.scale(s, aspectMode);
4588  newSize.rwidth() = qMax(newSize.width(), 1);
4589  newSize.rheight() = qMax(newSize.height(), 1);
4590  if (newSize == size())
4591  return *this;
4592 
4593  QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
4594  QImage img = transformed(wm, mode);
4595  return img;
4596 }
double qreal
Definition: qglobal.h:1193
QImageData * d
Definition: qimage.h:336
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QImage()
Constructs a null image.
Definition: qimage.cpp:798
int width() const
Returns the width.
Definition: qsize.h:126
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const
Returns a copy of the image that is transformed using the given transformation matrix and transformat...
Definition: qimage.cpp:4698
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int & rheight()
Returns a reference to the height.
Definition: qsize.h:144
int height() const
Returns the height.
Definition: qsize.h:129
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void scale(int w, int h, Qt::AspectRatioMode mode)
Scales the size to a rectangle with the given width and height, according to the specified mode: ...
Definition: qsize.h:138
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ scaledToHeight()

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

Returns a scaled copy of the image.

The returned image is scaled to the given height using the specified transformation mode.

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

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

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

Definition at line 4646 of file qimage.cpp.

4647 {
4648  if (!d) {
4649  qWarning("QImage::scaleHeight: Image is a null image");
4650  return QImage();
4651  }
4652  if (h <= 0)
4653  return QImage();
4654 
4655  qreal factor = (qreal) h / height();
4656  QTransform wm = QTransform::fromScale(factor, factor);
4657  return transformed(wm, mode);
4658 }
double qreal
Definition: qglobal.h:1193
QImageData * d
Definition: qimage.h:336
QImage()
Constructs a null image.
Definition: qimage.cpp:798
Q_CORE_EXPORT void qWarning(const char *,...)
QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const
Returns a copy of the image that is transformed using the given transformation matrix and transformat...
Definition: qimage.cpp:4698
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ scaledToWidth()

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

Returns a scaled copy of the image.

The returned image is scaled to the given width using the specified transformation mode.

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

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

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

Definition at line 4615 of file qimage.cpp.

4616 {
4617  if (!d) {
4618  qWarning("QImage::scaleWidth: Image is a null image");
4619  return QImage();
4620  }
4621  if (w <= 0)
4622  return QImage();
4623 
4624  qreal factor = (qreal) w / width();
4625  QTransform wm = QTransform::fromScale(factor, factor);
4626  return transformed(wm, mode);
4627 }
double qreal
Definition: qglobal.h:1193
QImageData * d
Definition: qimage.h:336
QImage()
Constructs a null image.
Definition: qimage.cpp:798
Q_CORE_EXPORT void qWarning(const char *,...)
QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const
Returns a copy of the image that is transformed using the given transformation matrix and transformat...
Definition: qimage.cpp:4698
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ 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 aligned on a 32-bit boundary.

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

Referenced by QPdfEnginePrivate::addImage(), QFontEngineMac::alphaMapForGlyph(), QFontEngineDirectWrite::alphaMapForGlyph(), QFontEngineXLFD::alphaMapForGlyph(), QFontEngineQPF::alphaMapForGlyph(), QFontEngine::alphaMapForGlyph(), QFontEngineQPF1::alphaMapForGlyph(), alphaMapFromPath(), QFontEngineWin::alphaRGBMapForGlyph(), QFontEngine::alphaRGBMapForGlyph(), blit180(), blit270(), blit90(), blit_template(), QWindowSurface::buffer(), QRasterBuffer::colorizeBitmap(), colorizeBitmap(), compressHelper(), convertWithPalette(), convolute(), copy(), create32BitCursor(), QX11PixmapData::createBitmapFromImage(), QDirectFBScreen::createDFBSurface(), createHeuristicMask(), createMaskFromColor(), QGIFFormat::disposePrevious(), QRasterPaintEngine::drawBitmap(), QMacStylePrivate::drawColorlessButton(), QPSPrintEnginePrivate::drawImage(), QGIFFormat::fillRect(), QGLTextureGlyphCache::fillTexture(), QImageTextureGlyphCache::fillTexture(), QXlibWindowSurface::flush(), QRasterWindowSurface::flush(), QRasterBuffer::flushToARGBImage(), QBitmap::fromData(), QX11PixmapData::fromImage(), QPixmap::fromWinHBITMAP(), QPixmap::fromWinHICON(), QCommonStyle::generatedIconPixmap(), QWindowSurface::grabWidget(), QVNCIntegration::grabWindow(), grayscale(), QFontEngineDirectWrite::imageForGlyph(), QPixmapData::mask(), mygetcanvasline(), operator==(), QColorLuminancePicker::paintEvent(), pixel(), pixelIndex(), qGamma_correct_back_to_linear_cs(), qgl_byteSwapImage(), QImageScale::qimageCalcScaleInfo(), QTestLiteStaticInfoPrivate::qimageFromXImage(), qSmoothScaleImage(), qstring_to_xtp(), qt_bitmapToRegion(), qt_blurrow(), qt_createIconMask(), qt_write_dib(), qt_write_dibv5(), qt_x11_drawImage(), QVNCDirtyMap::QVNCDirtyMap(), QTiffHandler::read(), ICOReader::read16_24_32BMP(), ICOReader::read1BitBMP(), ICOReader::read4BitBMP(), ICOReader::read8BitBMP(), read_pbm_body(), read_xbm_body(), read_xpm_body(), QColorPicker::resizeEvent(), rgbSwapped(), QVNCCursor::sendClientCursor(), QRasterPixmapData::setMask(), QPixmapData::setMask(), setPixel(), QCursor::setPos(), QX11PixmapData::takeQImageFromXImage(), QMacPixmapData::toImage(), QRasterPixmapData::toImage(), QX11PixmapData::toImage(), QPixmap::toWinHBITMAP(), QPixmap::toWinHICON(), QTiffHandler::write(), QVNCClientCursor::write(), QRfbRawEncoder::write(), QRfbHextileEncoder< SRC >::write(), write_pbm_image(), write_xbm_image(), and write_xpm_image().

1887 {
1888  if (!d)
1889  return 0;
1890 
1891  detach();
1892 
1893  // In case detach() ran out of memory
1894  if (!d)
1895  return 0;
1896 
1897  return d->data + i * d->bytes_per_line;
1898 }
QImageData * d
Definition: qimage.h:336
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
int bytes_per_line
Definition: qimage_p.h:86
uchar * data
Definition: qimage_p.h:81

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

1904 {
1905  if (!d)
1906  return 0;
1907 
1908  Q_ASSERT(i >= 0 && i < height());
1909  return d->data + i * d->bytes_per_line;
1910 }
QImageData * d
Definition: qimage.h:336
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int bytes_per_line
Definition: qimage_p.h:86
uchar * data
Definition: qimage_p.h:81
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

◆ serialNumber()

int QImage::serialNumber ( ) const

Returns a number that identifies the contents of this QImage object.

Use cacheKey() instead.

Warning
The serial number doesn't necessarily change when the image is altered. This means that it may be dangerous to use it as a cache key.
See also
operator==()

Definition at line 6267 of file qimage.cpp.

Referenced by QRasterPixmapData::createPixmapForImage(), QTextCursor::insertImage(), QRasterPixmapData::resize(), and QAhiScreenCursor::set().

6268 {
6269  if (!d)
6270  return 0;
6271  else
6272  return d->ser_no;
6273 }
QImageData * d
Definition: qimage.h:336
int ser_no
Definition: qimage_p.h:87

◆ setAlphaChannel()

void QImage::setAlphaChannel ( const QImage alphaChannel)

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

If alphaChannel is an 8 bit grayscale image, the intensity values are written into this buffer directly. Otherwise, alphaChannel is converted to 32 bit and the intensity of the RGB pixel values is used.

Note that the image will be converted to the Format_ARGB32_Premultiplied format if the function succeeds.

Use one of the composition modes in QPainter::CompositionMode instead.

Warning
This function is expensive.
See also
alphaChannel(), {QImage::Image Transformations}{Image Transformations}, {QImage::Image Formats}{Image Formats}

Definition at line 6329 of file qimage.cpp.

Referenced by QPixmapColorizeFilter::draw(), QFileSystemModel::headerData(), ICOReader::iconAt(), QRasterPixmapData::setAlphaChannel(), QX11PixmapData::setAlphaChannel(), QVolatileImage::setAlphaChannel(), and QPixmapData::setAlphaChannel().

6330 {
6331  if (!d)
6332  return;
6333 
6334  int w = d->width;
6335  int h = d->height;
6336 
6337  if (w != alphaChannel.d->width || h != alphaChannel.d->height) {
6338  qWarning("QImage::setAlphaChannel: "
6339  "Alpha channel must have same dimensions as the target image");
6340  return;
6341  }
6342 
6343  if (d->paintEngine && d->paintEngine->isActive()) {
6344  qWarning("QImage::setAlphaChannel: "
6345  "Unable to set alpha channel while image is being painted on");
6346  return;
6347  }
6348 
6350  detach();
6351  else
6353 
6354  if (isNull())
6355  return;
6356 
6357  // Slight optimization since alphachannels are returned as 8-bit grays.
6358  if (alphaChannel.d->depth == 8 && alphaChannel.isGrayscale()) {
6359  const uchar *src_data = alphaChannel.d->data;
6360  const uchar *dest_data = d->data;
6361  for (int y=0; y<h; ++y) {
6362  const uchar *src = src_data;
6363  QRgb *dest = (QRgb *)dest_data;
6364  for (int x=0; x<w; ++x) {
6365  int alpha = *src;
6366  int destAlpha = qt_div_255(alpha * qAlpha(*dest));
6367  *dest = ((destAlpha << 24)
6368  | (qt_div_255(qRed(*dest) * alpha) << 16)
6369  | (qt_div_255(qGreen(*dest) * alpha) << 8)
6370  | (qt_div_255(qBlue(*dest) * alpha)));
6371  ++dest;
6372  ++src;
6373  }
6374  src_data += alphaChannel.d->bytes_per_line;
6375  dest_data += d->bytes_per_line;
6376  }
6377 
6378  } else {
6379  const QImage sourceImage = alphaChannel.convertToFormat(QImage::Format_RGB32);
6380  if (sourceImage.isNull()) {
6381  qWarning("QImage::setAlphaChannel: out of memory");
6382  return;
6383  }
6384  const uchar *src_data = sourceImage.d->data;
6385  const uchar *dest_data = d->data;
6386  for (int y=0; y<h; ++y) {
6387  const QRgb *src = (const QRgb *) src_data;
6388  QRgb *dest = (QRgb *) dest_data;
6389  for (int x=0; x<w; ++x) {
6390  int alpha = qGray(*src);
6391  int destAlpha = qt_div_255(alpha * qAlpha(*dest));
6392  *dest = ((destAlpha << 24)
6393  | (qt_div_255(qRed(*dest) * alpha) << 16)
6394  | (qt_div_255(qGreen(*dest) * alpha) << 8)
6395  | (qt_div_255(qBlue(*dest) * alpha)));
6396  ++dest;
6397  ++src;
6398  }
6399  src_data += sourceImage.d->bytes_per_line;
6400  dest_data += d->bytes_per_line;
6401  }
6402  }
6403 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QImageData * d
Definition: qimage.h:336
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
unsigned char uchar
Definition: qglobal.h:994
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
int height
Definition: qimage_p.h:77
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
QPaintEngine * paintEngine
Definition: qimage_p.h:110
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
bool isGrayscale() const
For 32-bit images, this function is equivalent to allGray().
Definition: qimage.cpp:4477
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
int bytes_per_line
Definition: qimage_p.h:86
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
Definition: qrgb.h:75
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
Q_STATIC_INLINE_FUNCTION int qt_div_255(int x)
int depth
Definition: qimage_p.h:78

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

Referenced by alphaChannel(), QFontEngineQPF::alphaMapForGlyph(), QFontEngineQPF1::alphaMapForGlyph(), QX11PixmapData::createBitmapFromImage(), QWSCursor::createDropShadow(), createHeuristicMask(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsMobileStylePrivate::drawScrollbarGroove(), ensureValidImage(), QGLPixmapData::fillImage(), QBitmap::fromData(), QBitmap::fromImage(), QMacPixmapData::fromImage(), get_index(), makeBitmapCompliantIfNeeded(), QPixmapData::mask(), read_dib_body(), read_pbm_body(), read_xbm_body(), read_xpm_body(), ICOReader::readColorTable(), QRasterPixmapData::resize(), setup_qt(), QWindowsMobileStyle::standardPixmap(), QMotifStyle::standardPixmap(), QGtkStyle::standardPixmap(), swapPixel01(), QMacPixmapData::toImage(), and QX11PixmapData::toImage().

1851 {
1852  if (!d)
1853  return;
1854  if (i < 0 || d->depth > 8 || i >= 1<<d->depth) {
1855  qWarning("QImage::setColor: Index out of bound %d", i);
1856  return;
1857  }
1858  detach();
1859 
1860  // In case detach() run out of memory
1861  if (!d)
1862  return;
1863 
1864  if (i >= d->colortable.size())
1865  setColorCount(i+1);
1866  d->colortable[i] = c;
1867  d->has_alpha_clut |= (qAlpha(c) != 255);
1868 }
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
uint has_alpha_clut
Definition: qimage_p.h:96
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
Q_CORE_EXPORT void qWarning(const char *,...)
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
int depth
Definition: qimage_p.h:78
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ setColorCount()

void QImage::setColorCount ( int  colorCount)

Resizes the color table to contain colorCount entries.

Since
4.6

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

Referenced by alphaChannel(), createHeuristicMask(), ensureValidImage(), QGLPixmapData::fillImage(), QX11PixmapData::fromImage(), get_index(), ICOReader::iconAt(), QPixmapData::mask(), QImage(), read_dib_body(), read_pbm_body(), read_xbm_body(), read_xpm_body(), ICOReader::readColorTable(), QRasterPixmapData::resize(), setColor(), setNumColors(), setup_qt(), QMacPixmapData::toImage(), and QX11PixmapData::toImage().

2276 {
2277  if (!d) {
2278  qWarning("QImage::setColorCount: null image");
2279  return;
2280  }
2281 
2282  detach();
2283 
2284  // In case detach() ran out of memory
2285  if (!d)
2286  return;
2287 
2288  if (colorCount == d->colortable.size())
2289  return;
2290  if (colorCount <= 0) { // use no color table
2291  d->colortable = QVector<QRgb>();
2292  return;
2293  }
2294  int nc = d->colortable.size();
2296  for (int i = nc; i < colorCount; ++i)
2297  d->colortable[i] = 0;
2298 }
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
Q_CORE_EXPORT void qWarning(const char *,...)
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ setColorTable()

void QImage::setColorTable ( const QVector< QRgb colors)

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

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

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

Definition at line 1744 of file qimage.cpp.

Referenced by QProxyFontEngine::alphaMapForGlyph(), QFontEngineXLFD::alphaMapForGlyph(), QFontEngineBox::alphaMapForGlyph(), QGLPixmapDropShadowFilter::processGL(), and QTiffHandler::read().

1745 {
1746  if (!d)
1747  return;
1748  detach();
1749 
1750  // In case detach() ran out of memory
1751  if (!d)
1752  return;
1753 
1754  d->colortable = colors;
1755  d->has_alpha_clut = false;
1756  for (int i = 0; i < d->colortable.size(); ++i) {
1757  if (qAlpha(d->colortable.at(i)) != 255) {
1758  d->has_alpha_clut = true;
1759  break;
1760  }
1761  }
1762 }
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
uint has_alpha_clut
Definition: qimage_p.h:96
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

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

Referenced by convertToFormat(), qt_read_dibv5(), QTiffHandler::read(), read_dib_body(), QPngHandlerPrivate::readPngImage(), setImageMetrics(), and setPixel().

5646 {
5647  if (!d || !x)
5648  return;
5649  detach();
5650 
5651  if (d)
5652  d->dpmx = x;
5653 }
QImageData * d
Definition: qimage.h:336
qreal dpmx
Definition: qimage_p.h:90
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359

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

Referenced by convertToFormat(), qt_read_dibv5(), QTiffHandler::read(), read_dib_body(), QPngHandlerPrivate::readPngImage(), setImageMetrics(), and setPixel().

5668 {
5669  if (!d || !y)
5670  return;
5671  detach();
5672 
5673  if (d)
5674  d->dpmy = y;
5675 }
qreal dpmy
Definition: qimage_p.h:91
QImageData * d
Definition: qimage.h:336
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359

◆ setNumColors()

void QImage::setNumColors ( int  numColors)

Resizes the color table to contain numColors entries.

See also
setColorCount()

Definition at line 2252 of file qimage.cpp.

2253 {
2255 }
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
QT_DEPRECATED int numColors() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1636

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

Referenced by QPngHandlerPrivate::readPngImage().

5706 {
5707  if (!d)
5708  return;
5709  detach();
5710 
5711  if (d)
5712  d->offset = p;
5713 }
QImageData * d
Definition: qimage.h:336
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
QPoint offset
Definition: qimage_p.h:92

◆ setPixel() [1/2]

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

Sets the pixel index or color at (x, y) to 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.

Definition at line 4311 of file qimage.cpp.

Referenced by QGLGlyphCache::allocTexture(), QFontEngineBox::alphaMapForGlyph(), QRasterBuffer::bufferImage(), QWSCursor::createDropShadow(), darkenPixmap(), drawEllipse_midpoint_i(), QWindowsMobileStyle::generatedIconPixmap(), QMacStyle::generatedIconPixmap(), qt_patternForAlpha(), and QTgaFile::readImage().

4312 {
4313  if (!d || x < 0 || x >= width() || y < 0 || y >= height()) {
4314  qWarning("QImage::setPixel: coordinate (%d,%d) out of range", x, y);
4315  return;
4316  }
4317  // detach is called from within scanLine
4318  uchar * s = scanLine(y);
4319  if (!s) {
4320  qWarning("setPixel: Out of memory");
4321  return;
4322  }
4323  const quint32p p = quint32p::fromRawData(index_or_rgb);
4324  switch(d->format) {
4325  case Format_Mono:
4326  case Format_MonoLSB:
4327  if (index_or_rgb > 1) {
4328  qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);
4329  } else if (format() == Format_MonoLSB) {
4330  if (index_or_rgb==0)
4331  *(s + (x >> 3)) &= ~(1 << (x & 7));
4332  else
4333  *(s + (x >> 3)) |= (1 << (x & 7));
4334  } else {
4335  if (index_or_rgb==0)
4336  *(s + (x >> 3)) &= ~(1 << (7-(x & 7)));
4337  else
4338  *(s + (x >> 3)) |= (1 << (7-(x & 7)));
4339  }
4340  break;
4341  case Format_Indexed8:
4342  if (index_or_rgb >= (uint)d->colortable.size()) {
4343  qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);
4344  return;
4345  }
4346  s[x] = index_or_rgb;
4347  break;
4348  case Format_RGB32:
4349  //make sure alpha is 255, we depend on it in qdrawhelper for cases
4350  // when image is set as a texture pattern on a qbrush
4351  ((uint *)s)[x] = uint(255 << 24) | index_or_rgb;
4352  break;
4353  case Format_ARGB32:
4355  ((uint *)s)[x] = index_or_rgb;
4356  break;
4357  case Format_RGB16:
4358  ((quint16 *)s)[x] = qt_colorConvert<quint16, quint32p>(p, 0);
4359  break;
4361  ((qargb8565*)s)[x] = qt_colorConvert<qargb8565, quint32p>(p, 0);
4362  break;
4363  case Format_RGB666:
4364  ((qrgb666*)s)[x] = qt_colorConvert<qrgb666, quint32p>(p, 0);
4365  break;
4367  ((qargb6666*)s)[x] = qt_colorConvert<qargb6666, quint32p>(p, 0);
4368  break;
4369  case Format_RGB555:
4370  ((qrgb555*)s)[x] = qt_colorConvert<qrgb555, quint32p>(p, 0);
4371  break;
4373  ((qargb8555*)s)[x] = qt_colorConvert<qargb8555, quint32p>(p, 0);
4374  break;
4375  case Format_RGB888:
4376  ((qrgb888*)s)[x] = qt_colorConvert<qrgb888, quint32p>(p, 0);
4377  break;
4378  case Format_RGB444:
4379  ((qrgb444*)s)[x] = qt_colorConvert<qrgb444, quint32p>(p, 0);
4380  break;
4382  ((qargb4444*)s)[x] = qt_colorConvert<qargb4444, quint32p>(p, 0);
4383  break;
4384  case Format_Invalid:
4385  case NImageFormats:
4386  Q_ASSERT(false);
4387  }
4388 }
QImageData * d
Definition: qimage.h:336
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
unsigned char uchar
Definition: qglobal.h:994
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
Q_STATIC_INLINE_FUNCTION quint32p fromRawData(quint32 v)
QImage::Format format
Definition: qimage_p.h:85
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ setPixel() [2/2]

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

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

If the image's format is either monochrome or 8-bit, 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 8-bit 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 QImage::scanLine() to access pixel data directly.
See also
pixel(), {QImage::Pixel Manipulation}{Pixel Manipulation}

Definition at line 357 of file qimage.h.

357 { setPixel(pt.x(), pt.y(), index_or_rgb); }
void setPixel(int x, int y, uint index_or_rgb)
Sets the pixel index or color at (x, y) to index_or_rgb.
Definition: qimage.cpp:4311

◆ setText() [1/2]

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

Referenced by QPngHandlerPrivate::readPngImage().

5781 {
5782  if (!d)
5783  return;
5784  detach();
5785 
5786  if (d)
5787  d->text.insert(key, value);
5788 }
QImageData * d
Definition: qimage.h:336
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QMap< QString, QString > text
Definition: qimage_p.h:106

◆ setText() [2/2]

void QImage::setText ( const char *  key,
const char *  language,
const QString text 
)

Sets the image text to the given text and associate it with the given key. The text is recorded in the specified language, or in a default language if language is 0.

Use setText() instead.

The language the text is recorded in is no longer relevant since the text is always set using QString and UTF-8 representation.

Warning
This function is not part of the public interface. Records string for the keyword key. The key should be a portable keyword recognizable by other software - some suggested values can be found in the PNG specification. s can be any text. lang should specify the language code (see RFC 1766) or 0.

Definition at line 5920 of file qimage.cpp.

5921 {
5922  if (!d)
5923  return;
5924  detach();
5925 
5926  // In case detach() ran out of memory
5927  if (!d)
5928  return;
5929 
5931  if (lang && *lang)
5932  k += QLatin1Char('/') + QString::fromAscii(lang);
5933  d->text.insert(k, s);
5934 }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
The QString class provides a Unicode character string.
Definition: qstring.h:83
QImageData * d
Definition: qimage.h:336
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
int key
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QMap< QString, QString > text
Definition: qimage_p.h:106

◆ size()

QSize QImage::size ( ) const

Returns the size of the image, i.

e. its width() and height().

\sa {QImage#Image Information}{Image Information}

Definition at line 1587 of file qimage.cpp.

Referenced by blendCursor(), QTransformedScreen::blit(), QScreen::blit(), QWindowSurface::buffer(), colorizeBitmap(), QPaintBuffer::commandDescription(), convertWithPalette(), createMaskFromColor(), QGLPixmapData::createPixmapForImage(), QPixmapColorizeFilter::draw(), QDirectFBPaintEngine::drawImage(), QBlitterPaintEngine::drawImage(), QGL2PaintEngineEx::drawImage(), QVGPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QPaintEngineEx::drawImage(), QPaintBufferEngine::drawImage(), QCleanlooksStyle::drawPrimitive(), ensureValidImage(), QWindowSurface::grabWidget(), grayscale(), QStyledItemDelegate::initStyleOption(), QGLPixmapData::paintEngine(), QGLPixmapDropShadowFilter::processGL(), QImage(), qt_read_dibv5(), QTiffHandler::read(), read_dib_body(), read_pbm_body(), read_xbm_body(), read_xpm_body(), readImage(), QMinimalWindowSurface::resize(), QFbWindowSurface::resize(), scaled(), QVNCCursor::sendClientCursor(), QProxyScreenCursor::set(), QScreenCursor::set(), QDirectFBScreenCursor::set(), QWSLocalMemSurface::setGeometry(), QWSSharedMemSurface::setGeometry(), setup_qt(), QWaylandShmBuffer::size(), toVGImageWithOpacity(), QGL2PaintEngineExPrivate::updateBrushTexture(), and QVNCClientCursor::write().

1588 {
1589  return d ? QSize(d->width, d->height) : QSize(0, 0);
1590 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336
int height
Definition: qimage_p.h:77
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ swap()

void QImage::swap ( QImage other)
inline

Swaps image other with this image.

Since
4.8

This operation is very fast and never fails.

Definition at line 147 of file qimage.h.

147 { qSwap(d, other.d); }
QImageData * d
Definition: qimage.h:336
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181

◆ text() [1/3]

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

Referenced by convertWithPalette(), and set_text().

5737 {
5738  if (!d)
5739  return QString();
5740 
5741  if (!key.isEmpty())
5742  return d->text.value(key);
5743 
5744  QString tmp;
5745  foreach (const QString &key, d->text.keys()) {
5746  if (!tmp.isEmpty())
5747  tmp += QLatin1String("\n\n");
5748  tmp += key + QLatin1String(": ") + d->text.value(key).simplified();
5749  }
5750  return tmp;
5751 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QImageData * d
Definition: qimage.h:336
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
QMap< QString, QString > text
Definition: qimage_p.h:106

◆ text() [2/3]

QString QImage::text ( const char *  key,
const char *  language = 0 
) const

Returns the text recorded for the given key in the given language, or in a default language if language is 0.

Use text() instead.

The language the text is recorded in is no longer relevant since the text is always set using QString and UTF-8 representation.

Definition at line 5802 of file qimage.cpp.

5803 {
5804  if (!d)
5805  return QString();
5807  if (lang && *lang)
5808  k += QLatin1Char('/') + QString::fromAscii(lang);
5809  return d->text.value(k);
5810 }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
The QString class provides a Unicode character string.
Definition: qstring.h:83
QImageData * d
Definition: qimage.h:336
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
int key
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QMap< QString, QString > text
Definition: qimage_p.h:106

◆ text() [3/3]

QString QImage::text ( const QImageTextKeyLang keywordAndLanguage) const

Returns the text recorded for the given keywordAndLanguage.

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

Use text() instead.

The language the text is recorded in is no longer relevant since the text is always set using QString and UTF-8 representation.

Definition at line 5827 of file qimage.cpp.

5828 {
5829  if (!d)
5830  return QString();
5831  QString k = QString::fromAscii(kl.key);
5832  if (!kl.lang.isEmpty())
5833  k += QLatin1Char('/') + QString::fromAscii(kl.lang);
5834  return d->text.value(k);
5835 }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
The QString class provides a Unicode character string.
Definition: qstring.h:83
QImageData * d
Definition: qimage.h:336
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QMap< QString, QString > text
Definition: qimage_p.h:106

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

Referenced by set_text(), textLanguages(), and textList().

5725 {
5726  return d ? QStringList(d->text.keys()) : QStringList();
5727 }
QImageData * d
Definition: qimage.h:336
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
QMap< QString, QString > text
Definition: qimage_p.h:106

◆ textLanguages()

QStringList QImage::textLanguages ( ) const

Returns the language identifiers for which some texts are recorded.

Note that if you want to iterate over the list, you should iterate over a copy.

The language the text is recorded in is no longer relevant since the text is always set using QString and UTF-8 representation.

Definition at line 5850 of file qimage.cpp.

5851 {
5852  if (!d)
5853  return QStringList();
5855  QStringList languages;
5856  for (int i = 0; i < keys.size(); ++i) {
5857  int index = keys.at(i).indexOf(QLatin1Char('/'));
5858  if (index > 0)
5859  languages += keys.at(i).mid(index+1);
5860  }
5861 
5862  return languages;
5863 }
QImageData * d
Definition: qimage.h:336
QStringList keys
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QStringList textKeys() const
Returns the text keys for this image.
Definition: qimage.cpp:5724

◆ textList()

QList< QImageTextKeyLang > QImage::textList ( ) const

Returns a list of QImageTextKeyLang objects that enumerate all the texts key/language pairs set for this image.

Use textKeys() instead.

The language the text is recorded in is no longer relevant since the text is always set using QString and UTF-8 representation.

Definition at line 5879 of file qimage.cpp.

5880 {
5881  QList<QImageTextKeyLang> imageTextKeys;
5882  if (!d)
5883  return imageTextKeys;
5885  for (int i = 0; i < keys.size(); ++i) {
5886  int index = keys.at(i).indexOf(QLatin1Char('/'));
5887  if (index > 0) {
5888  QImageTextKeyLang tkl;
5889  tkl.key = keys.at(i).left(index).toAscii();
5890  tkl.lang = keys.at(i).mid(index+1).toAscii();
5891  imageTextKeys += tkl;
5892  }
5893  }
5894 
5895  return imageTextKeys;
5896 }
QImageData * d
Definition: qimage.h:336
QStringList keys
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QByteArray lang
Definition: qimage.h:75
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
quint16 index
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QStringList textKeys() const
Returns the text keys for this image.
Definition: qimage.cpp:5724
QByteArray key
Definition: qimage.h:74
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ transformed() [1/2]

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

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

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

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

Definition at line 4698 of file qimage.cpp.

Referenced by QFontEngine::alphaMapForGlyph(), QFontEngineMac::alphaRGBMapForGlyph(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QTiffHandler::read(), scaled(), scaledToHeight(), scaledToWidth(), QDirectFBPixmapData::transformed(), and QX11PixmapData::transformed().

4699 {
4700  return transformed(QTransform(matrix), mode);
4701 }
QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const
Returns a copy of the image that is transformed using the given transformation matrix and transformat...
Definition: qimage.cpp:4698
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ transformed() [2/2]

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

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

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

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

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

Definition at line 6757 of file qimage.cpp.

6758 {
6759  if (!d)
6760  return QImage();
6761 
6762  // source image data
6763  int ws = width();
6764  int hs = height();
6765 
6766  // target image data
6767  int wd;
6768  int hd;
6769 
6770  // compute size of target image
6771  QTransform mat = trueMatrix(matrix, ws, hs);
6772  bool complex_xform = false;
6773  bool scale_xform = false;
6774  if (mat.type() <= QTransform::TxScale) {
6775  if (mat.type() == QTransform::TxNone) // identity matrix
6776  return *this;
6777  else if (mat.m11() == -1. && mat.m22() == -1.)
6778  return rotated180(*this);
6779 
6780  if (mode == Qt::FastTransformation) {
6781  hd = qRound(qAbs(mat.m22()) * hs);
6782  wd = qRound(qAbs(mat.m11()) * ws);
6783  } else {
6784  hd = int(qAbs(mat.m22()) * hs + 0.9999);
6785  wd = int(qAbs(mat.m11()) * ws + 0.9999);
6786  }
6787  scale_xform = true;
6788  } else {
6789  if (mat.type() <= QTransform::TxRotate && mat.m11() == 0 && mat.m22() == 0) {
6790  if (mat.m12() == 1. && mat.m21() == -1.)
6791  return rotated90(*this);
6792  else if (mat.m12() == -1. && mat.m21() == 1.)
6793  return rotated270(*this);
6794  }
6795 
6796  QPolygonF a(QRectF(0, 0, ws, hs));
6797  a = mat.map(a);
6798  QRect r = a.boundingRect().toAlignedRect();
6799  wd = r.width();
6800  hd = r.height();
6801  complex_xform = true;
6802  }
6803 
6804  if (wd == 0 || hd == 0)
6805  return QImage();
6806 
6807  // Make use of the optimized algorithm when we're scaling
6808  if (scale_xform && mode == Qt::SmoothTransformation) {
6809  if (mat.m11() < 0.0F && mat.m22() < 0.0F) { // horizontal/vertical flip
6810  return smoothScaled(mirrored(true, true), wd, hd);
6811  } else if (mat.m11() < 0.0F) { // horizontal flip
6812  return smoothScaled(mirrored(true, false), wd, hd);
6813  } else if (mat.m22() < 0.0F) { // vertical flip
6814  return smoothScaled(mirrored(false, true), wd, hd);
6815  } else { // no flipping
6816  return smoothScaled(*this, wd, hd);
6817  }
6818  }
6819 
6820  int bpp = depth();
6821 
6822  int sbpl = bytesPerLine();
6823  const uchar *sptr = bits();
6824 
6825  QImage::Format target_format = d->format;
6826 
6827  if (complex_xform || mode == Qt::SmoothTransformation) {
6829  switch(d->format) {
6830  case QImage::Format_RGB16:
6831  target_format = Format_ARGB8565_Premultiplied;
6832  break;
6833  case QImage::Format_RGB555:
6834  target_format = Format_ARGB8555_Premultiplied;
6835  break;
6836  case QImage::Format_RGB666:
6837  target_format = Format_ARGB6666_Premultiplied;
6838  break;
6839  case QImage::Format_RGB444:
6840  target_format = Format_ARGB4444_Premultiplied;
6841  break;
6842  default:
6843  target_format = Format_ARGB32_Premultiplied;
6844  break;
6845  }
6846  }
6847  }
6848 
6849  QImage dImage(wd, hd, target_format);
6850  QIMAGE_SANITYCHECK_MEMORY(dImage);
6851 
6852  if (target_format == QImage::Format_MonoLSB
6853  || target_format == QImage::Format_Mono
6854  || target_format == QImage::Format_Indexed8) {
6855  dImage.d->colortable = d->colortable;
6856  dImage.d->has_alpha_clut = d->has_alpha_clut | complex_xform;
6857  }
6858 
6859  dImage.d->dpmx = dotsPerMeterX();
6860  dImage.d->dpmy = dotsPerMeterY();
6861 
6862  switch (bpp) {
6863  // initizialize the data
6864  case 8:
6865  if (dImage.d->colortable.size() < 256) {
6866  // colors are left in the color table, so pick that one as transparent
6867  dImage.d->colortable.append(0x0);
6868  memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.byteCount());
6869  } else {
6870  memset(dImage.bits(), 0, dImage.byteCount());
6871  }
6872  break;
6873  case 1:
6874  case 16:
6875  case 24:
6876  case 32:
6877  memset(dImage.bits(), 0x00, dImage.byteCount());
6878  break;
6879  }
6880 
6881  if (target_format >= QImage::Format_RGB32) {
6882  QPainter p(&dImage);
6883  if (mode == Qt::SmoothTransformation) {
6884  p.setRenderHint(QPainter::Antialiasing);
6885  p.setRenderHint(QPainter::SmoothPixmapTransform);
6886  }
6887  p.setTransform(mat);
6888  p.drawImage(QPoint(0, 0), *this);
6889  } else {
6890  bool invertible;
6891  mat = mat.inverted(&invertible); // invert matrix
6892  if (!invertible) // error, return null image
6893  return QImage();
6894 
6895  // create target image (some of the code is from QImage::copy())
6897  int dbpl = dImage.bytesPerLine();
6898  qt_xForm_helper(mat, 0, type, bpp, dImage.bits(), dbpl, 0, hd, sptr, sbpl, ws, hs);
6899  }
6900  return dImage;
6901 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
Format
The following image formats are available in Qt.
Definition: qimage.h:91
int type
Definition: qmetatype.cpp:239
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
static QImage rotated180(const QImage &src)
Definition: qimage.cpp:6681
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
uint has_alpha_clut
Definition: qimage_p.h:96
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
long ASN1_INTEGER_get ASN1_INTEGER * a
int dotsPerMeterY() const
Returns the number of pixels that fit vertically in a physical meter.
Definition: qimage.cpp:5628
QVectorData * d
Definition: qvector.h:109
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QImageData * d
Definition: qimage.h:336
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
QVector< QRgb > colortable
Definition: qimage_p.h:80
TransformationType type() const
Returns the transformation type of this matrix.
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
QImage()
Constructs a null image.
Definition: qimage.cpp:798
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
unsigned char uchar
Definition: qglobal.h:994
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
#define QT_XFORM_TYPE_MSBFIRST
static QImage rotated90(const QImage &src)
Definition: qimage.cpp:6626
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
QImage mirrored(bool horizontally=false, bool vertically=true) const
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on ...
Definition: qimage.cpp:4922
#define QT_XFORM_TYPE_LSBFIRST
static QImage rotated270(const QImage &src)
Definition: qimage.cpp:6686
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage::Format format
Definition: qimage_p.h:85
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
static QImage smoothScaled(const QImage &source, int w, int h)
Definition: qimage.cpp:6611
bool qt_xForm_helper(const QTransform &trueMat, int xoffset, int type, int depth, uchar *dptr, int dbpl, int p_inc, int dHeight, const uchar *sptr, int sbpl, int sWidth, int sHeight)
Definition: qimage.cpp:6100
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105
int dotsPerMeterX() const
Returns the number of pixels that fit horizontally in a physical meter.
Definition: qimage.cpp:5615
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
static QMatrix trueMatrix(const QMatrix &, int w, int h)
Returns the actual matrix used for transforming an image with the given width, height and matrix...
Definition: qimage.cpp:4680
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ trueMatrix() [1/2]

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

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

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

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

Definition at line 4680 of file qimage.cpp.

Referenced by transformed(), and QPixmap::trueMatrix().

4681 {
4682  return trueMatrix(QTransform(matrix), w, h).toAffine();
4683 }
static QMatrix trueMatrix(const QMatrix &, int w, int h)
Returns the actual matrix used for transforming an image with the given width, height and matrix...
Definition: qimage.cpp:4680
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ trueMatrix() [2/2]

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

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

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

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

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

Definition at line 6927 of file qimage.cpp.

6928 {
6929  const QRectF rect(0, 0, w, h);
6930  const QRect mapped = matrix.mapRect(rect).toAlignedRect();
6931  const QPoint delta = mapped.topLeft();
6932  return matrix * QTransform().translate(-delta.x(), -delta.y());
6933 }
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
Definition: qimage.cpp:1603
QFuture< T > mapped(const Sequence &sequence, MapFunction function)
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ valid() [1/2]

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

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

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

4166 {
4167  return d
4168  && x >= 0 && x < d->width
4169  && y >= 0 && y < d->height;
4170 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336
int height
Definition: qimage_p.h:77

◆ valid() [2/2]

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

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

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

Definition at line 354 of file qimage.h.

354 { return valid(pt.x(), pt.y()); }
bool valid(int x, int y) const
Returns true if QPoint(x, y) is a valid coordinate pair within the image; otherwise returns false...
Definition: qimage.cpp:4165

◆ width()

int QImage::width ( ) const

Returns the width of the image.

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

Definition at line 1557 of file qimage.cpp.

Referenced by QFontEngine::addBitmapFontToPath(), QPdfEnginePrivate::addBrushPattern(), QPdfEnginePrivate::addImage(), QFontEngineXLFD::addOutlineToPath(), allGray(), QAlphaWidget::alphaBlend(), QFontEngineMac::alphaMapForGlyph(), QFontEngineDirectWrite::alphaMapForGlyph(), QFontEngineXLFD::alphaMapForGlyph(), QFontEngine::alphaMapForGlyph(), alphaMapFromPath(), QFontEngine::alphaRGBMapForGlyph(), QX11PixmapData::bitmapFromImage(), QAhiScreen::blit(), QGLGlyphCache::cacheGlyphs(), QProxyFontEngine::canRender(), checkForAlphaPixels(), colorizeBitmap(), compressHelper(), convert_indexed8_to_ARGB_PM_inplace(), convert_indexed8_to_RGB16_inplace(), convert_indexed8_to_RGB_inplace(), QMacPasteboardMimeTiff::convertFromMime(), convertWithPalette(), convolute(), QImageData::create(), create32BitCursor(), QX11PixmapData::createBitmapFromImage(), QDirectFBScreen::createDFBSurface(), createHeuristicMask(), QVGPixmapData::createPixmapForImage(), QGLPixmapData::createPixmapForImage(), darkenPixmap(), QGIFFormat::decode(), QRasterPaintEngine::drawBitmap(), QCleanlooksStyle::drawComplexControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QVGCompositionHelper::drawCursorPixmap(), QPdfEngine::drawImage(), QCoreGraphicsPaintEngine::drawImage(), QPSPrintEnginePrivate::drawImage(), QGL2PaintEngineEx::drawImage(), QOpenGLPaintEngine::drawImage(), QVGPaintEngine::drawImage(), QPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QRasterPaintEnginePrivate::drawImage(), QPainter::drawImage(), QPSPrintEnginePrivate::drawImageHelper(), QPSPrintEngine::drawImageInternal(), drawImageTiled(), QWindowsMobileStylePrivate::drawPanelItemViewSelected(), QPdfEngine::drawPixmap(), QPlastiqueStyle::drawPrimitive(), QRasterPaintEngine::drawTextItem(), QOpenGLPaintEngine::drawTiledPixmap(), expblur(), QRasterPixmapData::fill(), QGLTextureGlyphCache::fillTexture(), QImageTextureGlyphCache::fillTexture(), QXlibWindowSurface::flush(), QRasterBuffer::flushToARGBImage(), QVGFontEngineCleaner::fontEngineDestroyed(), format(), QBlittablePixmapData::fromImage(), QDirectFBPixmapData::fromImage(), QMacPixmapData::fromImage(), QX11PixmapData::fromImage(), QWindowsMobileStyle::generatedIconPixmap(), QCommonStyle::generatedIconPixmap(), QMacStyle::generatedIconPixmap(), getImageSize(), QVNCIntegration::grabWindow(), grayscale(), ICOReader::iconAt(), QFontEngineMac::imageForGlyph(), QMeeGoPixmapData::imageToEGLSharedImage(), QFontEngineQPF::loadGlyph(), QPixmapData::mask(), mirrored(), operator==(), QWSLocalMemSurface::permanentState(), QWSSharedMemSurface::permanentState(), QRasterBuffer::prepare(), QRasterWindowSurface::prepareBuffer(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), qGamma_correct_back_to_linear_cs(), qgl_byteSwapImage(), QImageScale::qimageCalcScaleInfo(), QTestLiteStaticInfoPrivate::qimageFromXImage(), QMacCGContext::QMacCGContext(), qSmoothScaleImage(), qstring_to_xtp(), QSvgImage::QSvgImage(), qt_bitmapToRegion(), qt_blurImage(), qt_blurrow(), qt_createIconMask(), qt_halfScaled(), qt_mac_cg_context(), qt_mac_createCGImageFromQImage(), qt_mac_image_to_cgimage(), qt_scrollRectInImage(), qt_write_dib(), qt_write_dibv5(), rotate_right_mirror_horizontal(), rotate_right_mirror_vertical(), rotated270(), rotated90(), scaled(), scaledToWidth(), QItemDelegate::selected(), QVNCCursor::sendClientCursor(), QAhiScreenCursor::set(), QRasterPixmapData::setMask(), QPixmapData::setMask(), setPixel(), QMacStyle::styleHint(), QX11PixmapData::takeQImageFromXImage(), toVGImage(), QPixmap::toWinHBITMAP(), transformed(), QMeeGoPixmapData::updateFromSoftImage(), QVolatileImage::width(), QNativeImage::width(), QTiffHandler::write(), QBmpHandler::write(), QVNCClientCursor::write(), ICOReader::write(), write_jpeg_image(), write_pbm_image(), write_xbm_image(), write_xpm_image(), QMngHandlerPrivate::writeImage(), QPNGImageWriter::writeImage(), and QTextOdfWriter::writeInlineCharacter().

1558 {
1559  return d ? d->width : 0;
1560 }
int width
Definition: qimage_p.h:76
QImageData * d
Definition: qimage.h:336

Friends and Related Functions

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

Definition at line 5406 of file qimage.cpp.

5407 {
5408  if (s.version() >= 5) {
5409  if (image.isNull()) {
5410  s << (qint32) 0; // null image marker
5411  return s;
5412  } else {
5413  s << (qint32) 1;
5414  // continue ...
5415  }
5416  }
5417  QImageWriter writer(s.device(), s.version() == 1 ? "bmp" : "png");
5418  writer.write(image);
5419  return s;
5420 }
int qint32
Definition: qglobal.h:937
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QImageWriter class provides a format independent interface for writing images to files or other d...
Definition: qimagewriter.h:59
bool write(const QImage &image)
Writes the image image to the assigned device or file name.

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

Definition at line 5435 of file qimage.cpp.

5436 {
5437  if (s.version() >= 5) {
5438  qint32 nullMarker;
5439  s >> nullMarker;
5440  if (!nullMarker) {
5441  image = QImage(); // null image
5442  return s;
5443  }
5444  }
5445  image = QImageReader(s.device(), 0).read();
5446  return s;
5447 }
int qint32
Definition: qglobal.h:937
QImage()
Constructs a null image.
Definition: qimage.cpp:798
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62

◆ QBlittablePixmapData

friend class QBlittablePixmapData
friend

Definition at line 339 of file qimage.h.

◆ QPixmapCacheEntry

friend class QPixmapCacheEntry
friend

Definition at line 340 of file qimage.h.

◆ QRasterPixmapData

friend class QRasterPixmapData
friend

Definition at line 338 of file qimage.h.

◆ qt_image_colortable

const QVector<QRgb>* qt_image_colortable ( const QImage image)
friend

Definition at line 122 of file qimage.cpp.

123 {
124  return &image.d->colortable;
125 }
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80

◆ qt_image_id

Q_GUI_EXPORT qint64 qt_image_id ( const QImage image)
friend

Definition at line 117 of file qimage.cpp.

118 {
119  return image.cacheKey();
120 }
qint64 cacheKey() const
Returns a number that identifies the contents of this QImage object.
Definition: qimage.cpp:6282

◆ QWSOnScreenSurface

friend class QWSOnScreenSurface
friend

Definition at line 335 of file qimage.h.

Properties

◆ d

QImageData* QImage::d
private

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