📄 qimage.3qt
字号:
.BI "Endian \fBsystemBitOrder\fR ()".br.ti -1c.BI "Endian \fBsystemByteOrder\fR ()".br.ti -1c.BI "const char * \fBimageFormat\fR ( const QString & fileName )".br.ti -1c.BI "QStrList \fBinputFormats\fR ()".br.ti -1c.BI "QStrList \fBoutputFormats\fR ()".br.ti -1c.BI "QStringList \fBinputFormatList\fR ()".br.ti -1c.BI "QStringList \fBoutputFormatList\fR ()".br.in -1c.SH RELATED FUNCTION DOCUMENTATION.in +1c.ti -1c.BI "QDataStream & \fBoperator<<\fR ( QDataStream & s, const QImage & image )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( QDataStream & s, QImage & image )".br.in -1c.SH DESCRIPTIONThe QImage class provides a hardware-independent pixmap representation with direct access to the pixel data..PPIt is one of the two classes Qt provides for dealing with images, the other being QPixmap. QImage 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 QImage and QPixmap: QPixmap::convertToImage() and QPixmap::convertFromImage()..PPAn image has the parameters width, height and depth (bits per pixel, bpp), a color table and the actual pixels. QImage 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..PP32-bpp images encode an RGB value in 24 bits and ignore the color table. The most significant byte is used for the alpha buffer..PPAn entry in the color table is an RGB triplet encoded as a \fCuint\fR. Use the qRed(), qGreen() and qBlue() functions (qcolor.h) to access the components, and qRgb to make an RGB triplet (see the QColor class documentation)..PP1-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:.PP.nf.br QImage image;.br // sets bit at (x,y) to 1.br if ( image.bitOrder() == QImage::LittleEndian ).br *(image.scanLine(y) + (x >> 3)) |= 1 << (x & 7);.br else.br *(image.scanLine(y) + (x >> 3)) |= 1 << (7 - (x & 7));.br.fi.PPIf this looks complicated, it might be a good idea to convert the 1-bpp image to an 8-bpp image using convertDepth()..PP8-bpp images are much easier to work with than 1-bpp images because they have a single byte per pixel:.PP.nf.br QImage image;.br // set entry 19 in the color table to yellow.br image.setColor( 19, qRgb(255,255,0) );.br // set 8 bit pixel at (x,y) to value yellow (in color table).br *(image.scanLine(y) + x) = 19;.br.fi.PP32-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..PP.nf.br QImage image;.br // sets 32 bit pixel at (x,y) to yellow..br uint *p = (uint *)image.scanLine(y) + x;.br *p = qRgb(255,255,0);.br.fi.PPOn 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..PPQImage 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()..PPPixel colors are retrieved with pixel() and set with setPixel()..PPQImage 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()..PPImages 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()..PPStrings of text may be added to images using setText()..PPThe QImage class uses explicit sharing, similar to that used by QMemArray..PPNew image formats can be added as plugins..PPSee also QImageIO, QPixmap, Shared Classes, Graphics Classes, Image Processing Classes, and Implicitly and Explicitly Shared Classes..SS "Member Type Documentation".SH "QImage::Endian"This enum type is used to describe the endianness of the CPU and graphics hardware..TP\fCQImage::IgnoreEndian\fR - Endianness does not matter. Useful for some operations that are independent of endianness..TP\fCQImage::BigEndian\fR - Network byte order, as on SPARC and Motorola CPUs..TP\fCQImage::LittleEndian\fR - PC/Alpha byte order..SH "QImage::ScaleMode"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..PP<center>.ce 1.B "[Image Omitted]".PP</center> .TP\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..SH MEMBER FUNCTION DOCUMENTATION.SH "QImage::QImage ()"Constructs a null image..PPSee also isNull()..SH "QImage::QImage ( int w, int h, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )"Constructs an image with \fIw\fR width, \fIh\fR height, \fIdepth\fR bits per pixel, \fInumColors\fR colors and bit order \fIbitOrder\fR..PPUsing this constructor is the same as first constructing a null image and then calling the create() function..PPSee also create()..SH "QImage::QImage ( const QSize & size, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian )"Constructs an image with size \fIsize\fR pixels, depth \fIdepth\fR bits, \fInumColors\fR and \fIbitOrder\fR endianness..PPUsing this constructor is the same as first constructing a null image and then calling the create() function..PPSee also create()..SH "QImage::QImage ( const QString & fileName, const char * format = 0 )"Constructs an image and tries to load the image from the file \fIfileName\fR..PPIf \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..PPIf the loading of the image failed, this object is a null image..PPThe QImageIO documentation lists the supported image formats and explains how to add extra formats..PPSee also load(), isNull(), and QImageIO..SH "QImage::QImage ( const char * const xpm[] )"Constructs an image from \fIxpm\fR, which must be a valid XPM image..PPErrors are silently ignored..PPNote 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.PPThe 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 "QImage::QImage ( const QByteArray & array )"Constructs an image from the binary data \fIarray\fR. It tries to guess the file format..PPIf the loading of the image failed, this object is a null image..PPSee also loadFromData(), isNull(), and imageFormat()..SH "QImage::QImage ( uchar * yourdata, int w, int h, int depth, QRgb * 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 QImage. The image does not delete the buffer at destruction..PPIf \fIcolortable\fR is 0, a color table sufficient for \fInumColors\fR will be allocated (and destructed later)..PPNote that \fIyourdata\fR must be 32-bit aligned..PPThe endianness is given in \fIbitOrder\fR..SH "QImage::QImage ( uchar * yourdata, int w, int h, int depth, int bpl, QRgb * colortable, int numColors, Endian bitOrder )"Constructs an image that uses an existing memory buffer. The buffer must remain valid for the life of the QImage. 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..PPIf \fIcolortable\fR is 0, a color table sufficient for \fInumColors\fR will be allocated (and destructed later)..PPThe endianness is specified by \fIbitOrder\fR..SH "QImage::QImage ( const QImage & image )"Constructs a shallow copy of \fIimage\fR..SH "QImage::~QImage ()"Destroys the image and cleans up..SH "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 returns FALSE..PPThis function is slow for large 16-bit and 32-bit images..PPSee also isGrayscale()..SH "Endian QImage::bitOrder () const"Returns the bit order for the image..PPIf it is a 1-bpp image, this function returns either QImage::BigEndian or QImage::LittleEndian..PPIf it is not a 1-bpp image, this function returns QImage::IgnoreEndian..PPSee also depth()..SH "uchar * QImage::bits () const"Returns a pointer to the first pixel data. This is equivalent to scanLine(0)..PPSee also numBytes(), scanLine(), and jumpTable()..PPExample: opengl/texture/gltexobj.cpp..SH "int QImage::bytesPerLine () const"Returns the number of bytes per image scanline. This is equivalent to numBytes()/height()..PPSee also numBytes() and scanLine()..SH "QRgb QImage::color ( int i ) const"Returns the color in the color table at index \fIi\fR. The first color is at index 0..PPA color value is an RGB triplet. Use the qRed(), qGreen() and qBlue() functions (defined in qcolor.h) to get the color value components..PPSee also setColor(), numColors(), and QColor..PPExample: themes/wood.cpp..SH "QRgb * QImage::colorTable () const"Returns a pointer to the color table..PPSee also numColors()..SH "QImage QImage::convertBitOrder ( Endian bitOrder ) const"Converts the bit order of the image to \fIbitOrder\fR and returns the converted image. The original image is not changed..PPReturns \fC*this\fR if the \fIbitOrder\fR is equal to the image bit order, or a null image if this image cannot be converted..PPSee also bitOrder(), systemBitOrder(), and isNull()..SH "QImage QImage::convertDepth ( int depth, int conversion_flags ) const"Converts the depth (bpp) of the image to \fIdepth\fR and returns the converted image. The original image is not changed..PPThe \fIdepth\fR argument must be 1, 8, 16 or 32..PPReturns \fC*this\fR if \fIdepth\fR is equal to the image depth, or a null image if this image cannot be converted..PPIf 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..PPSee also Qt::ImageConversionFlags, depth(), and isNull()..SH "QImage QImage::convertDepth ( int depth ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..SH "QImage QImage::convertDepthWithPalette ( int d, QRgb * palette, int palette_count, int conversion_flags = 0 ) const"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..PPIf 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..PPNote: 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..PPCurrently inefficient for non-32-bit images..PPSee also Qt::ImageConversionFlags..SH "QImage QImage::copy () const"Returns a deep copy of the image..PPSee also detach()..SH "QImage QImage::copy ( int x, int y, int w, int h, int conversion_flags = 0 ) const"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -