📄 qpixmap.3qt
字号:
.PPIf \fIformat\fR is specified, the loader attempts to read the pixmap using the specified format. If \fIformat\fR is not specified (default), the loader reads a few bytes from the header to guess the file format..PPSee the convertFromImage() documentation for a description of the \fIconversion_flags\fR argument..PPThe QImageIO documentation lists the supported image formats and explains how to add extra formats..PPSee also loadFromData(), save(), imageFormat(), QImage::load() and QImageIO..PPExamples:.(lscrollview/scrollview.cpp picture/picture.cpp xform/xform.cpp.)l.SH "bool QPixmap::load ( const QString & fileName, const char * format=0, ColorMode mode=Auto )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "bool QPixmap::loadFromData ( const uchar * buf, uint len, const char * format, int conversion_flags )"Loads a pixmap from the binary data in \fIbuf\fR (\fIlen\fR bytes). Returns TRUE if successful, or FALSE if the pixmap could not be loaded..PPIf \fIformat\fR is specified, the loader attempts to read the pixmap using the specified format. If \fIformat\fR is not specified (default), the loader reads a few bytes from the header to guess the file format..PPSee the convertFromImage() documentation for a description of the \fIconversion_flags\fR argument..PPThe QImageIO documentation lists the supported image formats and explains how to add extra formats..PPSee also load(), save(), imageFormat(), QImage::loadFromData() and QImageIO..SH "bool QPixmap::loadFromData ( const QByteArray & buf, const char * format=0, int conversion_flags=0 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "bool QPixmap::loadFromData ( const uchar * buf, uint len, const char * format=0, ColorMode mode=Auto )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "const QBitmap * QPixmap::mask () const"Returns the mask bitmap, or null if no mask has been set..PPSee also setMask() and QBitmap..SH "int QPixmap::metric ( int m ) const \fC[virtual protected]\fR"Internal implementation of the virtual QPaintDevice::metric() function..PPUse the QPaintDeviceMetrics class instead..PPReimplemented from QPaintDevice..SH "QPixmap & QPixmap::operator= ( const QImage & image )"Converts the image \fIimage\fR to a pixmap that is assigned to this pixmap. Returns a reference to the pixmap..PPSee also convertFromImage()..SH "QPixmap & QPixmap::operator= ( const QPixmap & pixmap )"Assigns the pixmap \fIpixmap\fR to this pixmap and returns a reference to this pixmap..SH "QPixmap::Optimization QPixmap::optimization() const"Returns the optimization setting for this pixmap..PPThe default optimization setting is \fCQPixmap::NormalOptim.\fR You may change this settings in two ways:.TPCall setDefaultOptimization() to set the default optimization for all new pixmaps..TPCall setOptimization() to set a the optimization for individual pixmaps..PPSee also setOptimization(), setDefaultOptimization() and defaultOptimization()..SH "QRect QPixmap::rect () const"Returns the enclosing rectangle (0,0,width(),height()) of the pixmap..PPSee also width(), height() and size()..PPExamples:.(lxform/xform.cpp.)l.SH "void QPixmap::resize ( int w, int h )"Resizes the pixmap to \fIw\fR width and \fIh\fR height. If either \fIw\fR or \fIh\fR is less than 1, the pixmap becomes a null pixmap..PPIf both \fIw\fR and \fIh\fR are greater than 0, a valid pixmap is created. New pixels will be uninitialized (random) if the pixmap is expanded..PPExamples:.(ldesktop/desktop.cpp.)l.SH "void QPixmap::resize ( const QSize & size )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "bool QPixmap::save ( const QString & fileName, const char * format ) const"Saves the pixmap to the file \fIfileName,\fR using the image file format \fIformat.\fR Returns TRUE if successful, or FALSE if the pixmap could not be saved..PPSee also load(), loadFromData(), imageFormat(), QImage::save() and QImageIO..SH "bool QPixmap::save ( const QString & fileName, const char * format, int quality ) const"Saves the pixmap to the file \fIfileName,\fR using the image file format \fIformat\fR and a quality factor \fIquality. quality\fR must be in the range [0,100] or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files and -1 to use the default settings. Returns TRUE if successful, or FALSE if the pixmap could not be saved..PPSee also load(), loadFromData(), imageFormat(), QImage::save() and QImageIO..PPExamples:.(lqmag/qmag.cpp.)l.SH "bool QPixmap::selfMask () const"Returns TRUE if the pixmap's mask is identical to the pixmap itself..PPSee also mask()..SH "int QPixmap::serialNumber () const"Returns a number that uniquely identifies the contents of this QPixmap object. This means that multiple QPixmaps objects can have the same serial number as long as they refer to the same contents. The serial number is for example very useful for caching..PPSee also QPixmapCache..SH "void QPixmap::setDefaultOptimization ( Optimization optimization ) \fC[static]\fR"Sets the default pixmap optimization..PPAll \fInew\fR pixmaps that are created will use this default optimization. You may also set optimization for individual pixmaps using the setOptimization() function..PPThe initial default optimization setting is \fCQPixmap::Normal.\fR.PPSee also defaultOptimization(), setOptimization() and optimization()..SH "void QPixmap::setMask ( const QBitmap & newmask )"Sets a mask bitmap..PPThe \fImask\fR bitmap defines the clip mask for this pixmap. Every pixel in \fImask\fR corresponds to a pixel in this pixmap. Pixel value 1 means opaque and pixel value 0 means transparent. The mask must have the same size as this pixmap..PPSetting a null mask resets the mask,.PPSee also mask(), createHeuristicMask() and QBitmap..SH "QSize QPixmap::size () const"Returns the size of the pixmap..PPSee also width(), height() and rect()..PPExamples:.(lmovies/main.cpp qtimage/qtimage.cpp.)l.SH "QWMatrix QPixmap::trueMatrix ( const QWMatrix & matrix, int w, int h ) \fC[static]\fR"Returns the actual matrix used for transforming a pixmap with \fIw\fR width and \fIh\fR height..PPWhen transforming a pixmap with xForm(), the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. xForm() returns the smallest pixmap containing all transformed points of the original pixmap..PPThis function returns the modified matrix, which maps points correctly from the original pixmap into the new pixmap..PPSee also xForm() and QWMatrix..SH "int QPixmap::width () const"Returns the width of the pixmap..PPSee also height(), size() and rect()..PPExamples:.(lmovies/main.cpp qtimage/qtimage.cpp scrollview/scrollview.cpp xform/xform.cpp desktop/desktop.cpp.)l.SH "QPixmap QPixmap::xForm ( const QWMatrix & matrix ) const"Returns a copy of the pixmap that is transformed using \fImatrix.\fR.PPQt uses this function to implement rotated text on window systems that do not support such complex features..PPExample of how to manually draw a rotated text at (100,200) in a widget:.PP.nf.br char *str = "Trolls R Qt"; // text to be drawn.br QFont f( "Charter", 24 ); // use Charter 24pt font.br QPixmap pm( 8, 8 );.br QPainter p;.br QRect r; // text bounding rectangle.br QPoint bl; // text baseline position.br.br p.begin( &pm ); // first get the bounding.br p.setFont( f ); // text rectangle.br r = p.fontMetrics().boundingRect(str);.br bl = -r.topLeft(); // get baseline position.br p.end();.br.br pm.resize( r.size() ); // resize to fit the text.br pm.fill( white ); // fills pm with white.br p.begin( &pm ); // begin painting pm.br p.setFont( f ); // set the font.br p.setPen( blue ); // set blue text color.br p.drawText( bl, str ); // draw the text.br p.end(); // painting done.br.br QWMatrix m; // transformation matrix.br m.rotate( -33.4 ); // rotate coordinate system.br QPixmap rp = pm.xForm( m ); // rp is rotated pixmap.br.br QWMatrix t = QPixmap::trueMatrix( m, pm.width(), pm.height() );.br int x, y;.br t.map( bl.x(),bl.y(), &x,&y ); // get pm's baseline pos in rp.br.br bitBlt( myWidget, 100-x, 200-y, // blt rp into a widget.br &rp, 0, 0, -1, -1 );.fi.PPThis example outlines how Qt implements rotated text under X11. The font calculation is the most tedious part. The rotation itself is only 3 lines of code..PPIf you want to draw rotated text, you do not have to implement all the code above. The code below does exactly the same thing as the example above, except that it uses a QPainter..PP.nf.br char *str = "Trolls R Qt"; // text to be drawn.br QFont f( "Charter", 24 ); // use Charter 24pt font.br QPainter p;.br.br p.begin( myWidget );.br p.translate( 100, 200 ); // translates coord system.br p.rotate( -33.4 ); // rotates it counterclockwise.br p.setFont( f );.br p.drawText( 0, 0, str );.br p.end();.fi.PPSee also trueMatrix(), QWMatrix and QPainter::setWorldMatrix()..PPBugs and limitations:.TP2 and 4 bits pixmaps are not supported..PPExamples:.(lmovies/main.cpp qtimage/qtimage.cpp qmag/qmag.cpp xform/xform.cpp desktop/desktop.cpp.)l.SH RELATED FUNCTION DOCUMENTATION.SH "QDataStream & operator>> (QDataStream & s, QPixmap & pixmap)"Reads a pixmap from the stream..PPSee also QPixmap::load() and Format of the QDataStream operators.SH "QDataStream & operator<< (QDataStream & s, const QPixmap & pixmap)"Writes a pixmap to the stream as a PNG image..PPSee also QPixmap::save() and Format of the QDataStream operators.SH "SEE ALSO".BR http://doc.trolltech.com/qpixmap.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qpixmap.3qt) and the Qtversion (2.3.8).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -