It is one of the two classes TQt provides for dealing with images, the other being QPixmap. TQImage is designed and optimized for I/O and for direct pixel access/manipulation. QPixmap is designed and optimized for drawing. There are (slow) functions to convert between TQImage and QPixmap: QPixmap::convertToImage() and QPixmap::convertFromImage().
An image has the parameters width, height and depth (bits per pixel, bpp), a color table and the actual pixels. TQImage supports 1-bpp, 8-bpp and 32-bpp image data. 1-bpp and 8-bpp images use a color lookup table; the pixel value is a color table index.
An entry in the color table is an RGB triplet encoded as a \fCuint\fR. Use the tqRed(), tqGreen() and tqBlue() functions (ntqcolor.h) to access the components, and tqRgb to make an RGB triplet (see the TQColor class documentation).
1-bpp (monochrome) images have a color table with a most two colors. There are two different formats: big endian (MSB first) or little endian (LSB first) bit order. To access a single bit you will must do some bit shifts:
// set 8 bit pixel at (x,y) to value yellow (in color table)
.br
*(image.scanLine(y) + x) = 19;
.br
.fi
.PP
32-bpp images ignore the color table; instead, each pixel contains the RGB triplet. 24 bits contain the RGB value; the most significant byte is reserved for the alpha buffer.
On Qt/Embedded, scanlines are aligned to the pixel depth and may be padded to any degree, while on all other platforms, the scanlines are 32-bit aligned for all depths. The constructor taking a \fCuchar*\fR argument always expects 32-bit aligned data. On Qt/Embedded, an additional constructor allows the number of bytes-per-line to be specified.
TQImage supports a variety of methods for getting information about the image, for example, colorTable(), allGray(), isGrayscale(), bitOrder(), bytesPerLine(), depth(), dotsPerMeterX() and dotsPerMeterY(), hasAlphaBuffer(), numBytes(), numColors(), and width() and height().
TQImage also supports a number of functions for creating a new image that is a transformed version of the original. For example, copy(), convertBitOrder(), convertDepth(), createAlphaMask(), createHeuristicMask(), mirror(), scale(), smoothScale(), swapRGB() and xForm(). There are also functions for changing attributes of an image in-place, for example, setAlphaBuffer(), setColor(), setDotsPerMeterX() and setDotsPerMeterY() and setNumColors().
Images can be loaded and saved in the supported formats. Images are saved to a file with save(). Images are loaded from a file with load() (or in the constructor) or from an array of data with loadFromData(). The lists of supported formats are available from inputFormatList() and outputFormatList().
.PP
Strings of text may be added to images using setText().
The functions scale() and smoothScale() use different modes for scaling the image. The purpose of these modes is to retain the ratio of the image if this is required.
\fCQImage::ScaleFree\fR - The image is scaled freely: the resulting image fits exactly into the specified size; the ratio will not necessarily be preserved.
.TP
\fCQImage::ScaleMin\fR - The ratio of the image is preserved and the resulting image is guaranteed to fit into the specified size (it is as large as possible within these constraints) - the image might be smaller than the requested size.
.TP
\fCQImage::ScaleMax\fR - The ratio of the image is preserved and the resulting image fills the whole specified rectangle (it is as small as possible within these constraints) - the image might be larger than the requested size.
Constructs an image and tries to load the image from the file \fIfileName\fR.
.PP
If \fIformat\fR is specified, the loader attempts to read the image using the specified format. If \fIformat\fR is not specified (which is the default), the loader reads a few bytes from the header to guess the file format.
.PP
If the loading of the image failed, this object is a null image.
.PP
The QImageIO documentation lists the supported image formats and explains how to add extra formats.
Constructs an image from \fIxpm\fR, which must be a valid XPM image.
.PP
Errors are silently ignored.
.PP
Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:
.PP
.nf
.br
static const char * const start_xpm[]={
.br
"16 15 8 1",
.br
"a c #cec6bd",
.br
....
.br
.fi
.PP
The extra \fCconst\fR 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.
.SH "TQImage::TQImage ( uchar * yourdata, int w, int h, int depth, TQRgb * colortable, int numColors, Endian bitOrder )"
Constructs an image \fIw\fR pixels wide, \fIh\fR pixels high with a color depth of \fIdepth\fR, that uses an existing memory buffer, \fIyourdata\fR. The buffer must remain valid throughout the life of the TQImage. The image does not delete the buffer at destruction.
.SH "TQImage::TQImage ( uchar * yourdata, int w, int h, int depth, int bpl, TQRgb * colortable, int numColors, Endian bitOrder )"
Constructs an image that uses an existing memory buffer. The buffer must remain valid for the life of the TQImage. The image does not delete the buffer at destruction. The buffer is passed as \fIyourdata\fR. The image's width is \fIw\fR and its height is \fIh\fR. The color depth is \fIdepth\fR. \fIbpl\fR specifies the number of bytes per line.
Converts the depth (bpp) of the image to \fIdepth\fR and returns the converted image. The original image is not changed.
.PP
The \fIdepth\fR argument must be 1, 8, 16 (Qt/Embedded only) or 32.
.PP
Returns \fC*this\fR if \fIdepth\fR is equal to the image depth, or a null image if this image cannot be converted.
.PP
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the \fIconversion_flags\fR to specify how you'd prefer this to happen.
Returns an image with depth \fId\fR, using the \fIpalette_count\fR colors pointed to by \fIpalette\fR. If \fId\fR is 1 or 8, the returned image will have its color table ordered the same as \fIpalette\fR.
.PP
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the \fIconversion_flags\fR to specify how you'd prefer this to happen.
.PP
Note: currently no closest-color search is made. If colors are found that are not in the palette, the palette may not be used at all. This result should not be considered valid because it may change in future implementations.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns a deep copy of a sub-area of the image.
.PP
The returned image is always \fIw\fR by \fIh\fR pixels in size, and is copied from position \fIx\fR, \fIy\fR in this image. In areas beyond this image pixels are filled with pixel 0.
.PP
If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the \fIconversion_flags\fR to specify how you'd prefer this to happen.
Sets the image \fIwidth\fR, \fIheight\fR, \fIdepth\fR, its number of colors (in \fInumColors\fR), and bit order. Returns TRUE if successful, or FALSE if the parameters are incorrect or if memory cannot be allocated.
The \fIwidth\fR and \fIheight\fR is limited to 32767. \fIdepth\fR must be 1, 8, or 32. If \fIdepth\fR is 1, \fIbitOrder\fR must be set to either TQImage::LittleEndian or TQImage::BigEndian. For other depths \fIbitOrder\fR must be TQImage::IgnoreEndian.
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.
.PP
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.
.PP
The returned image has little-endian bit order, which you can convert to big-endianness using convertBitOrder().
.PP
If \fIclipTight\fR is TRUE the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels.
Detaches from shared image data and makes sure that this image is the only one referring to the data.
.PP
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.
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.
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.
Fills the entire image with the pixel value \fIpixel\fR.
.PP
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.
.PP
If the depth is 32 and the image has no alpha buffer, the \fIpixel\fR value is written to each pixel in the image. If the image has an alpha buffer, only the 24 RGB bits are set and the upper 8 bits (alpha value) are left unchanged.
Note: TQImage::pixel() returns the color of the pixel at the given coordinates; TQColor::pixel() returns the pixel value of the underlying window system (essentially an index value), so normally you will want to use TQImage::pixel() to use a color from an existing image or TQColor::rgb() to use a specific color.
The QImageIO documentation lists the guaranteed supported image formats, or use TQImage::inputFormats() and TQImage::outputFormats() to get lists that include the installed formats.
If the depth is 32: if \fIinvertAlpha\fR is TRUE, the alpha bits are also inverted, otherwise they are left unchanged.
.PP
If the depth is not 32, the argument \fIinvertAlpha\fR has no meaning.
.PP
Note that inverting an 8-bit image means to replace all pixels using color index \fIi\fR with a pixel using color index 255 minus \fIi\fR. Similarly for a 1-bit image. The color table is not changed.
Loads an image from the file \fIfileName\fR. Returns TRUE if the image was successfully loaded; otherwise returns FALSE.
.PP
If \fIformat\fR is specified, the loader attempts to read the image using the specified format. If \fIformat\fR is not specified (which is the default), the loader reads a few bytes from the header to guess the file format.
.PP
The QImageIO documentation lists the supported image formats and explains how to add extra formats.
.PP
See also loadFromData(), save(), imageFormat(), QPixmap::load(), and QImageIO.
Loads an image from the first \fIlen\fR bytes of binary data in \fIbuf\fR. Returns TRUE if the image was successfully loaded; otherwise returns FALSE.
.PP
If \fIformat\fR is specified, the loader attempts to read the image using the specified format. If \fIformat\fR is not specified (which is the default), the loader reads a few bytes from the header to guess the file format.
.PP
The QImageIO documentation lists the supported image formats and explains how to add extra formats.
.PP
See also load(), save(), imageFormat(), QPixmap::loadFromData(), and QImageIO.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether \fIhorizontal\fR and \fIvertical\fR are set to TRUE or FALSE. The original image is not changed.
Returns the size of the color table for the image.
.PP
Notice that numColors() returns 0 for 16-bpp (Qt/Embedded only) and 32-bpp images because these images do not use color tables, but instead encode pixel values as RGB triplets.
Returns TRUE if this image and image \fIi\fR 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.
Returns TRUE if this image and image \fIi\fR 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.
Saves the image to the file \fIfileName\fR, using the image file format \fIformat\fR and a quality factor of \fIquality\fR. \fIquality\fR must be in the range 0..100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 (the default) to use the default settings.
.PP
Returns TRUE if the image was successfully saved; otherwise returns FALSE.
.PP
See also load(), loadFromData(), imageFormat(), QPixmap::save(), and QImageIO.
Returns a scaled copy of the image. The returned image has a height of \fIh\fR pixels. This function automatically calculates the width of the image so that the ratio of the image is preserved.
.PP
If \fIh\fR is 0 or negative a null image is returned.
.PP
See also scale(), scaleWidth(), smoothScale(), and xForm().
Returns a scaled copy of the image. The returned image has a width of \fIw\fR pixels. This function automatically calculates the height of the image so that the ratio of the image is preserved.
.PP
If \fIw\fR is 0 or negative a null image is returned.
.PP
See also scale(), scaleHeight(), smoothScale(), and xForm().
\fBWarning:\fR If you are accessing 32-bpp image data, cast the returned pointer to \fCQRgb*\fR (TQRgb has a 32-bit size) and use it to read/write the pixel value. You cannot use the \fCuchar*\fR pointer directly, because the pixel format depends on the byte order on the underlying platform. Hint: use tqRed(), tqGreen() and tqBlue(), etc. (ntqcolor.h) to access the pixels.
Enables alpha buffer mode if \fIenable\fR is TRUE, otherwise disables it. The default setting is disabled.
.PP
An 8-bpp image has 8-bit pixels. A pixel is an index into the color table, which contains 32-bit color values. In a 32-bpp image, the 32-bit pixels are the color values.
.PP
This 32-bit value is encoded as follows: The lower 24 bits are used for the red, green, and blue components. The upper 8 bits contain the alpha component.
.PP
The alpha component specifies the transparency of a pixel. 0 means completely transparent and 255 means opaque. The alpha component is ignored if you do not enable alpha buffer mode.
Records string \fIs\fR for the keyword \fIkey\fR. The \fIkey\fR should be a portable keyword recognizable by other software - some suggested values can be found in the PNG specification. \fIs\fR can be any text. \fIlang\fR should specify the language code (see RFC 1766) or 0.
Returns a smoothly scaled copy of the image. The returned image has a size of width \fIw\fR by height \fIh\fR pixels if \fImode\fR is ScaleFree. The modes ScaleMin and ScaleMax may be used to preserve the ratio of the image: if \fImode\fR is ScaleMin, the returned image is guaranteed to fit into the rectangle specified by \fIw\fR and \fIh\fR (it is as large as possible within the constraints); if \fImode\fR is ScaleMax, the returned image fits at least into the specified rectangle (it is a small as possible within the constraints).
.PP
For 32-bpp images and 1-bpp/8-bpp color images the result will be 32-bpp, whereas all-gray images (including black-and-white 1-bpp) will produce 8-bit grayscale images with the palette spanning 256 grays from black to white.
.PP
This function uses code based on pnmscale.c by Jef Poskanzer.
.PP
pnmscale.c - read a portable anymap and scale it
.PP
Copyright (C) 1989, 1991 by Jef Poskanzer.
.PP
Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. This software is provided "as is" without express or implied warranty.
Returns a TQImage 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 TQImage is not changed.
Returns a copy of the image that is transformed using the transformation matrix, \fImatrix\fR.
.PP
The transformation \fImatrix\fR is internally adjusted to compensate for unwanted translation, i.e. xForm() returns the smallest image that contains all the transformed points of the original image.
.PP
See also scale(), QPixmap::xForm(), QPixmap::trueMatrix(), and QWMatrix.
Copies a block of pixels from \fIsrc\fR to \fIdst\fR. The pixels copied from source (src) are converted according to \fIconversion_flags\fR if it is incompatible with the destination (\fIdst\fR).
.PP
\fIsx\fR, \fIsy\fR is the top-left pixel in \fIsrc\fR, \fIdx\fR, \fIdy\fR is the top-left position in \fIdst\fR and \fIsw\fR, \\sh is the size of the copied block.
.PP
The copying is clipped if areas outside \fIsrc\fR or \fIdst\fR are specified.
.PP
If \fIsw\fR is -1, it is adjusted to src->width(). Similarly, if \fIsh\fR is -1, it is adjusted to src->height().