📄 qpixmap.3qt
字号:
.SH "QPixmap::ColorMode"This enum type defines the color modes that exist for converting QImage objects to QPixmap..TP\fCQPixmap::Auto\fR - Select Color or Mono on a case-by-case basis..TP\fCQPixmap::Color\fR - Always create colored pixmaps..TP\fCQPixmap::Mono\fR - Always create bitmaps..SH "QPixmap::Optimization"QPixmap has the choice of optimizing for speed or memory in a few places; the best choice varies from pixmap to pixmap but can generally be derived heuristically. This enum type defines a number of optimization modes that you can set for any pixmap to tweak the speed/memory tradeoffs:.TP\fCQPixmap::DefaultOptim\fR - Whatever QPixmap::defaultOptimization() returns. A pixmap with this optimization will have whatever the current default optimization is. If the default optimization is changed using setDefaultOptimization(), then this will not effect any pixmaps that have already been created..TP\fCQPixmap::NoOptim\fR - No optimization (currently the same as MemoryOptim)..TP\fCQPixmap::MemoryOptim\fR - Optimize for minimal memory use on Windows 9x and X11 systems..TP\fCQPixmap::NormalOptim\fR - Optimize for typical usage. Often uses more memory than MemoryOptim, and is often faster..TP\fCQPixmap::BestOptim\fR - Optimize for pixmaps that are drawn very often and where performance is critical. Generally uses more memory than NormalOptim and may provide a little more speed..PPWe recommend using DefaultOptim..PP.SH MEMBER FUNCTION DOCUMENTATION.SH "QPixmap::QPixmap ()"Constructs a null pixmap..PPSee also isNull()..SH "QPixmap::QPixmap ( const QImage & image )"Constructs a pixmap from the QImage \fIimage\fR..PPSee also convertFromImage()..SH "QPixmap::QPixmap ( int w, int h, int depth = -1, Optimization optimization = DefaultOptim )"Constructs a pixmap with \fIw\fR width, \fIh\fR height and \fIdepth\fR bits per pixel. The pixmap is optimized in accordance with the \fIoptimization\fR value..PPThe contents of the pixmap is uninitialized..PPThe \fIdepth\fR can be either 1 (monochrome) or the depth of the current video mode. If \fIdepth\fR is negative, then the hardware depth of the current video mode will be used..PPIf either \fIw\fR or \fIh\fR is zero, a null pixmap is constructed..PPSee also isNull() and QPixmap::Optimization..SH "QPixmap::QPixmap ( const QSize & size, int depth = -1, Optimization optimization = DefaultOptim )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPConstructs a pixmap of size \fIsize\fR, \fIdepth\fR bits per pixel, optimized in accordance with the \fIoptimization\fR value..SH "QPixmap::QPixmap ( const QString & fileName, const char * format = 0, ColorMode mode = Auto )"Constructs a pixmap from the file \fIfileName\fR. If the file does not exist or is of an unknown format, the pixmap becomes a null pixmap..PPThe \fIfileName\fR, \fIformat\fR and \fImode\fR parameters are passed on to load(). This means that the data in \fIfileName\fR is not compiled into the binary. If \fIfileName\fR contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory..PPSee also QPixmap::ColorMode, isNull(), load(), loadFromData(), save(), and imageFormat()..SH "QPixmap::QPixmap ( const QString & fileName, const char * format, int conversion_flags )"Constructs a pixmap from the file \fIfileName\fR. If the file does not exist or is of an unknown format, the pixmap becomes a null pixmap..PPThe \fIfileName\fR, \fIformat\fR and \fIconversion_flags\fR parameters are passed on to load(). This means that the data in \fIfileName\fR is not compiled into the binary. If \fIfileName\fR contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory..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, isNull(), load(), loadFromData(), save(), and imageFormat()..SH "QPixmap::QPixmap ( const char * xpm[] )"Constructs a pixmap 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 (for example, when the code is in a shared library) and ROMable when the application is to be stored in ROM..PPIn order to use that sort of declaration you must cast the variable back to \fCconst char **\fR when you create the QPixmap..SH "QPixmap::QPixmap ( const QByteArray & img_data )"Constructs a pixmaps by loading from \fIimg_data\fR. The data can be in any image format supported by Qt..PPSee also loadFromData()..SH "QPixmap::QPixmap ( const QPixmap & pixmap )"Constructs a pixmap that is a copy of \fIpixmap\fR..SH "QPixmap::QPixmap ( int w, int h, const uchar * bits, bool isXbitmap )\fC [protected]\fR"Constructs a monochrome pixmap, with width \fIw\fR and height \fIh\fR, that is initialized with the data in \fIbits\fR. The \fIisXbitmap\fR indicates whether the data is an X bitmap and defaults to FALSE. This constructor is protected and used by the QBitmap class..SH "QPixmap::~QPixmap ()"Destroys the pixmap..SH "bool QPixmap::convertFromImage ( const QImage & img, int conversion_flags )"Converts image \fIimg\fR and sets this pixmap. Returns TRUE if successful; otherwise returns FALSE..PPThe \fIconversion_flags\fR argument is a bitwise-OR of the Qt::ImageConversionFlags. Passing 0 for \fIconversion_flags\fR sets all the default options..PPNote that even though a QPixmap with depth 1 behaves much like a QBitmap, isQBitmap() returns FALSE..PPIf a pixmap with depth 1 is painted with color0 and color1 and converted to an image, the pixels painted with color0 will produce pixel index 0 in the image and those painted with color1 will produce pixel index 1..PPSee also convertToImage(), isQBitmap(), QImage::convertDepth(), defaultDepth(), and QImage::hasAlphaBuffer()..PPExamples:.)l canvas/canvas.cpp and themes/wood.cpp..SH "bool QPixmap::convertFromImage ( const QImage & image, ColorMode mode = Auto )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPConverts \fIimage\fR and sets this pixmap using color mode \fImode\fR. Returns TRUE if successful; otherwise returns FALSE..PPSee also QPixmap::ColorMode..SH "QImage QPixmap::convertToImage () const"Converts the pixmap to a QImage. Returns a null image if it fails..PPIf the pixmap has 1-bit depth, the returned image will also be 1 bit deep. If the pixmap has 2- to 8-bit depth, the returned image has 8-bit depth. If the pixmap has greater than 8-bit depth, the returned image has 32-bit depth..PPNote that for the moment, alpha masks on monochrome images are ignored..PPSee also convertFromImage()..PPExample: qmag/qmag.cpp..SH "QBitmap QPixmap::createHeuristicMask ( bool clipTight = TRUE ) const"Creates and returns a heuristic mask for this pixmap. It works by selecting a color from one of the corners and then chipping away pixels of that color, starting at all the edges..PPThe mask may not be perfect but it should be reasonable, so you can do things such as the following:.PP.nf.br pm->setMask( pm->createHeuristicMask() );.br.fi.PPThis function is slow because it involves transformation to a QImage, non-trivial computations and a transformation back to a QBitmap..PPIf \fIclipTight\fR is TRUE the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels..PPSee also QImage::createHeuristicMask()..SH "int QPixmap::defaultDepth ()\fC [static]\fR"Returns the default pixmap depth, i.e. the depth a pixmap gets if -1 is specified..PPSee also depth()..SH "Optimization QPixmap::defaultOptimization ()\fC [static]\fR"Returns the default pixmap optimization setting..PPSee also setDefaultOptimization(), setOptimization(), and optimization()..SH "int QPixmap::depth () const"Returns the depth of the pixmap..PPThe pixmap depth is also called bits per pixel (bpp) or bit planes of a pixmap. A null pixmap has depth 0..PPSee also defaultDepth(), isNull(), and QImage::convertDepth()..SH "void QPixmap::detach ()\fC [virtual]\fR"This is a special-purpose function that detaches the pixmap from shared pixmap data..PPA pixmap is automatically detached by Qt whenever its contents is about to change. This is done in all QPixmap member functions that modify the pixmap (fill(), resize(), convertFromImage(), load(), etc.), in bitBlt() for the destination pixmap and in QPainter::begin() on a pixmap..PPIt is possible to modify a pixmap without letting Qt know. You can first obtain the system-dependent handle() and then call system-specific functions (for instance, BitBlt under Windows) that modify the pixmap contents. In such cases, you can call detach() to cut the pixmap loose from other pixmaps that share data with this one..PPdetach() returns immediately if there is just a single reference or if the pixmap has not been initialized yet..SH "void QPixmap::fill ( const QColor & fillColor = Qt::white )"Fills the pixmap with the color \fIfillColor\fR..PPExamples:.)l aclock/aclock.cpp, chart/setdataform.cpp, grapher/grapher.cpp, hello/hello.cpp, t10/cannon.cpp, themes/metal.cpp, and xform/xform.cpp..SH "void QPixmap::fill ( const QWidget * widget, int xofs, int yofs )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPFills the pixmap with the \fIwidget\fR's background color or pixmap. If the background is empty, nothing is done. \fIxofs\fR, \fIyofs\fR is an offset in the widget..SH "void QPixmap::fill ( const QWidget * widget, const QPoint & ofs )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPFills the pixmap with the \fIwidget\fR's background color or pixmap. If the background is empty, nothing is done..PPThe \fIofs\fR point is an offset in the widget..PPThe point \fIofs\fR is a point in the widget's coordinate system. The pixmap's top-left pixel will be mapped to the point \fIofs\fR in the widget. This is significant if the widget has a background pixmap; otherwise the pixmap will simply be filled with the background color of the widget..PPExample:.PP.nf.br void CuteWidget::paintEvent( QPaintEvent *e ).br {.br QRect ur = e->rect(); // rectangle to update.br QPixmap pix( ur.size() ); // Pixmap for double-buffering.br pix.fill( this, ur.topLeft() ); // fill with widget background.br.br QPainter p( &pix );.br p.translate( -ur.x(), -ur.y() ); // use widget coordinate system.br // when drawing on pixmap.br // ... draw on pixmap ....br.br p.end();.br.br bitBlt( this, ur.topLeft(), &pix );.br }.br.fi.SH "QPixmap QPixmap::fromMimeSource ( const QString & abs_name )\fC [static]\fR"Convenience function. Gets the data associated with the absolute name \fIabs_name\fR from the default mime source factory and decodes it to a pixmap..PPSee also QMimeSourceFactory, QImage::fromMimeSource(), and QImageDrag::decode()..PPExample: textedit/textedit.cpp..SH "QPixmap QPixmap::grabWidget ( QWidget * widget, int x = 0, int y = 0, int w = -1, int h = -1 )\fC [static]\fR"Creates a pixmap and paints \fIwidget\fR in it..PPIf the \fIwidget\fR has any children, then they are also painted in the appropriate positions..PPIf you specify \fIx\fR, \fIy\fR, \fIw\fR or \fIh\fR, only the rectangle you specify is painted. The defaults are 0, 0 (top-left corner) and -1,-1 (which means the entire widget)..PP(If \fIw\fR is negative, the function copies everything to the right border of the window. If \fIh\fR is negative, the function copies everything to the bottom of the window.).PPIf \fIwidget\fR is 0, or if the rectangle defined by \fIx\fR, \fIy\fR, the modified \fIw\fR and the modified \fIh\fR does not overlap the \fIwidget\fR->rect(), this function will return a null QPixmap..PPThis function actually asks \fIwidget\fR to paint itself (and its children to paint themselves). QPixmap::grabWindow() grabs pixels off the screen, which is a bit faster and picks up \fIexactly\fR what's on-screen. This function works by calling paintEvent() with painter redirection turned on. If there are overlaying windows, grabWindow() will see them, but not this function..PPIf there is overlap, it returns a pixmap of the size you want, containing a rendering of \fIwidget\fR. If the rectangle you ask for is a superset of \fIwidget\fR, the areas outside \fIwidget\fR are covered with the widget's background..PPIf an error occurs when trying to grab the widget, such as the size of the widget being too large to fit in memory, an isNull() pixmap is returned..PPSee also grabWindow(), QPainter::redirect(), and QWidget::paintEvent()..SH "QPixmap QPixmap::grabWindow ( WId window, int x = 0, int y = 0, int w = -1, int h = -1 )\fC [static]\fR"Grabs the contents of the window \fIwindow\fR and makes a pixmap out of it. Returns the pixmap..PPThe arguments \fI(x, y)\fR specify the offset in the window, whereas \fI(w, h)\fR specify the width and height of the area to be copied..PPIf \fIw\fR is negative, the function copies everything to the right border of the window. If \fIh\fR is negative, the function copies everything to the bottom of the window..PPNote that grabWindow() grabs pixels from the screen, not from the window. If there is another window partially or entirely over the one you grab, you get pixels from the overlying window, too..PPNote also that the mouse cursor is generally not grabbed..PPThe reason we use a window identifier and not a QWidget is to enable grabbing of windows that are not part of the application, window system frames, and so on..PP\fBWarning:\fR Grabbing an area outside the screen is not safe in general. This depends on the underlying window system..PP\fBWarning:\fR X11 only: If \fIwindow\fR is not the same depth as the root window and another window partially or entirely obscures the one you grab, you will \fInot\fR get pixels from the overlying window. The contests of the obscured areas in the pixmap are undefined and uninitialized..PPSee also grabWidget()..PPExample: qmag/qmag.cpp..SH "bool QPixmap::hasAlpha () const"Returns TRUE this pixmap has an alpha channel or a mask..PPSee also hasAlphaChannel() and mask()..SH "bool QPixmap::hasAlphaChannel () const"Returns TRUE if the pixmap has an alpha channel; otherwise it returns FALSE..PPNOTE: If the pixmap has a mask but not alpha channel, this function returns FALSE..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -