CopperSpice API
1.9.2
|
Represents a bit map image. More...
Public Types | |
enum | Format |
enum | InvertMode |
Public Types inherited from QPaintDevice | |
enum | PaintDeviceMetric |
Public Methods | |
QImage () | |
QImage (const char *const xpm[]) | |
QImage (const QImage &other) | |
QImage (const QSize &size, Format format) | |
QImage (const QString &fileName, const QString &format=QString ()) | |
QImage (const uchar *data, int width, int height, Format format, QImageCleanupFunction cleanupFunction=nullptr, void *cleanupInfo=nullptr) | |
QImage (const uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction=nullptr, void *cleanupInfo=nullptr) | |
QImage (int width, int height, Format format) | |
QImage (QImage &&other) | |
QImage (uchar *data, int width, int height, Format format, QImageCleanupFunction cleanupFunction=nullptr, void *cleanupInfo=nullptr) | |
QImage (uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction=nullptr, void *cleanupInfo=nullptr) | |
~QImage () | |
bool | allGray () const |
QImage | alphaChannel () const |
int | bitPlaneCount () const |
uchar * | bits () |
const uchar * | bits () const |
int | byteCount () const |
int | bytesPerLine () const |
qint64 | cacheKey () const |
QRgb | color (int index) const |
int | colorCount () const |
QVector< QRgb > | colorTable () const |
const uchar * | constBits () const |
const uchar * | constScanLine (int index) const |
QImage | convertToFormat (Format format, const QVector< QRgb > &colorTable, Qt::ImageConversionFlags flags=Qt::AutoColor) const |
QImage | convertToFormat (Format format, Qt::ImageConversionFlags flags=Qt::AutoColor) && |
QImage | convertToFormat (Format format, Qt::ImageConversionFlags flags=Qt::AutoColor) const & |
QImage | copy (const QRect &rect=QRect ()) const |
QImage | copy (int x, int y, int width, int height) const |
QImage | createAlphaMask (Qt::ImageConversionFlags flags=Qt::AutoColor) const |
QImage | createHeuristicMask (bool clipTight=true) const |
QImage | createMaskFromColor (QRgb color, Qt::MaskMode mode=Qt::MaskInColor) const |
int | depth () const |
qreal | devicePixelRatio () const |
int | dotsPerMeterX () const |
int | dotsPerMeterY () const |
void | fill (const QColor &color) |
void | fill (Qt::GlobalColor color) |
void | fill (uint pixelValue) |
Format | format () const |
bool | hasAlphaChannel () const |
int | height () const |
void | invertPixels (InvertMode mode=InvertRgb) |
bool | isGrayscale () const |
bool | isNull () const |
bool | load (const QString &fileName, const QString &format=QString ()) |
bool | load (QIODevice *device, const QString &format) |
bool | loadFromData (const QByteArray &data, const QString &format=QString ()) |
bool | loadFromData (const uchar *buffer, int len, const QString &format=QString ()) |
QImage && | mirrored (bool horizontal=false, bool vertical=true) && |
QImage | mirrored (bool horizontal=false, bool vertical=true) const & |
QPoint | offset () const |
operator QVariant () const | |
bool | operator!= (const QImage &other) const |
QImage & | operator= (const QImage &other) |
QImage & | operator= (QImage &&other) |
bool | operator== (const QImage &other) const |
QPaintEngine * | paintEngine () const override |
QRgb | pixel (const QPoint &pos) const |
QRgb | pixel (int x, int y) const |
QColor | pixelColor (const QPoint &pos) const |
QColor | pixelColor (int x, int y) const |
QPixelFormat | pixelFormat () const |
int | pixelIndex (const QPoint &pos) const |
int | pixelIndex (int x, int y) const |
QRect | rect () const |
QImage && | rgbSwapped () && |
QImage | rgbSwapped () const & |
bool | save (const QString &fileName, const QString &format=QString (), int quality=-1) const |
bool | save (QIODevice *device, const QString &format=QString (), int quality=-1) const |
QImage | scaled (const QSize &size, Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const |
QImage | scaled (int width, int height, Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const |
QImage | scaledToHeight (int height, Qt::TransformationMode mode=Qt::FastTransformation) const |
QImage | scaledToWidth (int width, Qt::TransformationMode mode=Qt::FastTransformation) const |
uchar * | scanLine (int index) |
const uchar * | scanLine (int index) const |
int | serialNumber () const |
void | setAlphaChannel (const QImage &alphaChannel) |
void | setColor (int index, QRgb colorValue) |
void | setColorCount (int colorCount) |
void | setColorTable (const QVector< QRgb > &colors) |
void | setDevicePixelRatio (qreal scaleFactor) |
void | setDotsPerMeterX (int x) |
void | setDotsPerMeterY (int y) |
void | setOffset (const QPoint &offset) |
void | setPixel (const QPoint &pos, uint index_or_rgb) |
void | setPixel (int x, int y, uint index_or_rgb) |
void | setPixelColor (const QPoint &pos, const QColor &color) |
void | setPixelColor (int x, int y, const QColor &color) |
void | setText (const QString &key, const QString &text) |
QSize | size () const |
void | swap (QImage &other) |
QString | text (const QString &key=QString ()) const |
QStringList | textKeys () const |
QImage | transformed (const QMatrix &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const |
QImage | transformed (const QTransform &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const |
bool | valid (const QPoint &pos) const |
bool | valid (int x, int y) const |
int | width () const |
Public Methods inherited from QPaintDevice | |
virtual | ~QPaintDevice () |
int | colorCount () const |
int | depth () const |
int | devicePixelRatio () const |
qreal | devicePixelRatioF () const |
int | height () const |
int | heightMM () const |
int | logicalDpiX () const |
int | logicalDpiY () const |
bool | paintingActive () const |
int | physicalDpiX () const |
int | physicalDpiY () const |
int | width () const |
int | widthMM () const |
Static Public Methods | |
static QImage | fromData (const QByteArray &data, const QString &format=QString ()) |
static QImage | fromData (const uchar *data, int size, const QString &format=QString ()) |
static QImage::Format | toImageFormat (QPixelFormat format) |
static QPixelFormat | toPixelFormat (QImage::Format format) |
static QMatrix | trueMatrix (const QMatrix &matrix, int width, int height) |
static QTransform | trueMatrix (const QTransform &matrix, int width, int height) |
Protected Methods | |
int | metric (PaintDeviceMetric metric) const override |
QImage | smoothScaled (int width, int height) const |
Protected Methods inherited from QPaintDevice | |
QPaintDevice () | |
Friends | |
class | QBackingStore |
Related Functions | |
These are not member functions | |
QDataStream & | operator<< (QDataStream &stream, const QImage &image) |
QDataStream & | operator>> (QDataStream &stream, QImage &image) |
The QImage class represents a hardware independent representation of a bit map image. The image allows direct access to the pixel data and can be used as a paint device.
CopperSpice 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 inherits from QPixmap, ensuring a depth of 1. The QPicture class is a paint device which 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.
QImage provides a collection of functions which 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. QImage objects can also be streamed and compared.
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. Refer to the 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, CopperSpice supports the following formats:
Format | Description | CopperSpice 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 |
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 independent 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. |
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 refer to Image Formats. 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. |
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, refer to the Image Formats.
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.
32-bit | |
---|---|
QImage image(3, 3, QImage::Format_RGB32);
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 monochrome 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.
8-bit | |
---|---|
QImage image(3, 3, QImage::Format_Indexed8);
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)
).
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. 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.
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. |
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:
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.
enum QImage::Format |
The following image formats are available in CopperSpice.
Constant | Value | Description |
---|---|---|
QImage::Format_Invalid | 0 | The image is invalid. |
QImage::Format_Mono | 1 | The image is stored using 1-bit per pixel. Bytes are packed with the most significant bit (MSB) first. |
QImage::Format_MonoLSB | 2 | The image is stored using 1-bit per pixel. Bytes are packed with the less significant bit (LSB) first. |
QImage::Format_Indexed8 | 3 | The image is stored using 8-bit indexes into a colormap. |
QImage::Format_RGB32 | 4 | The image is stored using a 32-bit RGB format (0xffRRGGBB). |
QImage::Format_ARGB32 | 5 | The image is stored using a 32-bit ARGB format (0xAARRGGBB). |
QImage::Format_ARGB32_Premultiplied | 6 | 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. |
QImage::Format_RGB16 | 7 | The image is stored using a 16-bit RGB format (5-6-5). |
QImage::Format_ARGB8565_Premultiplied | 8 | The image is stored using a premultiplied 24-bit ARGB format (8-5-6-5). |
QImage::Format_RGB666 | 9 | The image is stored using a 24-bit RGB format (6-6-6). The unused most significant bits is always zero. |
QImage::Format_ARGB6666_Premultiplied | 10 | The image is stored using a premultiplied 24-bit ARGB format (6-6-6-6). |
QImage::Format_RGB555 | 11 | The image is stored using a 16-bit RGB format (5-5-5). The unused most significant bit is always zero. |
QImage::Format_ARGB8555_Premultiplied | 12 | The image is stored using a premultiplied 24-bit ARGB format (8-5-5-5). |
QImage::Format_RGB888 | 13 | The image is stored using a 24-bit RGB format (8-8-8). |
QImage::Format_RGB444 | 14 | The image is stored using a 16-bit RGB format (4-4-4). The unused bits are always zero. |
QImage::Format_ARGB4444_Premultiplied | 15 | The image is stored using a premultiplied 16-bit ARGB format (4-4-4-4). |
QImage::Format_RGBX8888 | 16 | The image is stored using a 32-bit byte-ordered RGB(x) format (8-8-8-8). This is the same as the Format_RGBA8888 except alpha must always be 255. |
QImage::Format_RGBA8888 | 17 | The image is stored using a 32-bit byte-ordered RGBA format (8-8-8-8). Unlike ARGB32 this is a byte-ordered format, which means the 32bit encoding differs between big endian and little endian architectures, being respectively (0xRRGGBBAA) and (0xAABBGGRR). The order of the colors is the same on any architecture if read as bytes 0xRR,0xGG,0xBB,0xAA. |
QImage::Format_RGBA8888_Premultiplied | 18 | The image is stored using a premultiplied 32-bit byte-ordered RGBA format (8-8-8-8). |
QImage::Format_BGR30 | 19 | The image is stored using a 32-bit BGR format (x-10-10-10). |
QImage::Format_A2BGR30_Premultiplied | 20 | The image is stored using a 32-bit premultiplied ABGR format (2-10-10-10). |
QImage::Format_RGB30 | 21 | The image is stored using a 32-bit RGB format (x-10-10-10). |
QImage::Format_A2RGB30_Premultiplied | 22 | The image is stored using a 32-bit premultiplied ARGB format (2-10-10-10). |
QImage::Format_Alpha8 | 23 | The image is stored using an 8-bit alpha only format. |
QImage::Format_Grayscale8 | 24 | The image is stored using an 8-bit grayscale format. |
enum QImage::InvertMode |
This enum type is used to describe how pixel values should be inverted in the invertPixels() function.
Constant | Value | Description |
---|---|---|
QImage::InvertRgb | 0 | Invert only the RGB values and leave the alpha channel unchanged. |
QImage::InvertRgba | 1 | Invert all channels, including the alpha channel. |
QImage::QImage | ( | ) |
Constructs a null image.
QImage::QImage | ( | int | width, |
int | height, | ||
Format | format | ||
) |
QImage::QImage | ( | uchar * | data, |
int | width, | ||
int | height, | ||
Format | format, | ||
QImageCleanupFunction | cleanupFunction = nullptr , |
||
void * | cleanupInfo = nullptr |
||
) |
Constructs an image with the given width, height and format, that uses an existing memory buffer, data. The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.
The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.
If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setColorCount() or setColorTable() before the image is used.
QImage::QImage | ( | const uchar * | data, |
int | width, | ||
int | height, | ||
Format | format, | ||
QImageCleanupFunction | cleanupFunction = nullptr , |
||
void * | cleanupInfo = nullptr |
||
) |
Constructs an image with the given width, height and format, that uses an existing read-only memory buffer, data. The width and height must be specified in pixels, data> must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.
The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.
If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setColorCount() or setColorTable() before the image is used.
Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, calling QImage::bits() will return a deep copy of the image, rather than the buffer passed to the constructor. This allows for the efficiency of constructing a QImage from raw data, without the possibility of the raw data being changed.
QImage::QImage | ( | uchar * | data, |
int | width, | ||
int | height, | ||
int | bytesPerLine, | ||
Format | format, | ||
QImageCleanupFunction | cleanupFunction = nullptr , |
||
void * | cleanupInfo = nullptr |
||
) |
Constructs an image with the given width, height and format, that uses an existing memory buffer, data. The width and height must be specified in pixels. The bytesPerLine specifies the number of bytes per line (stride).
The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.
If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setColorCount() or setColorTable() before the image is used.
QImage::QImage | ( | const uchar * | data, |
int | width, | ||
int | height, | ||
int | bytesPerLine, | ||
Format | format, | ||
QImageCleanupFunction | cleanupFunction = nullptr , |
||
void * | cleanupInfo = nullptr |
||
) |
Constructs an image with the given width, height and format, that uses an existing memory buffer, data. The width and height must be specified in pixels. The value for bytesPerLine specifies the number of bytes per line (stride).
The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.
If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setColorCount() or setColorTable() before the image is used.
Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, calling QImage::bits() will return a deep copy of the image, rather than the buffer passed to the constructor. This allows for the efficiency of constructing a QImage from raw data, without the possibility of the raw data being changed.
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. Refer to the Resource System overview for details on how to embed images and other resource files in the application's executable.
|
explicit |
Constructs an image from the given xpm image. Make sure that the image is a valid XPM image. Errors are silently ignored. It is possible to squeeze the XPM variable a little bit by using an unusual declaration.
The extra const
makes the entire definition read only, which is slightly more efficient (for example, when the code is in a shared library) and able to be stored in ROM with the application.
QImage::QImage | ( | const QImage & | other | ) |
Copy constructs a new QImage from other.
|
inline |
Move constructs a new QImage from other.
QImage::~QImage | ( | ) |
Destroys the image and cleans up.
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. This method is slow for images without color table.
|
deprecated |
You can see an example of use of this function in QPixmap's 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.
This is an expensive function.
int QImage::bitPlaneCount | ( | ) | const |
uchar * QImage::bits | ( | ) |
Returns a pointer to the first pixel data. This is equivalent to scanLine(0).
qImage uses 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.
const uchar * QImage::bits | ( | ) | const |
QImage uses implicit data sharing, but this function does not perform a deep copy of the shared pixel data, because the returned data is const.
int QImage::byteCount | ( | ) | const |
Returns the number of bytes occupied by the image data.
int QImage::bytesPerLine | ( | ) | const |
Returns the number of bytes per image scanline. This is equivalent to byteCount() / height().
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.
QRgb QImage::color | ( | int | index | ) | const |
Returns the color in the color table at index. 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.
int QImage::colorCount | ( | ) | const |
Returns the size of the color table for the image. Notice that colorCount() returns 0 for 32-bpp images because these images do not use color tables, but instead encode pixel values as ARGB quadruplets.
QVector< QRgb > QImage::colorTable | ( | ) | const |
Returns a list of the colors contained in the image's color table, or an empty list if the image does not have a color table
const uchar * QImage::constBits | ( | ) | const |
Returns a pointer to the first pixel data. QImage uses implicit data sharing, but this function does not perform a deep copy of the shared pixel data, because the returned data is const.
const uchar * QImage::constScanLine | ( | int | index | ) | const |
Returns a pointer to the pixel data at the scanline with the given index. The first scanline is at index 0. The scanline data is aligned on a 32-bit boundary.
QImage uses implicit data sharing, but this function does not perform a deep copy of the shared pixel data, because the returned data is const.
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. Conversion from 32 bit to 8 bit indexed is a slow operation and will use a straightforward nearest color approach, with no dithering.
|
inline |
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.
|
inline |
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.
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 rect.
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.
|
inline |
The returned image is copied from the position (x, y) in this image, and will always have the given width and height. In areas beyond this image, pixels are set to 0.
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 Qt::EmptyFlag 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.
QImage QImage::createHeuristicMask | ( | bool | clipTight = true | ) | const |
Creates and returns a 1-bpp heuristic mask for this image. 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.
The method 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.
This method disregards the alpha buffer.
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.
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.
qreal QImage::devicePixelRatio | ( | ) | const |
Returns the device pixel ratio for the image. This is the ratio between device pixels and device independent pixels. The default value is 1.0. Use this method when calculating layout geometry based on the image size.
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.
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.
void QImage::fill | ( | const QColor & | color | ) |
Fills the entire image with the given color.
If the depth of the image is 1, the image will be filled with 1 if color equals Qt::color1, otherwise it will 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, otherwise it will be filled with 0.
void QImage::fill | ( | Qt::GlobalColor | color | ) |
Fills the image with the given color, described as a standard global color.
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.
Format QImage::format | ( | ) | const |
Returns the format of the image.
|
inlinestatic |
Loads an image from the given data using the specified format.
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.
bool QImage::hasAlphaChannel | ( | ) | const |
Returns true if the image has a format that respects the alpha channel, otherwise returns false.
int QImage::height | ( | ) | const |
Returns the height of the image.
void QImage::invertPixels | ( | InvertMode | mode = InvertRgb | ) |
Inverts all pixel values in the image.
The given invert mode only have a meaning when the image's depth is 32. The default mode is InvertRgb, which leaves the alpha channel unchanged. If the mode is InvertRgba, the alpha bits are also inverted.
Inverting an 8-bit image means to replace all pixels using color index i with a pixel using color index 255 minus i. The same is the case for a 1-bit image. The color table is not changed.
bool QImage::isGrayscale | ( | ) | const |
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.
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. Refer to the Resource System overview for details on how to embed images and other resource files in the application's executable.
Reads a QImage from the given device. This can be used to load an image directly from a QByteArray.
|
inline |
Loads an image from the given data using the specified format.
Loads an image from the first len bytes of the given binary buffer. Returns true if the image was successfully loaded, otherwise returns false.
The loader attempts to read the image using the specified format, for example 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.
|
overrideprotectedvirtual |
Returns the metric information for the given paint device metric.
Reimplemented from QPaintDevice::metric()
|
inline |
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.
The original image is not changed.
|
inline |
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. The original image is not changed.
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.
bool QImage::operator!= | ( | const QImage & | other | ) | const |
Returns true if this image and other have different contents, otherwise returns false. The comparison can be slow if the image data needs to be compared pixel by pixel.
QImage & QImage::operator= | ( | const QImage & | other | ) |
Copy assigns from other and returns a reference to this object.
|
inline |
Move assigns from other and returns a reference to this object.
bool QImage::operator== | ( | const QImage & | other | ) | const |
Returns true if this image and other have the same contents, otherwise returns false. The comparison can be slow if the image data needs to be compared pixel by pixel.
|
overridevirtual |
Returns a pointer to the paint engine used for drawing on the device.
Implements QPaintDevice::paintEngine()
|
inline |
Returns the color of the pixel at the given pos. If the position is not valid, the results are undefined. This method is expensive when used for massive pixel manipulations.
QRgb QImage::pixel | ( | int | x, |
int | y | ||
) | const |
Returns the color of the pixel at coordinates (x, y).
Returns the color of the pixel at the given pos as a QColor. If the position is not valid an invalid QColor is returned.
This method is expensive when used for massive pixel manipulations. Use constBits() or constScanLine() when many pixels needs to be read.
QColor QImage::pixelColor | ( | int | x, |
int | y | ||
) | const |
Returns the color of the pixel at coordinates (x, y) as a QColor.
QPixelFormat QImage::pixelFormat | ( | ) | const |
Returns the QImage::Format as a QPixelFormat.
|
inline |
int QImage::pixelIndex | ( | int | x, |
int | y | ||
) | const |
Returns the pixel index at (x, y).
QRect QImage::rect | ( | ) | const |
|
inline |
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.
|
inline |
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.
bool QImage::save | ( | const QString & | fileName, |
const QString & | format = QString() , |
||
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 the fileName 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.
bool QImage::save | ( | QIODevice * | device, |
const QString & | format = QString() , |
||
int | quality = -1 |
||
) | const |
Writes a QImage to the given device. This can be used to save an image directly into a QByteArray.
QImage QImage::scaled | ( | const QSize & | size, |
Qt::AspectRatioMode | aspectRatioMode = Qt::IgnoreAspectRatio , |
||
Qt::TransformationMode | mode = Qt::FastTransformation |
||
) | const |
Returns a copy of the image scaled to a rectangle defined by the given size according to the given aspectRatioMode and mode. If the given size is empty this method returns a null image.
|
inline |
Returns a copy of the image scaled to a rectangle with the given width and height according to the given aspectRatioMode and mode. If either the width or the height is zero or negative, the method returns a null image.
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. If the given height is 0 or negative, a null image is returned.
This method automatically calculates the width of the image so that the ratio of the image is preserved.
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. If the given width is 0 or negative, a null image is returned.
This method automatically calculates the height of the image so that its aspect ratio is preserved.
uchar * QImage::scanLine | ( | int | index | ) |
Returns a pointer to the pixel data at the scanline with the given index. The first scanline is at index 0. The scanline data is aligned on a 32-bit boundary.
QRgb*
(QRgb has a 32-bit size) and use it to read/write the pixel value. You can not 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.const uchar * QImage::scanLine | ( | int | index | ) | const |
Const version of scanLine().
|
inlinedeprecated |
Returns a number that identifies the contents of this QImage object. Distinct QImage objects can only have the same serial number if they refer to the same contents (but they do not have to).
The serial number does not necessarily change when the image is altered. This means that it may be dangerous to use it as a cache key.
|
deprecated |
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.
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.
This function is expensive.
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().
void QImage::setColorCount | ( | int | colorCount | ) |
Resizes the color table to contain colorCount entries. If the color table is expanded, all the extra colors will be set to transparent (i.e qRgba(0, 0, 0, 0)). When the image is used, the color table must be large enough to have entries for all the pixel/index values present in the image, otherwise the results are undefined.
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.
void QImage::setDevicePixelRatio | ( | qreal | scaleFactor | ) |
Sets the device pixel ratio for the image. This is the ratio between image pixels and device independent pixels. The default scaleFactor is 1.0. Setting it to something else has the following two effects.
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.
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.
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.
Sets the pixel index or color at the given pos 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.
void QImage::setPixel | ( | int | x, |
int | y, | ||
uint | index_or_rgb | ||
) |
Sets the pixel index or color at (x, y) to index_or_rgb.
Sets the color at the given pos to color. If position is not a valid coordinate pair in the image, or the image's format is either monochrome or paletted, the result is undefined. If performance is a concern use scanLine() or bits() to access pixel data directly.
void QImage::setPixelColor | ( | int | x, |
int | y, | ||
const QColor & | color | ||
) |
Sets the pixel color at (x, y) to color.
Sets the image text for the given key to the specified text.
To store a single text block such as a comment or 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().
|
protected |
Returns a smoothly scaled copy of the image. The returned image has a size of width by height pixels.
|
inline |
Swaps image other with this image. This operation is very fast and never fails.
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.
QStringList QImage::textKeys | ( | ) | const |
|
static |
Converts format into a QImage::Format.
|
static |
Converts format into a QPixelFormat.
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. This occurs when the image produced is the smallest image that contains all the transformed points of the original image. Use trueMatrix() to retrieve the actual matrix used for transforming an image.
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. The image produced is the smallest image that contains all the transformed points of the original image. Use the trueMatrix() function to retrieve the actual matrix used for transforming an image.
Unlike the other overload, this function can be used to perform perspective transformations on images.
Returns the actual matrix used for transforming an image with the given width, height and matrix.
When transforming an image using the transformed() function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. transformed() returns the smallest image containing all transformed points of the original image. This function returns the modified matrix, which maps points correctly from the original image into the new image.
|
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 method creates transformation matrices that can be used to perform perspective transformations on images.
|
inline |
Returns true if pos is a valid coordinate pair within the image, otherwise returns false.
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.
int QImage::width | ( | ) | const |
Returns the width of the image.
|
related |
Writes the image to the stream and returns a reference to the stream. The image is written as a PNG image or as a BMP image if the stream's version is 1. Writing the stream to a file will not produce a valid image file.
Refer to Serializing Data Types for additional information.
|
related |
Reads an image from the stream to the image and returns a reference to the stream.
Refer to Serializing Data Types for additional information.