The Qpixmap class represents the image, which is implemented in the Qtgui shared library.
Structure
The Qpixmap object generated by the following constructor is an empty image:
Qpixmap (); Constructs an empty image with a size of 0
The following constructor generates the size of the Qpixmap object, but the image data is not initialized:
Qpixmap (const qsize &size); Constructs an image of size, the image data is uninitialized
qpixmap (int width, int height); Equivalent to Qpixmap (qsize (width, height));
The following constructor can load an image from a specified file and generate a Qpixmap object:
Qpixmap (const QString &filename, const char *format = 0, Qt::imageconversionflags flags = Qt::autocolor);
The meanings of each of its parameters are explained below.
1) FileName: file name.
2) Format: A string that represents an image file and, if 0, is automatically recognized.
3) Flags: Represents the color conversion mode.
If the image file fails to load, an empty image is generated, where the flags parameter has the following values.
1) Qt::autocolor: Automatically determined by the system.
2) Qt::coloronly: color mode.
3) Qt::monoonly: Monochrome mode.
Image parameters
The following member functions can obtain information about the image represented by the Qpixmap object:
int depth () const; Color depth, both the number of bits per pixel of the
int width () const; Image width, in pixels of
int height () const; Image height, Unit is pixel
qsize size () cosnt; The size of the image, i.e. qsize (width (), height ());
Qrect rect () const; The rectangular area of the image, i.e. Qrect (Qpoint (0,0), size ());
Loading and saving images
Use the following member function to load an image from a file:
BOOL Load (const QString &filename, const char *fornat = 0, Qt::imagecoversionflags flags = Qt::autocolor);
Here the meaning of each parameter is the same as in the constructor, and a return value of TRUE indicates that the load was successful and false indicates that the load failed. The opposite action is to save the image represented by Qpixmap to a file, using the following member functions:
BOOL Save (const QString &filename, const char *format = 0, int quality =-1) const;
The meanings of each parameter and the return value are explained below.
1) FileName: file name.
2) Format: String that represents the format of the image file, and if 0, the file format is automatically determined based on the suffix of the file name.
3) Quality: For lossy compressed file format, it represents the quality of image preservation, the lower the quality, the greater the compression rate. A value range of 0~100,-1 indicates the default value is taken.
4) Return value: True indicates that the save was successful and false indicates that the save failed.
Judge
The following member function can determine whether an Qpixmap object is an empty image:
BOOL IsNull () const; Determine if the image is empty