QImage Class Reference |
Constant | Value | Description |
---|---|---|
QImage::IgnoreEndian | 2 | Endianness does not matter. Useful for some operations that are independent of endianness. |
QImage::BigEndian | 0 | Most significant bit first or network byte order, as on SPARC, PowerPC, and Motorola CPUs. |
QImage::LittleEndian | 1 | Least significant bit first or little endian byte order, as on Intel x86. |
The following image formats are available in all versions of Qt:
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. Note that you will also need to call setNumColors() with a value of 256 before setting any of the colors in the index. |
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.) |
The following image formats are specific to Qt/Embedded:
Constant | Value | Description |
---|---|---|
QImage::Format_RGB16 | 7 | The image is stored using a 16-bit RGB format. |
QImage::Format_RGB15 | 8 | The image is stored using a 15-bit RGB format. |
QImage::Format_Grayscale16 | 9 | The image is stored with 65536 levels of gray (16 bits per pixel). |
QImage::Format_Grayscale8 | 10 | The image is stored with 256 levels of gray (8 bits per pixel). |
QImage::Format_Grayscale4 | 11 | The image is stored with 16 levels of gray (4 bits per pixel). |
QImage::Format_Grayscale4LSB | 12 | The image is stored with 16 levels of gray, stored in a form where the lowest 4 bits in a byte contain the first pixel in each pair. |
QImage::Format_Grayscale2 | 13 | The image is stored with 4 levels of gray (2 bits per pixel). |
QImage::Format_Grayscale2LSB | 14 | The image is stored with 4 levels of gray, stored in a form where the least significant bits contain the first pixel value and the most significant bits contain the last pixel value in each byte containing a group of 4 pixels. |
See also format() and convertToFormat().
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. |
Constructs a null image.
See also isNull().
Constructs an image with size in format format.
Constructs an image with width, height in format format.
Constructs an image width pixels wide, height pixels high with a format of format, that uses an existing memory buffer, data. The buffer must remain valid throughout the life of the QImage. The image does not delete the buffer at destruction.
Note that data must be 32-bit aligned.
If the image is in an indexed color format, set the color table for the image using setColorTable().
Constructs an image from xpm, which must be 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 ROMable when the application is to be stored in ROM.
Constructs an image and tries to load the image from the file fileName.
If format is specified, 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.
If the loading of the image failed, this object is a null image.
The QImageReader documentation lists the supported image formats and explains how to add extra formats.
The file name can be 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 load(), isNull(), and QImageReader.
Constructs a shallow copy of image.
Constructs an image and tries to load the image from the file fileName.
If format is specified, the loader attempts to read the image using the specified format. If format is not specified (which is the default), the loader probes the files for a header to guess the file format.
If the loading of the image failed, this object is a null image.
The QImageReader documentation lists the supported image formats and explains how to add extra formats.
The file name can be 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 if you want to ensure that all user-visible strings go through QObject::tr(), for example.
See also QString::fromAscii(), load(), isNull(), and QImageReader.
Destroys the image and cleans up.
Returns true if all the colors in the image are shades of gray (i.e. their red, green and blue components are equal); otherwise returns false.
This function is slow for large 32-bit images.
See also isGrayscale().
Extracts the alpha channel from this image as an 8 bit gray scale image and returns it.
See also setAlphaChannel().
Returns a pointer to the first pixel data. This is equivalent to scanLine(0).
See also numBytes(), scanLine(), and jumpTable().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns the number of bytes per image scanline. This is equivalent to numBytes()/height().
See also numBytes() and scanLine().
Returns the color in the color table at index i. The first color is at index 0.
A color value is an RGB triplet. Use the qRed(), qGreen(), and qBlue() functions to get the color value components.
See also setColor(), numColors(), and QColor.
Returns the color table of the image, or an empty list of the image does not have a color table
See also setColorTable() and numColors().
Returns a copy of the image in the given format.
The image conversion flags specified by flags control how the image data is handled during the conversion process.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns a copy of the image converted to the given format, using a color table specified by colorTable.
The image conversion flags specified by flags control how the image data is handled during the conversion process.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns a sub-area of the image.
The returned image is always w by h pixels in size, and is copied from position x, y in this image. In areas beyond this image pixels are filled with pixel 0.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns a sub-area of the image.
The returned image always has the size of the rectangle r. In areas beyond this image pixels are filled with pixel 0.
If r is a null rectangle the entire image is copied.
Builds and returns a 1-bpp mask from the alpha buffer in this image. Returns a null image if the image is of format RGB32.
See QPixmap::convertFromImage() for a description of the flags argument.
The returned image has little-endian bit order, which you can convert to big-endian using convertToFormat().
See also createHeuristicMask().
Creates and returns a 1-bpp heuristic mask for this image. It 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, which you can convert to big-endian using convertToFormat().
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.
This function disregards the alpha buffer.
See also createAlphaMask().
Returns the depth of the image.
The image depth is the number of bits used to encode a single pixel, also called bits per pixel (bpp) or bit planes of an image.
The supported depths are 1, 8 and 32.
See also convertToFormat().
Detaches from shared image d and makes sure that this image is the only one referring to the data.
If multiple images share common data, this image makes a copy of the data and detaches itself from the sharing mechanism. Nothing is done if there is just a single reference.
See also copy().
Returns the number of pixels that fit horizontally in a physical meter. This and dotsPerMeterY() define the intended scale and aspect ratio of the image.
See also setDotsPerMeterX().
Returns the number of pixels that fit vertically in a physical meter. This and dotsPerMeterX() define the intended scale and aspect ratio of the image.
See also setDotsPerMeterY().
Fills the entire image with the pixel value pixel.
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.
Note: QImage::pixel() returns the color of the pixel at the given coordinates; 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 invertPixels(), depth(), hasAlphaBuffer(), and create().
returns the format of the image.
Constructs a QImage from the first size bytes of binary data in data. If the loading of the image failed, this object is a null image.
If format is specified, 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.
The QImageReader documentation lists the supported image formats and explains how to add extra formats.
See also load(), save(), QImageReader::imageFormat(), QPixmap::loadFromData(), and QImageReader.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Loads an image from the QByteArray data.
Returns true if the image has an alpha channel.
Returns the height of the image.
See also width(), size(), and rect().
Inverts all pixel values in the image.
If the depth is 32: if mode is InvertRgba (the default), the alpha bits are also inverted, otherwise they are left unchanged.
If the depth is not 32, the argument mode has no meaning. The default mode is InvertRgb, which leaves the alpha channel unchanged.
Note that inverting an 8-bit image means to replace all pixels using color index i with a pixel using color index 255 minus i. Similarly for a 1-bit image. The color table is not changed.
See also fill(), depth(), and hasAlphaBuffer().
Returns true if the image is detached; otherwise returns false.
See also detach().
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() and depth().
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 fileName. Returns true if the image was successfully loaded; otherwise returns false.
If format is specified, 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.
The QImageReader documentation lists the supported image formats and explains how to add extra formats.
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 loadFromData(), save(), QImageReader::imageFormat(), QPixmap::load(), and QImageReader.
Loads an image from the first len bytes of binary data in data. Returns true if the image was successfully loaded; otherwise returns false.
If format is specified, 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.
The QImageReader documentation lists the supported image formats and explains how to add extra formats.
See also load(), save(), QImageReader::imageFormat(), QPixmap::loadFromData(), and QImageReader.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Loads an image from the QByteArray data.
Returns the size for the specified metric on the device.
Reimplemented from QPaintDevice.
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.
See also scaled().
Returns the number of bytes occupied by the image data.
See also bytesPerLine() and bits().
Returns the size of the color table for the image.
Notice that numColors() returns 0 for 32-bpp images because these images do not use color tables, but instead encode pixel values as RGB triplets.
See also setNumColors() and colorTable().
Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images.
See also setOffset().
Returns the color of the pixel at the coordinates (x, y).
If (x, y) is not on the image, the results are undefined.
See also setPixel(), qRed(), qGreen(), qBlue(), and valid().
Returns the pixel index at the given coordinates.
If (x, y) is not valid, or if the image is not a paletted image (depth() > 8), the results are undefined.
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
See also width(), height(), and size().
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 a BGR image. The original QImage is not changed.
Saves the image to the file fileName, using the image file format format and a quality factor of quality. quality 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 load(), loadFromData(), QImageReader::imageFormat(), QPixmap::save(), and QImageReader.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
This function writes a QImage to the QIODevice, device. This can be used, for example, to save an image directly into a QByteArray:
QImage image; QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); image.save(&buffer, "PNG"); // writes image into ba in PNG format
Returns a copy of the image scaled to a rectangle of width w and height h according to aspectRatioMode and transformMode.
If either the width w or the height h is zero or negative, this function returns a null image.
See also scaledToWidth(), scaledToHeight(), and transformed().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Scales the image to the given size, using the aspect ratio and transformation modes specified by aspectMode and transformMode.
Returns a scaled copy of the image with a height of h pixels using a transformation specified by mode. This function automatically calculates the width of the image so that the ratio of the image is preserved.
If h is 0 or negative a null image is returned.
See also scaled(), scaledToWidth(), and transformed().
Returns a scaled copy of the image with a width of w pixels using the specified transformation mode. This function automatically calculates the height of the image so that its aspect ratio is preserved.
If w is 0 or negative a null image is returned.
See also scaled(), scaledToHeight(), and transformed().
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(), and jumpTable().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns a number that uniquely identifies the contents of this QImage object. This means that multiple QImage objects can have the same serial number as long as they refer to the same contents.
A null image always have a serial number of 0.
An example of where this is useful is for caching QImages.
Sets the alpha channel of this image to 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.
The image will be converted to the format Format_ARGB32_Premultiplied if the function succeeds.
See also alphaChannel().
Sets a color in the color table at index i to c.
A color value is an RGB triplet. Use the qRed(), qGreen(), and qBlue() functions to get the color value components.
Note that, for images in Format_Indexed8 format, you will first need to call setNumColors() with a value of 256 before using this function.
See also color(), setNumColors(), and numColors().
Sets the color table used to translate color indexes to RGB values to the specified colors.
See also colorTable().
Sets the value returned by dotsPerMeterX() to x.
See also dotsPerMeterX().
Sets the value returned by dotsPerMeterY() to y.
See also dotsPerMeterY().
Resizes the color table to numColors colors.
If the color table is expanded all the extra colors will be set to black (RGB 0,0,0).
See also numColors(), color(), setColor(), and colorTable().
Sets the value returned by offset() to p.
See also offset().
Sets the pixel index or color at the coordinates (x, y) to index_or_rgb.
If (x, y) is not valid, the result is undefined.
If the image is a paletted image (depth() <= 8) and index_or_rgb >= numColors(), the result is undefined.
See also pixelIndex(), pixel(), qRgb(), qRgba(), and valid().
Records string s 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.
See also text().
Returns the size of the image, i.e. its width and height.
See also width(), height(), and rect().
Returns the string recorded for the keyword key in language lang, or in a default language if lang is 0.
See also setText().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns the string recorded for the keyword and language kl.
Returns the keywords for which some texts are recorded.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QStringList list = myImage.textKeys(); QStringList::Iterator it = list.begin(); while(it != list.end()) { myProcessing(*it); ++it; }
See also textList(), text(), setText(), and textLanguages().
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, e.g.
QStringList list = myImage.textLanguages(); QStringList::Iterator it = list.begin(); while(it != list.end()) { myProcessing(*it); ++it; }
See also textList(), text(), setText(), and textKeys().
Returns a list of QImageTextKeyLang objects that enumerate all the texts key/language pairs set by setText() for this image.
Returns a copy of the image that is transformed with the transformation matrix specified by matrix and using the transformation mode specified by 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.
See also scaled(), QPixmap::transformed(), QPixmap::trueMatrix(), and QMatrix.
Returns the actual matrix used for transforming a image with w width and h height and matrix matrix.
When transforming a image with transformed(), 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() and QMatrix.
Returns true if (x, y) is a valid coordinate in the image; otherwise returns false.
See also width(), height(), and pixelIndex().
Returns the width of the image.
See also height(), size(), and rect().
Returns the image as a QVariant
Returns true if this image and image i 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=().
Assigns a shallow copy of image to this image and returns a reference to this image.
See also copy().
Returns true if this image and image i have the same 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=().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Writes the image image to the stream s 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.
Format of the QDataStream operators
See also QImage::save().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Reads an image from the stream s and stores it in image.
Format of the QDataStream operators
See also QImage::load().
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.0 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com