Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The TQPixmap class is an off-screen, pixel-based paint device. More...
#include <tqpixmap.h>
Inherits TQPaintDevice and TQt.
Inherited by TQBitmap and TQCanvasPixmap.
TQPixmap is one of the two classes TQt provides for dealing with images; the other is TQImage. TQPixmap is designed and optimized for drawing; TQImage is designed and optimized for I/O and for direct pixel access/manipulation. There are (slow) functions to convert between TQImage and TQPixmap: convertToImage() and convertFromImage().
One common use of the TQPixmap class is to enable smooth updating of widgets. Whenever something complex needs to be drawn, you can use a pixmap to obtain flicker-free drawing, like this:
Pixel data in a pixmap is internal and is managed by the underlying window system. Pixels can be accessed only through TQPainter functions, through bitBlt(), and by converting the TQPixmap to a TQImage.
You can easily display a TQPixmap on the screen using TQLabel::setPixmap(). For example, all the TQButton subclasses support pixmap use.
The TQPixmap class uses copy-on-write, so it is practical to pass TQPixmap objects by value.
You can retrieve the width(), height(), depth() and size() of a pixmap. The enclosing rectangle is given by rect(). Pixmaps can be filled with fill() and resized with resize(). You can create and set a mask with createHeuristicMask() and setMask(). Use selfMask() to see if the pixmap is identical to its mask.
In addition to loading a pixmap from file using load() you can also loadFromData(). You can control optimization with setOptimization() and obtain a transformed version of the pixmap using xForm()
Note regarding Windows 95 and 98: on Windows 9x the system crashes if you create more than about 1000 pixmaps, independent of the size of the pixmaps or installed RAM. Windows NT-systems (including 2000, XP and following versions) do not have the same limitation, but depending on the graphics equipment the system will fail to allocate pixmap objects at some point (due to system running out of GDI resources).
TQt tries to work around the resource limitation. If you set the pixmap optimization to TQPixmap::MemoryOptim and the width of your pixmap is less than or equal to 128 pixels, TQt stores the pixmap in a way that is very memory-efficient when there are many pixmaps.
If your application uses dozens or hundreds of pixmaps (for example on tool bar buttons and in popup menus), and you plan to run it on Windows 95 or Windows 98, we recommend using code like this:
TQPixmap::setDefaultOptimization( TQPixmap::MemoryOptim ); while ( ... ) { // load tool bar pixmaps etc. TQPixmap *pixmap = new TQPixmap(fileName); } TQPixmap::setDefaultOptimization( TQPixmap::NormalOptim );
In general it is recommended to make as much use of TQPixmap's implicit sharing and the TQPixmapCache as possible.
See also TQBitmap, TQImage, TQImageIO, Shared Classes, Graphics Classes, Image Processing Classes, and Implicitly and Explicitly Shared Classes.
This enum type defines the color modes that exist for converting TQImage objects to TQPixmap.
TQPixmap 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:
We recommend using DefaultOptim.
See also isNull().
See also convertFromImage().
The contents of the pixmap is uninitialized.
The depth can be either 1 (monochrome) or the depth of the current video mode. If depth is negative, then the hardware depth of the current video mode will be used.
If either w or h is zero, a null pixmap is constructed.
See also isNull() and TQPixmap::Optimization.
Constructs a pixmap of size size, depth bits per pixel, optimized in accordance with the optimization value.
The fileName, format and mode parameters are passed on to load(). This means that the data in fileName is not compiled into the binary. If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.
See also TQPixmap::ColorMode, isNull(), load(), loadFromData(), save(), and imageFormat().
The fileName, format and conversion_flags parameters are passed on to load(). This means that the data in fileName is not compiled into the binary. If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.
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 conversion_flags to specify how you'd prefer this to happen.
See also TQt::ImageConversionFlags, isNull(), load(), loadFromData(), save(), and imageFormat().
Errors are silently ignored.
Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:
static const char * const start_xpm[]={ "16 15 8 1", "a c #cec6bd", ....
The extra const 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.
In order to use that sort of declaration you must cast the variable back to const char ** when you create the TQPixmap.
See also loadFromData().
The conversion_flags argument is a bitwise-OR of the TQt::ImageConversionFlags. Passing 0 for conversion_flags sets all the default options.
Note that even though a TQPixmap with depth 1 behaves much like a TQBitmap, isTQBitmap() returns FALSE.
If 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.
See also convertToImage(), isTQBitmap(), TQImage::convertDepth(), defaultDepth(), and TQImage::hasAlphaBuffer().
Examples: canvas/canvas.cpp and themes/wood.cpp.
Converts image and sets this pixmap using color mode mode. Returns TRUE if successful; otherwise returns FALSE.
See also TQPixmap::ColorMode.
If 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.
Note that for the moment, alpha masks on monochrome images are ignored.
See also convertFromImage().
Example: qmag/qmag.cpp.
The mask may not be perfect but it should be reasonable, so you can do things such as the following:
pm->setMask( pm->createHeuristicMask() );
This function is slow because it involves transformation to a TQImage, non-trivial computations and a transformation back to a TQBitmap.
If clipTight is TRUE the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels.
See also TQImage::createHeuristicMask().
See also depth().
See also setDefaultOptimization(), setOptimization(), and optimization().
Returns the depth of the pixmap.
The pixmap depth is also called bits per pixel (bpp) or bit planes of a pixmap. A null pixmap has depth 0.
See also defaultDepth(), isNull(), and TQImage::convertDepth().
A pixmap is automatically detached by TQt whenever its contents is about to change. This is done in all TQPixmap member functions that modify the pixmap (fill(), resize(), convertFromImage(), load(), etc.), in bitBlt() for the destination pixmap and in TQPainter::begin() on a pixmap.
It is possible to modify a pixmap without letting TQt 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.
detach() returns immediately if there is just a single reference or if the pixmap has not been initialized yet.
Examples: chart/setdataform.cpp, desktop/desktop.cpp, hello/hello.cpp, t10/cannon.cpp, themes/metal.cpp, and xform/xform.cpp.
Fills the pixmap with the widget's background color or pixmap. If the background is empty, nothing is done. xofs, yofs is an offset in the widget.
Fills the pixmap with the widget's background color or pixmap. If the background is empty, nothing is done.
The ofs point is an offset in the widget.
The point ofs is a point in the widget's coordinate system. The pixmap's top-left pixel will be mapped to the point ofs 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.
Example:
void CuteWidget::paintEvent( TQPaintEvent *e ) { TQRect ur = e->rect(); // rectangle to update TQPixmap pix( ur.size() ); // Pixmap for double-buffering pix.fill( this, ur.topLeft() ); // fill with widget background TQPainter p( &pix ); p.translate( -ur.x(), -ur.y() ); // use widget coordinate system // when drawing on pixmap // ... draw on pixmap ... p.end(); bitBlt( this, ur.topLeft(), &pix ); }
See also TQMimeSourceFactory, TQImage::fromMimeSource(), and TQImageDrag::decode().
Example: textedit/textedit.cpp.
If the widget has any children, then they are also painted in the appropriate positions.
If you specify x, y, w or h, only the rectangle you specify is painted. The defaults are 0, 0 (top-left corner) and -1,-1 (which means the entire widget).
(If w is negative, the function copies everything to the right border of the window. If h is negative, the function copies everything to the bottom of the window.)
If widget is 0, or if the rectangle defined by x, y, the modified w and the modified h does not overlap the widget->rect(), this function will return a null TQPixmap.
This function actually asks widget to paint itself (and its children to paint themselves). TQPixmap::grabWindow() grabs pixels off the screen, which is a bit faster and picks up exactly 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.
If there is overlap, it returns a pixmap of the size you want, containing a rendering of widget. If the rectangle you ask for is a superset of widget, the areas outside widget are covered with the widget's background.
If 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.
See also grabWindow(), TQPainter::redirect(), and TQWidget::paintEvent().
The arguments (x, y) specify the offset in the window, whereas (w, h) specify the width and height of the area to be copied.
If w is negative, the function copies everything to the right border of the window. If h is negative, the function copies everything to the bottom of the window.
Note 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.
Note also that the mouse cursor is generally not grabbed.
The reason we use a window identifier and not a TQWidget is to enable grabbing of windows that are not part of the application, window system frames, and so on.
Warning: Grabbing an area outside the screen is not safe in general. This depends on the underlying window system.
Warning: X11 only: If window is not the same depth as the root window and another window partially or entirely obscures the one you grab, you will not get pixels from the overlying window. The contests of the obscured areas in the pixmap are undefined and uninitialized.
See also grabWidget().
Example: qmag/qmag.cpp.
See also hasAlphaChannel() and mask().
NOTE: If the pixmap has a mask but not alpha channel, this function returns FALSE.
See also hasAlpha() and mask().
Returns the height of the pixmap.
See also width(), size(), and rect().
Examples: desktop/desktop.cpp, movies/main.cpp, scribble/scribble.cpp, scrollview/scrollview.cpp, t10/cannon.cpp, and xform/xform.cpp.
The TQImageIO documentation lists the supported image formats.
Returns TRUE if this is a null pixmap; otherwise returns FALSE.
A null pixmap has zero width, zero height and no contents. You cannot draw in a null pixmap or bitBlt() anything to it.
Resizing an existing pixmap to (0, 0) makes a pixmap into a null pixmap.
See also resize().
Examples: movies/main.cpp, tqdir/tqdir.cpp, qmag/qmag.cpp, and scrollview/scrollview.cpp.
Returns TRUE if this is a TQBitmap; otherwise returns FALSE.
If format is specified, the loader attempts to read the pixmap using the specified format. If format is not specified (default), the loader reads a few bytes from the header to guess the file's format.
See the convertFromImage() documentation for a description of the conversion_flags argument.
The TQImageIO documentation lists the supported image formats and explains how to add extra formats.
See also loadFromData(), save(), imageFormat(), TQImage::load(), and TQImageIO.
Examples: picture/picture.cpp, scrollview/scrollview.cpp, and xform/xform.cpp.
Loads a pixmap from the file fileName at runtime.
If format is specified, the loader attempts to read the pixmap using the specified format. If format is not specified (default), the loader reads a few bytes from the header to guess the file's format.
The mode is used to specify the color mode of the pixmap.
See also TQPixmap::ColorMode.
If format is specified, the loader attempts to read the pixmap using the specified format. If format is not specified (default), the loader reads a few bytes from the header to guess the file's format.
See the convertFromImage() documentation for a description of the conversion_flags argument.
The TQImageIO documentation lists the supported image formats and explains how to add extra formats.
See also load(), save(), imageFormat(), TQImage::loadFromData(), and TQImageIO.
Loads a pixmap from the binary data in buf (len bytes) using color mode mode. Returns TRUE if successful; otherwise returns FALSE.
If format is specified, the loader attempts to read the pixmap using the specified format. If format is not specified (default), the loader reads a few bytes from the header to guess the file's format.
See also TQPixmap::ColorMode.
Returns the mask bitmap, or 0 if no mask has been set.
See also setMask(), TQBitmap, and hasAlpha().
Use the TQPaintDeviceMetrics class instead.
m is the metric to get.
Converts the image image to a pixmap that is assigned to this pixmap. Returns a reference to the pixmap.
See also convertFromImage().
Returns the optimization setting for this pixmap.
The default optimization setting is TQPixmap::NormalOptim. You can change this setting in two ways:
See also setOptimization(), setDefaultOptimization(), and defaultOptimization().
Returns the enclosing rectangle (0,0,width(),height()) of the pixmap.
See also width(), height(), and size().
If both w and h are greater than 0, a valid pixmap is created. New pixels will be uninitialized (random) if the pixmap is expanded.
Examples: desktop/desktop.cpp.
Resizes the pixmap to size size.
See also load(), loadFromData(), imageFormat(), TQImage::save(), and TQImageIO.
Example: qmag/qmag.cpp.
This function writes a TQPixmap to the TQIODevice, device. This can be used, for example, to save a pixmap directly into a TQByteArray:
TQPixmap pixmap; TQByteArray ba; TQBuffer buffer( ba ); buffer.open( IO_WriteOnly ); pixmap.save( &buffer, "PNG" ); // writes pixmap into ba in PNG format
Returns TRUE if the pixmap's mask is identical to the pixmap itself; otherwise returns FALSE.
See also mask().
Returns a number that uniquely identifies the contents of this TQPixmap object. This means that multiple TQPixmap objects can have the same serial number as long as they refer to the same contents.
An example of where this is useful is for caching TQPixmaps.
See also TQPixmapCache.
All new pixmaps that are created will use this default optimization. You may also set optimization for individual pixmaps using the setOptimization() function.
The initial default optimization setting is TQPixmap::Normal.
See also defaultOptimization(), setOptimization(), and optimization().
The newmask bitmap defines the clip mask for this pixmap. Every pixel in newmask 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.
Warning: Setting the mask on a pixmap will cause any alpha channel data to be cleared. For example:
TQPixmap alpha( "image-with-alpha.png" ); TQPixmap alphacopy = alpha; alphacopy.setMask( *alphacopy.mask() );Now, alpha and alphacopy are visually different.
Setting a null mask resets the mask.
See also mask(), createHeuristicMask(), and TQBitmap.
The optimization setting affects pixmap operations, in particular drawing of transparent pixmaps (bitBlt() a pixmap with a mask set) and pixmap transformations (the xForm() function).
Pixmap optimization involves keeping intermediate results in a cache buffer and using the cache to speed up bitBlt() and xForm(). The cost is more memory consumption, up to twice as much as an unoptimized pixmap.
Use the setDefaultOptimization() to change the default optimization for all new pixmaps.
See also optimization(), setDefaultOptimization(), and defaultOptimization().
Example: desktop/desktop.cpp.
Returns the size of the pixmap.
See also width(), height(), and rect().
Example: movies/main.cpp.
When 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.
This function returns the modified matrix, which maps points correctly from the original pixmap into the new pixmap.
See also xForm() and TQWMatrix.
Returns the width of the pixmap.
See also height(), size(), and rect().
Examples: desktop/desktop.cpp, movies/main.cpp, scribble/scribble.cpp, scrollview/scrollview.cpp, and xform/xform.cpp.
The transformation matrix 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.
This function is slow because it involves transformation to a TQImage, non-trivial computations and a transformation back to a TQPixmap.
See also trueMatrix(), TQWMatrix, TQPainter::setWorldMatrix(), and TQImage::xForm().
Examples: desktop/desktop.cpp, fileiconview/tqfileiconview.cpp, movies/main.cpp, and qmag/qmag.cpp.
Copies a block of pixels from src to dst. The alpha channel and mask data (if any) is also copied from src. NOTE: src is not alpha blended or masked when copied to dst. Use bitBlt() or TQPainter::drawPixmap() to perform alpha blending or masked drawing.
sx, sy is the top-left pixel in src (0, 0 by default), dx, dy is the top-left position in dst and sw, \sh is the size of the copied block (all of src by default).
If src, dst, sw or sh is 0 (zero), copyBlt() does nothing. If sw or sh is negative, copyBlt() copies starting at sx (and respectively, sy) and ending at the right edge (and respectively, the bottom edge) of src.
copyBlt() does nothing if src and dst have different depths.
Writes the pixmap pixmap to the stream s as a PNG image.
Note that writing the stream to a file will not produce a valid image file.
See also TQPixmap::save() and Format of the TQDataStream operators.
Reads a pixmap from the stream s into the pixmap pixmap.
See also TQPixmap::load() and Format of the TQDataStream operators.
This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.
Copyright © 2007 Trolltech | Trademarks | TQt 3.3.8
|