|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QPixmap
public class QPixmap
The QPixmap class is an off-screen image representation that can be used as a paint device.
Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. The isQBitmap function returns true if a QPixmap object is really a bitmap, otherwise returns false. Finally, the QPicture class is a paint device that records and replays QPainter commands.
A QPixmap can easily be displayed on the screen using QLabel or one of QAbstractButton's subclasses (such as QPushButton and QToolButton). QLabel has a pixmap property, whereas QAbstractButton has an icon property. And because QPixmap is a QPaintDevice subclass, QPainter can be used to draw directly onto pixmaps.
In addition to the ordinary constructors, a QPixmap can be constructed using the static grabWidget and grabWindow functions which creates a QPixmap and paints the given widget, or window, in it.
Note that the pixel data in a pixmap is internal and is managed by the underlying window system. Pixels can only be accessed through QPainter functions or by converting the QPixmap to a QImage. Depending on the system, QPixmap is stored using a RGB32 or a premultiplied alpha format. If the image has an alpha channel, and if the system allows, the preferred format is premultiplied alpha. Note also that QPixmap, unlike QImage, may be hardware dependent. On X11 and Mac, a QPixmap is stored on the server side while a QImage is stored on the client side (on Windows, these two classes have an equivalent internal representation, i.e. both QImage and QPixmap are stored on the client side and don't use any GDI resources).
There are functions to convert between QImage and QPixmap. Typically, the QImage class is used to load an image file, optionally manipulating the image data, before the QImage object is converted into a QPixmap to be shown on screen. Alternatively, if no manipulation is desired, the image file can be loaded directly into a QPixmap. On Windows, the QPixmap class also supports conversion between HBITMAP and QPixmap.
QPixmap provides a collection of functions that can be used to obtain a variety of information about the pixmap. In addition, there are several functions that enables transformation of the pixmap.
QPixmap objects can be passed around by value since the QPixmap class uses implicit data sharing. For more information, see the Implicit Data Sharing documentation. QPixmap objects can also be streamed.
QPixmap provides several ways of reading an image file: The file can be loaded when constructing the QPixmap object, or by using the load() or loadFromData() functions later on. When loading an image, the file name can either refer to an actual file on disk or to one of the application's embedded resources. See The Qt Resource System overview for details on how to embed images and other resource files in the application's executable.
Simply call the save() function to save a QPixmap object.
The complete list of supported file formats are available through the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions. New file formats can be added as plugins. By default, Qt supports the following formats:
Format | Description | Qt's support |
---|---|---|
BMP | Windows Bitmap | Read/write |
GIF | Graphic Interchange Format (optional) | Read |
JPG | Joint Photographic Experts Group | Read/write |
JPEG | Joint Photographic Experts Group | Read/write |
PNG | Portable Network Graphics | Read/write |
PBM | Portable Bitmap | Read |
PGM | Portable Graymap | Read |
PPM | Portable Pixmap | Read/write |
XBM | X11 Bitmap | Read/write |
XPM | X11 Pixmap | Read/write |
(To configure Qt with GIF support, pass -qt-gif to the configure script or check the appropriate option in the graphical installer.)
QPixmap provides a collection of functions that can be used to obtain a variety of information about the pixmap:
Available Functions | |
---|---|
Geometry | The size, width and height functions provide information about the pixmap's size. The rect function returns the image's enclosing rectangle. |
Alpha component | The hasAlphaChannel returns true if the pixmap has a format that respects the alpha channel, otherwise returns false, while the hasAlpha function returns true if the pixmap has an alpha channel or a mask (otherwise false). The alphaChannel function returns the alpha channel as a new QPixmap object, while the mask function returns the mask as a QBitmap object. The alpha channel and mask can be set using the setAlphaChannel and setMask functions, respectively. |
Low-level information | The depth function returns the depth of the pixmap. The defaultDepth function returns the default depth, i.e. the depth used by the application on the given screen. The cacheKey function returns a number that uniquely identifies the contents of the QPixmap object. The x11Info() function returns information about the configuration of the X display used to display the widget. The x11PictureHandle() function returns the X11 Picture handle of the pixmap for XRender support. Note that the two latter functions are only available on x11. |
A QPixmap object can be converted into a QImage using the toImage function. Likewise, a QImage can be converted into a QPixmap using the fromImage. If this is too expensive an operation, you can use QBitmap::fromImage() instead.
In addition, on Windows, the QPixmap class supports conversion to and from HBitmap: the toWinHBITMAP() function creates a HBITMAP equivalent to the QPixmap, based on the given HBitmapFormat, and returns the HBITMAP handle. The fromWinHBITMAP() function returns a QPixmap that is equivalent to the given bitmap which has the specified format.
QPixmap supports a number of functions for creating a new pixmap that is a transformed version of the original: The createHeuristicMask function creates and returns a 1-bpp heuristic mask (i.e. a QBitmap) 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. The createMaskFromColor function creates and returns a mask (i.e. a QBitmap) for the pixmap based on a given color.
The scaled, scaledToWidth and scaledToHeight functions return scaled copies of the pixmap, while the copy function creates a QPixmap that is a plain copy of the original one.
The transformed function returns a copy of the pixmap that is transformed with the given transformation matrix and transformation mode: Internally, the transformation matrix is adjusted to compensate for unwanted translation, i.e. transformed returns the smallest pixmap containing all transformed points of the original pixmap. The static trueMatrix function returns the actual matrix used for transforming the pixmap.
There are also functions for changing attributes of a pixmap. in-place: The fill function fills the entire image with the given color, the setMask function sets a mask bitmap, and the setAlphaChannel function sets the pixmap's alpha channel.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Constructor Summary | |
---|---|
QPixmap()
Constructs a null pixmap. |
|
QPixmap(int w,
int h)
Constructs a pixmap with the given w and h. |
|
QPixmap(QPixmap arg__1)
Constructs a pixmap that is a copy of the given arg__1. |
|
QPixmap(QSize arg__1)
Constructs a pixmap of the given arg__1. |
|
QPixmap(java.lang.String fileName)
This is an overloaded constructor provided for convenience. |
|
QPixmap(java.lang.String[] xpm)
Constructs a pixmap from the given xpm data, which must be a valid XPM image. |
|
QPixmap(java.lang.String fileName,
java.lang.String format)
This is an overloaded constructor provided for convenience. |
|
QPixmap(java.lang.String fileName,
java.lang.String format,
Qt.ImageConversionFlag... flags)
This is an overloaded constructor provided for convenience. |
|
QPixmap(java.lang.String fileName,
java.lang.String format,
Qt.ImageConversionFlags flags)
Constructs a pixmap from the file with the given fileName. |
Method Summary | |
---|---|
QPixmap |
alphaChannel()
Returns the alpha channel of the pixmap as a new grayscale QPixmap in which each pixel's red, green, and blue values are given the alpha value of the original pixmap. |
long |
cacheKey()
Returns a number that identifies this QPixmap. |
QPixmap |
copy()
Equivalent to copy(QRect()). |
QPixmap |
copy(int x,
int y,
int width,
int height)
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x, y, width, height). |
QPixmap |
copy(QRect rect)
Returns a deep copy of the subset of the pixmap that is specified by the given rect. |
QBitmap |
createHeuristicMask()
Equivalent to createHeuristicMask(true). |
QBitmap |
createHeuristicMask(boolean clipTight)
Creates and returns a heuristic mask for this pixmap. |
QBitmap |
createMaskFromColor(QColor maskColor)
Creates and returns a mask for this pixmap based on the given maskColor. |
QBitmap |
createMaskFromColor(QColor maskColor,
Qt.MaskMode mode)
Creates and returns a mask for this pixmap based on the given maskColor. |
static int |
defaultDepth()
Returns the default pixmap depth used by the application. |
int |
depth()
Returns the depth of the pixmap. |
int |
devType()
|
void |
fill()
Equivalent to fill(Qt::white). |
void |
fill(QColor fillColor)
Fills the pixmap with the given fillColor. |
void |
fill(QWidget widget,
int xofs,
int yofs)
Fills the pixmap with the widget's background color or pixmap. |
void |
fill(QWidget widget,
QPoint ofs)
Fills the pixmap with the widget's background color or pixmap according to the given offset. |
static QPixmap |
fromImage(QImage image)
Equivalent to fromImage(image, Qt::AutoColor). |
static QPixmap |
fromImage(QImage image,
Qt.ImageConversionFlag... flags)
Converts the given image to a pixmap using the specified flags to control the conversion. |
static QPixmap |
fromImage(QImage image,
Qt.ImageConversionFlags flags)
Converts the given image to a pixmap using the specified flags to control the conversion. |
static QPixmap |
fromNativePointer(QNativePointer nativePointer)
This function returns the QPixmap instance pointed to by nativePointer |
static QPixmap |
grabWidget(QWidget widget)
Equivalent to grabWidget(widget, 0, 0, -1, -1). |
static QPixmap |
grabWidget(QWidget widget,
int x)
Equivalent to grabWidget(widget, x, 0, -1, -1). |
static QPixmap |
grabWidget(QWidget widget,
int x,
int y)
Equivalent to grabWidget(widget, x, y, -1, -1). |
static QPixmap |
grabWidget(QWidget widget,
int x,
int y,
int w)
Equivalent to grabWidget(widget, x, y, w, -1). |
static QPixmap |
grabWidget(QWidget widget,
int x,
int y,
int w,
int h)
Creates a pixmap and paints the given widget, restricted by QRect(x, y, w, h), in it. |
static QPixmap |
grabWidget(QWidget widget,
QRect rect)
Creates a pixmap and paints the given widget, restricted by the given rect, in it. |
static QPixmap |
grabWindow(long arg__1)
Equivalent to grabWindow(arg__1, 0, 0, -1, -1). |
static QPixmap |
grabWindow(long arg__1,
int x)
Equivalent to grabWindow(arg__1, x, 0, -1, -1). |
static QPixmap |
grabWindow(long arg__1,
int x,
int y)
Equivalent to grabWindow(arg__1, x, y, -1, -1). |
static QPixmap |
grabWindow(long arg__1,
int x,
int y,
int w)
Equivalent to grabWindow(arg__1, x, y, w, -1). |
static QPixmap |
grabWindow(long arg__1,
int x,
int y,
int w,
int h)
Creates and returns a pixmap constructed by grabbing the contents of the given arg__1 restricted by QRect(x, y, w, h). |
boolean |
hasAlpha()
Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false. |
boolean |
hasAlphaChannel()
Returns true if the pixmap has a format that respects the alpha channel, otherwise returns false. |
int |
height()
Returns the height of the pixmap. |
int |
heightMM()
Returns the height of the paint device in millimeters. |
boolean |
isNull()
Returns true if this is a null pixmap; otherwise returns false. |
boolean |
isQBitmap()
Returns true if this is a QBitmap; otherwise returns false. |
boolean |
load(java.lang.String fileName)
This is an overloaded method provided for convenience. |
boolean |
load(java.lang.String fileName,
java.lang.String format)
This is an overloaded method provided for convenience. |
boolean |
load(java.lang.String fileName,
java.lang.String format,
Qt.ImageConversionFlag... flags)
This is an overloaded method provided for convenience. |
boolean |
load(java.lang.String fileName,
java.lang.String format,
Qt.ImageConversionFlags flags)
Loads a pixmap from the file with the given fileName. |
boolean |
loadFromData(byte[] data)
This is an overloaded method provided for convenience. |
boolean |
loadFromData(byte[] data,
java.lang.String format)
This is an overloaded method provided for convenience. |
boolean |
loadFromData(byte[] data,
java.lang.String format,
Qt.ImageConversionFlag... flags)
This is an overloaded method provided for convenience. |
boolean |
loadFromData(byte[] data,
java.lang.String format,
Qt.ImageConversionFlags flags)
Loads a pixmap from the binary data. |
boolean |
loadFromData(QByteArray data)
This is an overloaded method provided for convenience. |
boolean |
loadFromData(QByteArray data,
java.lang.String format)
This is an overloaded method provided for convenience. |
boolean |
loadFromData(QByteArray data,
java.lang.String format,
Qt.ImageConversionFlag... flags)
This is an overloaded method provided for convenience. |
boolean |
loadFromData(QByteArray data,
java.lang.String format,
Qt.ImageConversionFlags flags)
Loads a pixmap from the binary data using the specified format and conversion flags. |
int |
logicalDpiX()
Returns the horizontal resolution of the device in dots per inch, which is used when computing font sizes. |
int |
logicalDpiY()
Returns the vertical resolution of the device in dots per inch, which is used when computing font sizes. |
QBitmap |
mask()
Returns the mask, or a null bitmap if no mask has been set. |
int |
metric(QPaintDevice.PaintDeviceMetric arg__1)
Returns the metric information for the given paint device arg__1. |
static QNativePointer |
nativePointerArray(QPixmap[] array)
This function returns a QNativePointer that is pointing to the specified QPixmap array. |
int |
numColors()
Returns the number of different colors available for the paint device. |
QPaintEngine |
paintEngine()
Returns a pointer to the paint engine used for drawing on the device. |
boolean |
paintingActive()
Returns true if the device is currently being painted on, i.e. someone has called QPainter::begin() but not yet called QPainter::end() for this device; otherwise returns false. |
int |
physicalDpiX()
Returns the horizontal resolution of the device in dots per inch. |
int |
physicalDpiY()
Returns the horizontal resolution of the device in dots per inch. |
void |
readFrom(QDataStream arg__1)
Reads a QPixmap from arg__1. |
QRect |
rect()
Returns the pixmap's enclosing rectangle. |
boolean |
save(QIODevice dev)
This is an overloaded method provided for convenience. |
boolean |
save(QIODevice dev,
java.lang.String format)
This is an overloaded method provided for convenience. |
boolean |
save(QIODevice dev,
java.lang.String format,
int quality)
This function writes a QPixmap to the given dev using the specified image file format and quality factor. |
boolean |
save(java.lang.String fileName)
This is an overloaded method provided for convenience. |
boolean |
save(java.lang.String fileName,
java.lang.String format)
This is an overloaded method provided for convenience. |
boolean |
save(java.lang.String fileName,
java.lang.String format,
int quality)
Saves the pixmap to the file with the given fileName using the specified image file format and quality factor. |
QPixmap |
scaled(int w,
int h)
Equivalent to scaled(w, h, Qt::IgnoreAspectRatio, Qt::FastTransformation). |
QPixmap |
scaled(int w,
int h,
Qt.AspectRatioMode aspectMode)
Equivalent to scaled(w, h, aspectMode, Qt::FastTransformation). |
QPixmap |
scaled(int w,
int h,
Qt.AspectRatioMode aspectMode,
Qt.TransformationMode mode)
Returns a copy of the pixmap scaled to a rectangle with the given w and h according to the given aspectMode and mode. |
QPixmap |
scaled(QSize s)
Equivalent to scaled(s, Qt::IgnoreAspectRatio, Qt::FastTransformation). |
QPixmap |
scaled(QSize s,
Qt.AspectRatioMode aspectMode)
Equivalent to scaled(s, aspectMode, Qt::FastTransformation). |
QPixmap |
scaled(QSize s,
Qt.AspectRatioMode aspectMode,
Qt.TransformationMode mode)
Scales the pixmap to the given s, using the aspect ratio and transformation modes specified by aspectMode and mode. |
QPixmap |
scaledToHeight(int h)
Equivalent to scaledToHeight(h, Qt::FastTransformation). |
QPixmap |
scaledToHeight(int h,
Qt.TransformationMode mode)
Returns a scaled copy of the image. |
QPixmap |
scaledToWidth(int w)
Equivalent to scaledToWidth(w, Qt::FastTransformation). |
QPixmap |
scaledToWidth(int w,
Qt.TransformationMode mode)
Returns a scaled copy of the image. |
void |
setAlphaChannel(QPixmap arg__1)
Sets the alpha channel of this pixmap to the given arg__1 by converting the arg__1 into 32 bit and using the intensity of the RGB pixel values. |
void |
setMask(QBitmap arg__1)
Sets a mask bitmap. |
QSize |
size()
Returns the size of the pixmap. |
QImage |
toImage()
Converts the pixmap to a QImage. |
QPixmap |
transformed(QMatrix arg__1,
Qt.TransformationMode mode)
This convenience function loads the arg__1 into a QTransform and calls the overloaded function. |
QPixmap |
transformed(QTransform arg__1,
Qt.TransformationMode mode)
Returns a copy of the pixmap that is transformed using the given transformation arg__1 and transformation mode. |
static QMatrix |
trueMatrix(QMatrix m,
int w,
int h)
This convenience function loads the matrix m into a QTransform and calls the overloaded function with the QTransform and the width w and the height h. |
static QTransform |
trueMatrix(QTransform m,
int w,
int h)
Returns the actual matrix used for transforming a pixmap with the given w, h and m. |
int |
width()
Returns the width of the pixmap. |
int |
widthMM()
Returns the width of the paint device in millimeters. |
void |
writeTo(QDataStream arg__1)
Writes thisQPixmap to arg__1. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QPixmap(int w, int h)
Constructs a pixmap with the given w and h.
The content of the pixmap is uninitialized. If either w or h is zero, a null pixmap is constructed.
public QPixmap(QPixmap arg__1)
Constructs a pixmap that is a copy of the given arg__1.
public QPixmap(QSize arg__1)
Constructs a pixmap of the given arg__1.
public QPixmap()
Constructs a null pixmap.
public QPixmap(java.lang.String[] xpm)
Errors are silently ignored.
public QPixmap(java.lang.String fileName, java.lang.String format, Qt.ImageConversionFlags flags)
The loader attempts to read the pixmap using the specified format. If the format is not specified (which is the default), the loader probes the file for a header to guess the file format.
The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the \l{resources.html}{Resource System} overview for details on how to embed images and other resource files in the application's executable.
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 flags to control the conversion.
The fileName, format and 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.
public QPixmap(java.lang.String fileName, java.lang.String format, Qt.ImageConversionFlag... flags)
public QPixmap(java.lang.String fileName, java.lang.String format)
public QPixmap(java.lang.String fileName)
Method Detail |
---|
public final QPixmap alphaChannel()
Returns the alpha channel of the pixmap as a new grayscale QPixmap in which each pixel's red, green, and blue values are given the alpha value of the original pixmap. The color depth of the returned pixmap is the system depth on X11 and 8-bit on Windows and Mac OS X.
You can use this function while debugging to get a visible image of the alpha channel. If the pixmap doesn't have an alpha channel, i.e., the alpha channel's value for all pixels equals 0xff), a null pixmap is returned. You can check this with the isNull() function.
We show an example:
pixmap = QPixmap(100, 100); pixmap.fill(Qt::transparent); QRadialGradient gradient(50, 50, 50, 50, 50); gradient.setColorAt(0, QColor::fromRgbF(1, 0, 0, 1)); gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0)); QPainter painter(&pixmap); painter.fillRect(0, 0, 100, 100, gradient); channelImage = pixmap.alphaChannel(); update();
Information
public final long cacheKey()
Returns a number that identifies this QPixmap. Distinct QPixmap objects can only have the same cache key if they refer to the same contents.
The cacheKey will change when the pixmap is altered.
public final QPixmap copy(int x, int y, int width, int height)
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x, y, width, height).
public final QPixmap copy()
Equivalent to copy(QRect()).
public final QPixmap copy(QRect rect)
Returns a deep copy of the subset of the pixmap that is specified by the given rect. For more information on deep copies, see the Implicit Data Sharing documentation.
If the given rect is empty, the whole image is copied.
Transformations
public final QBitmap createHeuristicMask()
Equivalent to createHeuristicMask(true).
public final QBitmap createHeuristicMask(boolean clipTight)
Creates and returns a heuristic mask for this pixmap.
The function works by selecting a color from one of the corners and then chipping away pixels of that color, starting at all the edges. If clipTight is true (the default) the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels.
The mask may not be perfect but it should be reasonable, so you can do things such as the following:
QPixmap myPixmap; myPixmap->setMask(myPixmap->createHeuristicMask());
This function is slow because it involves converting to/from a QImage, and non-trivial computations.
public final QBitmap createMaskFromColor(QColor maskColor)
Creates and returns a mask for this pixmap based on the given maskColor. Same as calling createMaskFromColor(maskColor, Qt::MaskInColor)
public final QBitmap createMaskFromColor(QColor maskColor, Qt.MaskMode mode)
Creates and returns a mask for this pixmap based on the given maskColor. If the mode is Qt::MaskInColor, all pixels matching the maskColor will be opaque. If mode is Qt::MaskOutColor, all pixels matching the maskColor will be transparent.
This function is slow because it involves converting to/from a QImage.
public final int depth()
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.
depth
in interface QPaintDeviceInterface
Information
public final void fill()
Equivalent to fill(Qt::white).
public final void fill(QColor fillColor)
Fills the pixmap with the given fillColor.
Transformations
public final void fill(QWidget widget, int xofs, int yofs)
Fills the pixmap with the widget's background color or pixmap. The given point, (xofs, yofs), defines an offset in widget coordinates to which the pixmap's top-left pixel will be mapped to.
public final void fill(QWidget widget, QPoint ofs)
Fills the pixmap with the widget's background color or pixmap according to the given offset.
The QPoint ofs defines a point in widget coordinates to which the pixmap's top-left pixel will be mapped to. This is only significant if the widget has a background pixmap; otherwise the pixmap will simply be filled with the background color of the widget.
public final boolean hasAlpha()
Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false.
public final boolean hasAlphaChannel()
Returns true if the pixmap has a format that respects the alpha channel, otherwise returns false.
public final int height()
Returns the height of the pixmap.
height
in interface QPaintDeviceInterface
Information
public final int heightMM()
Returns the height of the paint device in millimeters.
heightMM
in interface QPaintDeviceInterface
public final boolean isNull()
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.
public final boolean isQBitmap()
Returns true if this is a QBitmap; otherwise returns false.
public final int logicalDpiX()
Returns the horizontal resolution of the device in dots per inch, which is used when computing font sizes. For X11, this is usually the same as could be computed from widthMM, but it varies on Windows.
Note that if the logicalDpiX doesn't equal the physicalDpiX, the corresponding QPaintEngine must handle the resolution mapping.
logicalDpiX
in interface QPaintDeviceInterface
public final int logicalDpiY()
Returns the vertical resolution of the device in dots per inch, which is used when computing font sizes. For X11, this is usually the same as could be computed from heightMM, but it varies on Windows.
Note that if the logicalDpiY doesn't equal the physicalDpiY, the corresponding QPaintEngine must handle the resolution mapping.
logicalDpiY
in interface QPaintDeviceInterface
public final QBitmap mask()
Returns the mask, or a null bitmap if no mask has been set.
Information
public final int numColors()
Returns the number of different colors available for the paint device. Since this value is an int, it will not be sufficient to represent the number of colors on 32 bit displays, in this case INT_MAX is returned instead.
numColors
in interface QPaintDeviceInterface
public final void writeTo(QDataStream arg__1)
public final void readFrom(QDataStream arg__1)
public final boolean paintingActive()
Returns true if the device is currently being painted on, i.e. someone has called QPainter::begin() but not yet called QPainter::end() for this device; otherwise returns false.
paintingActive
in interface QPaintDeviceInterface
public final int physicalDpiX()
Returns the horizontal resolution of the device in dots per inch.
Note that if the physicalDpiX doesn't equal the logicalDpiX, the corresponding QPaintEngine must handle the resolution mapping.
physicalDpiX
in interface QPaintDeviceInterface
public final int physicalDpiY()
Returns the horizontal resolution of the device in dots per inch.
Note that if the physicalDpiY doesn't equal the logicalDpiY, the corresponding QPaintEngine must handle the resolution mapping.
physicalDpiY
in interface QPaintDeviceInterface
public final QRect rect()
Returns the pixmap's enclosing rectangle.
Information
public final QPixmap scaled(int w, int h, Qt.AspectRatioMode aspectMode)
Equivalent to scaled(w, h, aspectMode, Qt::FastTransformation).
public final QPixmap scaled(int w, int h)
Equivalent to scaled(w, h, Qt::IgnoreAspectRatio, Qt::FastTransformation).
public final QPixmap scaled(int w, int h, Qt.AspectRatioMode aspectMode, Qt.TransformationMode mode)
Returns a copy of the pixmap scaled to a rectangle with the given w and h according to the given aspectMode and mode.
If either the w or the h is zero or negative, this function returns a null pixmap.
public final QPixmap scaled(QSize s, Qt.AspectRatioMode aspectMode)
Equivalent to scaled(s, aspectMode, Qt::FastTransformation).
public final QPixmap scaled(QSize s)
Equivalent to scaled(s, Qt::IgnoreAspectRatio, Qt::FastTransformation).
public final QPixmap scaled(QSize s, Qt.AspectRatioMode aspectMode, Qt.TransformationMode mode)
Scales the pixmap to the given s, using the aspect ratio and transformation modes specified by aspectMode and mode.
If the given s is empty, this function returns a null pixmap.
Transformations
public final QPixmap scaledToHeight(int h)
Equivalent to scaledToHeight(h, Qt::FastTransformation).
public final QPixmap scaledToHeight(int h, Qt.TransformationMode mode)
Returns a scaled copy of the image. The returned image is scaled to the given h using the specified transformation mode. The width of the pixmap is automatically calculated so that the aspect ratio of the pixmap is preserved.
If h is 0 or negative, a null pixmap is returned.
Transformations
public final QPixmap scaledToWidth(int w)
Equivalent to scaledToWidth(w, Qt::FastTransformation).
public final QPixmap scaledToWidth(int w, Qt.TransformationMode mode)
Returns a scaled copy of the image. The returned image is scaled to the given w using the specified transformation mode. The height of the pixmap is automatically calculated so that the aspect ratio of the pixmap is preserved.
If w is 0 or negative, a null pixmap is returned.
Transformations
public final void setAlphaChannel(QPixmap arg__1)
Sets the alpha channel of this pixmap to the given arg__1 by converting the arg__1 into 32 bit and using the intensity of the RGB pixel values.
The effect of this function is undefined when the pixmap is being painted on.
Transformations
public final void setMask(QBitmap arg__1)
Sets a mask bitmap.
The arg__1 bitmap defines the clip mask for this pixmap. Every pixel in arg__1 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:
QPixmap alpha("image-with-alpha.png"); QPixmap alphacopy = alpha; alphacopy.setMask(alphacopy.mask());
Now, alpha and alphacopy are visually different.
Setting a null mask resets the mask.
The effect of this function is undefined when the pixmap is being painted on.
Transformations
,
QBitmappublic final QSize size()
Returns the size of the pixmap.
Information
public final QImage toImage()
Converts the pixmap to a QImage. Returns a null image if the conversion fails.
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.
public final QPixmap transformed(QMatrix arg__1, Qt.TransformationMode mode)
This convenience function loads the arg__1 into a QTransform and calls the overloaded function.
public final QPixmap transformed(QTransform arg__1, Qt.TransformationMode mode)
Returns a copy of the pixmap that is transformed using the given transformation arg__1 and transformation mode. The original pixmap is not changed.
The transformation arg__1 is internally adjusted to compensate for unwanted translation; i.e. the pixmap produced is the smallest pixmap that contains all the transformed points of the original pixmap. Use the trueMatrix function to retrieve the actual matrix used for transforming the pixmap.
This function is slow because it involves transformation to a QImage, non-trivial computations and a transformation back to a QPixmap.
Transformations
public final int width()
Returns the width of the pixmap.
width
in interface QPaintDeviceInterface
Information
public final int widthMM()
Returns the width of the paint device in millimeters.
widthMM
in interface QPaintDeviceInterface
public int devType()
devType
in interface QPaintDeviceInterface
public int metric(QPaintDevice.PaintDeviceMetric arg__1)
Returns the metric information for the given paint device arg__1.
metric
in interface QPaintDeviceInterface
public QPaintEngine paintEngine()
Returns a pointer to the paint engine used for drawing on the device.
paintEngine
in interface QPaintDeviceInterface
public static int defaultDepth()
Returns the default pixmap depth used by the application.
Information
public static QPixmap fromImage(QImage image, Qt.ImageConversionFlag... flags)
Converts the given image to a pixmap using the specified flags to control the conversion. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags. Passing 0 for flags sets all the default options.
In case of monochrome and 8-bit images, the image is first converted to a 32-bit pixmap and then filled with the colors in the color table. If this is too expensive an operation, you can use QBitmap::fromImage() instead.
Conversion
public static QPixmap fromImage(QImage image)
Equivalent to fromImage(image, Qt::AutoColor).
public static QPixmap fromImage(QImage image, Qt.ImageConversionFlags flags)
Converts the given image to a pixmap using the specified flags to control the conversion. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags. Passing 0 for flags sets all the default options.
In case of monochrome and 8-bit images, the image is first converted to a 32-bit pixmap and then filled with the colors in the color table. If this is too expensive an operation, you can use QBitmap::fromImage() instead.
Conversion
public static QPixmap grabWidget(QWidget widget, QRect rect)
Creates a pixmap and paints the given widget, restricted by the given rect, in it. If the widget has any children, then they are also painted in the appropriate positions.
If no rectangle is specified (the default) the entire widget is painted.
If widget is 0, the specified rectangle doesn't overlap the widget's rectangle, or an error occurs, the function will return a null QPixmap. If the rectangle is a superset of the given widget, the areas outside the widget are covered with the widget's background.
This function actually asks widget to paint itself (and its children to paint themselves) by calling paintEvent() with painter redirection turned on. But QPixmap also provides the grabWindow function which is a bit faster grabbing pixels directly off the screen. In addition, if there are overlaying windows, grabWindow, unlike grabWidget, will see them.
Warning: Do not call this function from QWidget::paintEvent().
public static QPixmap grabWidget(QWidget widget, int x, int y, int w)
Equivalent to grabWidget(widget, x, y, w, -1).
public static QPixmap grabWidget(QWidget widget, int x, int y)
Equivalent to grabWidget(widget, x, y, -1, -1).
public static QPixmap grabWidget(QWidget widget, int x)
Equivalent to grabWidget(widget, x, 0, -1, -1).
public static QPixmap grabWidget(QWidget widget)
Equivalent to grabWidget(widget, 0, 0, -1, -1).
public static QPixmap grabWidget(QWidget widget, int x, int y, int w, int h)
Creates a pixmap and paints the given widget, restricted by QRect(x, y, w, h), in it.
Warning: Do not call this function from QWidget::paintEvent().
public static QPixmap grabWindow(long arg__1, int x, int y, int w)
Equivalent to grabWindow(arg__1, x, y, w, -1).
public static QPixmap grabWindow(long arg__1, int x, int y)
Equivalent to grabWindow(arg__1, x, y, -1, -1).
public static QPixmap grabWindow(long arg__1, int x)
Equivalent to grabWindow(arg__1, x, 0, -1, -1).
public static QPixmap grabWindow(long arg__1)
Equivalent to grabWindow(arg__1, 0, 0, -1, -1).
public static QPixmap grabWindow(long arg__1, int x, int y, int w, int h)
Creates and returns a pixmap constructed by grabbing the contents of the given arg__1 restricted by QRect(x, y, w, h).
The arguments (x, y) specify the offset in the window, whereas (w, h) specify 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.
The window system identifier (WId) can be retrieved using the QWidget::winId() function. The rationale for using 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.
The grabWindow function grabs pixels from the screen, not from the window, i.e. if there is another window partially or entirely over the one you grab, you get pixels from the overlying window, too. The mouse cursor is generally not grabbed.
Note on X11that if the given arg__1 doesn't have 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 contents of the obscured areas in the pixmap will be undefined and uninitialized.
Warning: In general, grabbing an area outside the screen is not safe. This depends on the underlying window system.
public static QTransform trueMatrix(QTransform m, int w, int h)
Returns the actual matrix used for transforming a pixmap with the given w, h and m.
When transforming a pixmap using the transformed function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. transformed 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.
Transformations
public static QMatrix trueMatrix(QMatrix m, int w, int h)
This convenience function loads the matrix m into a QTransform and calls the overloaded function with the QTransform and the width w and the height h.
public static QPixmap fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public static QNativePointer nativePointerArray(QPixmap[] array)
array
- the array that the returned pointer will point to.
public final boolean save(QIODevice dev, java.lang.String format, int quality)
public final boolean save(QIODevice dev, java.lang.String format)
public final boolean save(QIODevice dev)
public final boolean save(java.lang.String fileName, java.lang.String format, int quality)
The quality factor 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.
If format is 0, an image format will be chosen from fileName's suffix.
public final boolean save(java.lang.String fileName, java.lang.String format)
public final boolean save(java.lang.String fileName)
public final boolean load(java.lang.String fileName, java.lang.String format, Qt.ImageConversionFlags flags)
The loader attempts to read the pixmap using the specified format. If the format is not specified (which is the default), the loader probes the file for a header to guess the file format.
The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the \l{resources.html}{Resource System} overview for details on how to embed pixmaps and other resource files in the application's executable.
If the data needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to control the conversion.
Note that QPixmaps are automatically added to the QPixmapCache when loaded from a file; the key used is internal and can not be acquired.
public final boolean load(java.lang.String fileName, java.lang.String format, Qt.ImageConversionFlag... flags)
public final boolean load(java.lang.String fileName, java.lang.String format)
public final boolean load(java.lang.String fileName)
public final boolean loadFromData(byte[] data, java.lang.String format, Qt.ImageConversionFlags flags)
The loader attempts to read the pixmap using the specified format. If the format is not specified (which is the default), the loader probes the file for a header to guess the file format.
If the data needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to control the conversion.
public final boolean loadFromData(byte[] data, java.lang.String format, Qt.ImageConversionFlag... flags)
public final boolean loadFromData(byte[] data, java.lang.String format)
public final boolean loadFromData(byte[] data)
public final boolean loadFromData(QByteArray data, java.lang.String format, Qt.ImageConversionFlags flags)
public final boolean loadFromData(QByteArray data, java.lang.String format, Qt.ImageConversionFlag... flags)
public final boolean loadFromData(QByteArray data, java.lang.String format)
public final boolean loadFromData(QByteArray data)
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |