|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QImage
public class QImage
The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and 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. Finally, the QPicture
class is a paint device that records and replays QPainter
commands.
Because QImage is a QPaintDevice
subclass, QPainter
can be used to draw directly onto images. When using QPainter
on a QImage, the painting can be performed in another thread than the current GUI thread.
The QImage class supports several image formats described by the Format
enum. These include monochrome, 8-bit, 32-bit and alpha-blended images which are available in all versions of Qt 4.x.
QImage provides a collection of functions that can be used to obtain a variety of information about the image. There are also several functions that enables transformation of the image.
QImage objects can be passed around by value since the QImage class uses implicit data sharing. QImage objects can also be streamed and compared.
Note: If you would like to load QImage objects in a static build of Qt, refer to the Plugin HowTo.
load()
or loadFromData()
functions later on. QImage also provides the static fromData()
function, constructing a QImage from the given data. 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 QImage 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:
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 |
TIFF | Tagged Image File Format | Read/write |
XBM | X11 Bitmap | Read/write |
XPM | X11 Pixmap | Read/write |
Geometry | The size() , width() , height() , dotsPerMeterX() , and dotsPerMeterY() functions provide information about the image size and aspect ratio. The |
Colors | The color of a pixel can be retrieved by passing its coordinates to the pixel() function. The pixel() function returns the color as a QRgb value indepedent of the image's format. In case of monochrome and 8-bit images, the The See also the Pixel Manipulation and Image Transformations sections. |
Text | The text() function returns the image text associated with the given text key. An image's text keys can be retrieved using the textKeys() function. Use the setText() function to alter an image's text. |
Low-level information | The depth() function returns the depth of the image. The supported depths are 1 (monochrome), 8 and 32 (for more information see the Image Formats section). The The |
In case of a 32-bit image, the setPixel()
function can be used to alter the color of the pixel at the given coordinates to any other color specified as an ARGB quadruplet. To make a suitable QRgb value, use the qRgb() (adding a default alpha component to the given RGB values, i.e. creating an opaque color) or qRgba() function. For example:
![]() | QImage image = new QImage(3, 3, QImage.Format.Format_RGB32); int value; value = new QColor(189, 149, 39).rgb(); // 0xffbd9527 image.setPixel(1, 1, value); value = new QColor(122, 163, 39).rgb(); // 0xff7aa327 image.setPixel(0, 1, value); image.setPixel(1, 0, value); value = new QColor(237, 187, 51).rgb(); // 0xffedba31 image.setPixel(2, 1, value); |
setPixel()
function can only be used to alter the color of the pixel at the given coordinates to a predefined color from the image's color table, i.e. it can only change the pixel's index value. To alter or add a color to an image's color table, use the setColor()
function. An entry in the color table is an ARGB quadruplet encoded as an QRgb value. Use the qRgb() and qRgba() functions to make a suitable QRgb value for use with the setColor()
function. For example:
![]() | QImage image = new QImage(3, 3, QImage.Format.Format_Indexed8); int value; value = new QColor(122, 163, 39).rgb(); // 0xff7aa327 image.setColor(0, value); value = new QColor(237, 187, 51).rgb(); // 0xffedba31 image.setColor(1, value); value = new QColor(189, 149, 39).rgb(); // 0xffbd9527 image.setColor(2, value); image.setPixel(0, 1, 0); image.setPixel(1, 0, 0); image.setPixel(1, 1, 2); image.setPixel(2, 1, 1); |
scanLine()
function which returns a pointer to the pixel data at the scanline with the given index, and the bits()
function which returns a pointer to the first pixel data (this is equivalent to scanLine(0)).Format
enum. The monochrome (1-bit), 8-bit and 32-bit images are available in all versions of Qt. In addition Qt for Embedded Linux also supports 2-bit, 4-bit, and 16-bit images. For more information about the Qt Extended specific formats, see the documentation of the Format
enum. Monochrome images are stored using 1-bit indexes into a color table with at most two colors. There are two different types of monochrome images: big endian (MSB first) or little endian (LSB first) bit order.
8-bit images are stored using 8-bit indexes into a color table, i.e. they have a single byte per pixel. The color table is a QVector<QRgb>, and the QRgb typedef is equivalent to an unsigned int containing an ARGB quadruplet on the format 0xAARRGGBB.
32-bit images have no color table; instead, each pixel contains an QRgb value. There are three different types of 32-bit images storing RGB (i.e. 0xffRRGGBB), ARGB and premultiplied ARGB values respectively. In the premultiplied format the red, green, and blue channels are multiplied by the alpha component divided by 255.
An image's format can be retrieved using the format()
function. Use the convertToFormat()
functions to convert an image into another format. The allGray()
and isGrayscale()
functions tell whether a color image can safely be converted to a grayscale image.Image Transformations
QImage supports a number of functions for creating a new image that is a transformed version of the original: The createAlphaMask()
function builds and returns a 1-bpp mask from the alpha buffer in this image, and the createHeuristicMask()
function creates and returns a 1-bpp heuristic mask for this image. The latter function works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges.
The mirrored()
function returns a mirror of the image in the desired direction, the scaled()
returns a copy of the image scaled to a rectangle of the desired measures, the rgbSwapped()
function constructs a BGR image from a RGB image, and the alphaChannel()
function constructs an image from this image's alpha channel.
The scaledToWidth()
and scaledToHeight()
functions return scaled copies of the image.
The transformed()
function returns a copy of the image 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 image containing all transformed points of the original image. The static trueMatrix()
function returns the actual matrix used for transforming the image.
There are also functions for changing attributes of an image in-place:
setAlphaChannel() | Sets the alpha channel of the image. |
setDotsPerMeterX() | Defines the aspect ratio by setting the number of pixels that fit horizontally in a physical meter. |
setDotsPerMeterY() | Defines the aspect ratio by setting the number of pixels that fit vertically in a physical meter. |
fill() | Fills the entire image with the given pixel value. |
invertPixels() | Inverts all pixel values in the image using the given InvertMode value. |
setColorTable() | Sets the color table used to translate color indexes. Only monochrome and 8-bit formats. |
setNumColors() | Resizes the color table. Only monochrome and 8-bit formats. |
transformed()
functions use code based on smooth scaling algorithm by Daniel M. Duley.Copyright (C) 2004, 2005 Daniel M. DuleyRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. QImageReader
, QImageWriter
, QPixmap
, QSvgRenderer
, Image Composition Example, Image Viewer Example, Scribble Example, and Pixelator Example.
Nested Class Summary | |
---|---|
static class |
QImage.Format
The following image formats are available in all versions of Qt. |
static class |
QImage.InvertMode
This enum type is used to describe how pixel values should be inverted in the invertPixels() function. |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QImage()
Constructs a null image. |
|
QImage(byte[] data,
int width,
int height,
QImage.Format format)
Constructs an image with the given width, height, depth, bytesPerLine, colortable, numColors and bitOrder, that uses an existing memory buffer, data. |
|
QImage(int width,
int height,
QImage.Format format)
Constructs an image with the given width, height and format. |
|
QImage(QImage arg__1)
Constructs a shallow copy of the given image. |
|
QImage(QNativePointer data,
int width,
int height,
int bytesPerLine,
QImage.Format format)
Constructs an image with the given width, height and format, that uses an existing memory buffer, data. |
|
QImage(QSize size,
QImage.Format format)
Constructs an image with the given size and format. |
|
QImage(java.lang.String fileName)
Constructs an image from the given xpm image. |
|
QImage(java.lang.String[] xpm)
|
|
QImage(java.lang.String fileName,
java.lang.String format)
Constructs an image and tries to load the image from the file with the given fileName. |
Method Summary | |
---|---|
boolean |
allGray()
Returns true if all the colors in the image are shades of gray (i. |
QImage |
alphaChannel()
Returns the alpha channel of the image as a new grayscale QImage in which each pixel's red, green, and blue values are given the alpha value of the original image. |
QNativePointer |
bits()
Returns a pointer to the first pixel data. |
int |
bytesPerLine()
Returns the number of bytes per image scanline. |
long |
cacheKey()
Returns a number that identifies the contents of this QImage object. |
QImage |
clone()
This method is reimplemented for internal reasons |
int |
color(int i)
Returns the color in the color table at index i. |
java.util.List |
colorTable()
Returns a list of the colors contained in the image's color table, or an empty list if the image does not have a color table |
QImage |
convertToFormat(QImage.Format f)
Returns a copy of the image in the given format. |
QImage |
convertToFormat(QImage.Format f,
java.util.List colorTable)
Returns a copy of the image in the given format. |
QImage |
convertToFormat(QImage.Format f,
java.util.List colorTable,
Qt.ImageConversionFlag[] flags)
|
QImage |
convertToFormat(QImage.Format f,
java.util.List colorTable,
Qt.ImageConversionFlags flags)
Returns a copy of the image in the given format. |
QImage |
convertToFormat(QImage.Format f,
Qt.ImageConversionFlag[] flags)
|
QImage |
convertToFormat(QImage.Format f,
Qt.ImageConversionFlags flags)
Returns a copy of the image in the given format. |
QImage |
copy()
Returns a sub-area of the image as a new image. |
QImage |
copy(int x,
int y,
int w,
int h)
This is an overloaded member function, provided for convenience. |
QImage |
copy(QRect rect)
Returns a sub-area of the image as a new image. |
byte[] |
copyOfBytes()
Returns a copy of the image data. |
QImage |
createAlphaMask()
Builds and returns a 1-bpp mask from the alpha buffer in this image. |
QImage |
createAlphaMask(Qt.ImageConversionFlag[] flags)
|
QImage |
createAlphaMask(Qt.ImageConversionFlags flags)
Builds and returns a 1-bpp mask from the alpha buffer in this image. |
QImage |
createHeuristicMask()
Creates and returns a 1-bpp heuristic mask for this image. |
QImage |
createHeuristicMask(boolean clipTight)
Creates and returns a 1-bpp heuristic mask for this image. |
QImage |
createMaskFromColor(int color)
Creates and returns a mask for this image based on the given color value. |
QImage |
createMaskFromColor(int color,
Qt.MaskMode mode)
Creates and returns a mask for this image based on the given color value. |
int |
depth()
Returns the bit depth (number of bit planes) of the paint device. |
int |
dotsPerMeterX()
Returns the number of pixels that fit horizontally in a physical meter. |
int |
dotsPerMeterY()
Returns the number of pixels that fit vertically in a physical meter. |
void |
fill(int pixel)
Fills the entire image with the given pixelValue. |
QImage.Format |
format()
Returns the format of the image. |
static QImage |
fromData(QByteArray data)
This is an overloaded method provided for convenience. |
static QImage |
fromData(QByteArray data,
java.lang.String format)
This is an overloaded method provided for convenience. |
boolean |
hasAlphaChannel()
Returns true if the image has a format that respects the alpha channel, otherwise returns false. |
int |
height()
Returns the height of the paint device in default coordinate system units (e. |
int |
heightMM()
Returns the height of the paint device in millimeters. |
void |
invertPixels()
Inverts all pixel values in the image. |
void |
invertPixels(QImage.InvertMode arg__1)
Inverts all pixel values in the image. |
boolean |
isGrayscale()
For 32-bit images, this function is equivalent to allGray() . |
boolean |
isNull()
Returns true if it is a null image, otherwise returns false. |
boolean |
load(QIODevice device)
This is an overloaded method provided for convenience. |
boolean |
load(QIODevice device,
java.lang.String format)
This is an overloaded function provided for convenience. |
boolean |
load(java.lang.String fileName)
This is an overloaded method provided for convenience. |
boolean |
load(java.lang.String fileName,
java.lang.String format)
Loads an image from the file with the given fileName. |
boolean |
loadFromData(byte[] data)
Loads an image from the given QByteArray data. |
boolean |
loadFromData(byte[] data,
java.lang.String format)
Loads an image from the given QByteArray 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. |
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. |
int |
metric(QPaintDevice.PaintDeviceMetric metric)
Returns the metric information for the given paint device metric. |
QImage |
mirrored()
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false. |
QImage |
mirrored(boolean horizontally)
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false. |
QImage |
mirrored(boolean horizontally,
boolean vertically)
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether horizontal and vertical are set to true or false. |
int |
numBytes()
Returns the number of bytes occupied by the image data. |
int |
numColors()
Returns the number of different colors available for the paint device. |
QPoint |
offset()
Returns the number of pixels by which the image is intended to be offset by when positioning relative to other images. |
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. |
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. |
int |
pixel(int x,
int y)
This is an overloaded member function, provided for convenience. |
int |
pixel(QPoint pt)
Returns the color of the pixel at the given position. |
int |
pixelIndex(int x,
int y)
This is an overloaded member function, provided for convenience. |
int |
pixelIndex(QPoint pt)
Returns the pixel index at the given position. |
void |
readFrom(QDataStream arg__1)
|
QRect |
rect()
Returns the enclosing rectangle (0, 0, width() , height() ) of the image. |
QImage |
rgbSwapped()
Returns a QImage in which the values of the red and blue components of all pixels have been swapped, effectively converting an RGB image to an BGR image. |
boolean |
save(QIODevice dev)
This is an overloaded function 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 is an overloaded method provided for convenience. |
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 image to the file with the given fileName, using the given image file format and quality factor. |
QImage |
scaled(int w,
int h)
This is an overloaded member function, provided for convenience. |
QImage |
scaled(int w,
int h,
Qt.AspectRatioMode aspectMode)
This is an overloaded member function, provided for convenience. |
QImage |
scaled(int w,
int h,
Qt.AspectRatioMode aspectMode,
Qt.TransformationMode mode)
This is an overloaded member function, provided for convenience. |
QImage |
scaled(QSize s)
Returns a copy of the image scaled to a rectangle defined by the given size according to the given aspectRatioMode and transformMode. |
QImage |
scaled(QSize s,
Qt.AspectRatioMode aspectMode)
Returns a copy of the image scaled to a rectangle defined by the given size according to the given aspectRatioMode and transformMode. |
QImage |
scaled(QSize s,
Qt.AspectRatioMode aspectMode,
Qt.TransformationMode mode)
Returns a copy of the image scaled to a rectangle defined by the given size according to the given aspectRatioMode and transformMode. |
QImage |
scaledToHeight(int h)
Returns a scaled copy of the image. |
QImage |
scaledToHeight(int h,
Qt.TransformationMode mode)
Returns a scaled copy of the image. |
QImage |
scaledToWidth(int w)
Returns a scaled copy of the image. |
QImage |
scaledToWidth(int w,
Qt.TransformationMode mode)
Returns a scaled copy of the image. |
QNativePointer |
scanLine(int arg__1)
Returns a pointer to the pixel data at the scanline with index i. |
void |
setAlphaChannel(QImage alphaChannel)
Sets the alpha channel of this image to the given alphaChannel. |
void |
setColor(int i,
int c)
Sets the color at the given index in the color table, to the given to colorValue. |
void |
setColorTable(java.util.List colors)
Sets the color table used to translate color indexes to QRgb values, to the specified colors. |
void |
setDotsPerMeterX(int arg__1)
Sets the number of pixels that fit horizontally in a physical meter, to x. |
void |
setDotsPerMeterY(int arg__1)
Sets the number of pixels that fit vertically in a physical meter, to y. |
void |
setNumColors(int arg__1)
Resizes the color table to contain numColors entries. |
void |
setOffset(QPoint arg__1)
Sets the the number of pixels by which the image is intended to be offset by when positioning relative to other images, to offset. |
void |
setPixel(int x,
int y,
int index_or_rgb)
This is an overloaded member function, provided for convenience. |
void |
setPixel(QPoint pt,
int index_or_rgb)
Sets the pixel index or color at the given position to index_or_rgb. |
void |
setText(java.lang.String key,
java.lang.String value)
Sets the image text to the given text and associate it with the given key. |
QSize |
size()
Returns the size of the image, i. |
java.lang.String |
text()
Returns the image text associated with the given key. |
java.lang.String |
text(java.lang.String key)
Returns the image text associated with the given key. |
java.util.List |
textKeys()
Returns the text keys for this image. |
QImage |
transformed(QMatrix matrix)
Returns a copy of the image that is transformed using the given transformation matrix and transformation mode. |
QImage |
transformed(QMatrix matrix,
Qt.TransformationMode mode)
Returns a copy of the image that is transformed using the given transformation matrix and transformation mode. |
QImage |
transformed(QTransform matrix)
Returns a copy of the image that is transformed using the given transformation matrix and transformation mode. |
QImage |
transformed(QTransform matrix,
Qt.TransformationMode mode)
Returns a copy of the image that is transformed using the given transformation matrix and transformation mode. |
static QMatrix |
trueMatrix(QMatrix arg__1,
int w,
int h)
Returns the actual matrix used for transforming an image with the given width, height and matrix. |
static QTransform |
trueMatrix(QTransform arg__1,
int w,
int h)
Returns the actual matrix used for transforming an image with the given width, height and matrix. |
boolean |
valid(int x,
int y)
This is an overloaded member function, provided for convenience. |
boolean |
valid(QPoint pt)
Returns true if pos is a valid coordinate pair within the image; otherwise returns false. |
int |
width()
Returns the width of the paint device in default coordinate system units (e. |
int |
widthMM()
Returns the width of the paint device in millimeters. |
void |
writeTo(QDataStream arg__1)
|
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QImage()
isNull()
.
public QImage(QImage arg__1)
For more information about shallow copies, see the Implicit Data Sharing documentation.
copy()
.
public QImage(QSize size, QImage.Format format)
Warning: This will create a QImage with uninitialized data. Call fill()
to fill the image with an appropriate pixel value before drawing onto it with QPainter
.
public QImage(int width, int height, QImage.Format format)
Warning: This will create a QImage with uninitialized data. Call fill()
to fill the image with an appropriate pixel value before drawing onto it with QPainter
.
public QImage(QNativePointer data, int width, int height, int bytesPerLine, QImage.Format format)
The buffer must remain valid throughout the life of the QImage. The image does not delete the buffer at destruction.
If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setNumColors()
or setColorTable()
before the image is used.
public QImage(java.lang.String[] xpm)
public QImage(byte[] data, int width, int height, QImage.Format format)
Warning: This constructor is only available in Qt for Embedded Linux.
The data has to be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned, so it's no longer possible to specify a custom bytesPerLine value.
public QImage(java.lang.String fileName, java.lang.String format)
The loader attempts to read the image 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 loading of the image failed, this object is a null image.
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.
public QImage(java.lang.String fileName)
Make sure that the image is a valid XPM image. Errors are silently ignored.
Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:
String start_xpm[] = { "16 15 8 1", "a c #cec6bd", .... };The extra const makes the entire definition read-only, which is slightly more efficient (e.g., when the code is in a shared library) and able to be stored in ROM with the application.
Method Detail |
---|
public final boolean allGray()
Note that this function is slow for images without color table.
isGrayscale()
.
public final QImage alphaChannel()
You can see an example of use of this function in QPixmap
's alphaChannel()
, which works in the same way as this function on QPixmaps.
hasAlphaChannel()
, Pixmap
, and Image Transformations.
public final QNativePointer bits()
Note that QImage uses implicit data sharing. This function performs a deep copy of the shared pixel data, thus ensuring that this QImage is the only one using the current return value.
scanLine()
, and numBytes()
.
public final int bytesPerLine()
This is equivalent to numBytes()
/ height()
.
scanLine()
.
public final long cacheKey()
The key will change when the image is altered.
public final int color(int i)
The colors in an image's color table are specified as ARGB quadruplets (QRgb). Use the qAlpha(), qRed(), qGreen(), and qBlue() functions to get the color value components.
setColor()
, pixelIndex()
, and Pixel Manipulation.
public final java.util.List colorTable()
setColorTable()
, numColors()
, and color()
.
public final QImage convertToFormat(QImage.Format f, Qt.ImageConversionFlag[] flags)
public final QImage convertToFormat(QImage.Format f)
The specified image conversion flags control how the image data is handled during the conversion process.
public final QImage convertToFormat(QImage.Format f, Qt.ImageConversionFlags flags)
The specified image conversion flags control how the image data is handled during the conversion process.
public final QImage convertToFormat(QImage.Format f, java.util.List colorTable, Qt.ImageConversionFlag[] flags)
public final QImage convertToFormat(QImage.Format f, java.util.List colorTable)
The specified image conversion flags control how the image data is handled during the conversion process.
public final QImage convertToFormat(QImage.Format f, java.util.List colorTable, Qt.ImageConversionFlags flags)
The specified image conversion flags control how the image data is handled during the conversion process.
public final QImage copy()
The returned image is copied from the position (rectangle.x(), rectangle.y()) in this image, and will always have the size of the given rectangle.
In areas beyond this image, pixels are set to 0. For 32-bit RGB images, this means black; for 32-bit ARGB images, this means transparent black; for 8-bit images, this means the color with index 0 in the color table which can be anything; for 1-bit images, this means Qt::color0
.
If the given rectangle is a null rectangle the entire image is copied.
public final QImage copy(QRect rect)
The returned image is copied from the position (rectangle.x(), rectangle.y()) in this image, and will always have the size of the given rectangle.
In areas beyond this image, pixels are set to 0. For 32-bit RGB images, this means black; for 32-bit ARGB images, this means transparent black; for 8-bit images, this means the color with index 0 in the color table which can be anything; for 1-bit images, this means Qt::color0
.
If the given rectangle is a null rectangle the entire image is copied.
public final QImage copy(int x, int y, int w, int h)
The returned image is copied from the position (x, y) in this image, and will always have the given width and height. In areas beyond this image, pixels are set to 0.
public final QImage createAlphaMask(Qt.ImageConversionFlag[] flags)
public final QImage createAlphaMask()
QImage::Format_RGB32
. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags, and controls the conversion process. Passing 0 for flags sets all the default options.
The returned image has little-endian bit order (i.e. the image's format is QImage::Format_MonoLSB
), which you can convert to big-endian (QImage::Format_Mono
) using the convertToFormat()
function.
createHeuristicMask()
, and Image Transformations.
public final QImage createAlphaMask(Qt.ImageConversionFlags flags)
QImage::Format_RGB32
. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags, and controls the conversion process. Passing 0 for flags sets all the default options.
The returned image has little-endian bit order (i.e. the image's format is QImage::Format_MonoLSB
), which you can convert to big-endian (QImage::Format_Mono
) using the convertToFormat()
function.
createHeuristicMask()
, and Image Transformations.
public final QImage createHeuristicMask()
The function works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges. The four corners vote for which color is to be masked away. In case of a draw (this generally means that this function is not applicable to the image), the result is arbitrary.
The returned image has little-endian bit order (i.e. the image's format is QImage::Format_MonoLSB
), which you can convert to big-endian (QImage::Format_Mono
) using the convertToFormat()
function.
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.
Note that this function disregards the alpha buffer.
createAlphaMask()
, and Image Transformations.
public final QImage createHeuristicMask(boolean clipTight)
The function works by selecting a color from one of the corners, then chipping away pixels of that color starting at all the edges. The four corners vote for which color is to be masked away. In case of a draw (this generally means that this function is not applicable to the image), the result is arbitrary.
The returned image has little-endian bit order (i.e. the image's format is QImage::Format_MonoLSB
), which you can convert to big-endian (QImage::Format_Mono
) using the convertToFormat()
function.
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.
Note that this function disregards the alpha buffer.
createAlphaMask()
, and Image Transformations.
public final QImage createMaskFromColor(int color)
createAlphaMask()
, and createHeuristicMask()
.
public final QImage createMaskFromColor(int color, Qt.MaskMode mode)
createAlphaMask()
, and createHeuristicMask()
.
public final int depth()
depth
in interface QPaintDeviceInterface
public final int dotsPerMeterX()
dotsPerMeterY()
, this number defines the intended scale and aspect ratio of the image. setDotsPerMeterX()
, and Image Information.
public final int dotsPerMeterY()
dotsPerMeterX()
, this number defines the intended scale and aspect ratio of the image. setDotsPerMeterY()
, and Image Information.
public final void fill(int pixel)
If the depth of this image is 1, only the lowest bit is used. If you say fill(0), fill(2), etc., the image is filled with 0s. If you say fill(1), fill(3), etc., the image is filled with 1s. If the depth is 8, the lowest 8 bits are used and if the depth is 16 the lowest 16 bits are used.
Note: QImage::pixel()
returns the color of the pixel at the given coordinates while QColor::pixel() returns the pixel value of the underlying window system (essentially an index value), so normally you will want to use QImage::pixel()
to use a color from an existing image or QColor::rgb()
to use a specific color.
depth()
, and Image Transformations.
public final QImage.Format format()
public final boolean hasAlphaChannel()
alphaChannel()
, and Image Information.
public final int height()
QPixmap
and QWidget
). heightMM()
.
height
in interface QPaintDeviceInterface
public final int heightMM()
height()
.
heightMM
in interface QPaintDeviceInterface
public final void invertPixels()
The given invert mode only have a meaning when the image's depth is 32. The default mode is InvertRgb
, which leaves the alpha channel unchanged. If the mode is InvertRgba
, the alpha bits are also inverted.
Inverting an 8-bit image means to replace all pixels using color index i with a pixel using color index 255 minus i. The same is the case for a 1-bit image. Note that the color table is not changed.
public final void invertPixels(QImage.InvertMode arg__1)
The given invert mode only have a meaning when the image's depth is 32. The default mode is InvertRgb
, which leaves the alpha channel unchanged. If the mode is InvertRgba
, the alpha bits are also inverted.
Inverting an 8-bit image means to replace all pixels using color index i with a pixel using color index 255 minus i. The same is the case for a 1-bit image. Note that the color table is not changed.
public final boolean isGrayscale()
allGray()
. For 8-bpp images, this function returns true if color(i) is QRgb(i, i, i) for all indexes of the color table; otherwise returns false.
allGray()
, and Image Formats.
public final boolean isNull()
A null image has all parameters set to zero and no allocated data.
public final int logicalDpiX()
widthMM()
. Note that if the logicalDpiX()
doesn't equal the physicalDpiX()
, the corresponding QPaintEngine
must handle the resolution mapping.
logicalDpiY()
, and physicalDpiX()
.
logicalDpiX
in interface QPaintDeviceInterface
public final int logicalDpiY()
heightMM()
. Note that if the logicalDpiY()
doesn't equal the physicalDpiY()
, the corresponding QPaintEngine
must handle the resolution mapping.
logicalDpiX()
, and physicalDpiY()
.
logicalDpiY
in interface QPaintDeviceInterface
public final QImage mirrored(boolean horizontally)
Note that the original image is not changed.
public final QImage mirrored()
Note that the original image is not changed.
public final QImage mirrored(boolean horizontally, boolean vertically)
Note that the original image is not changed.
public final int numBytes()
bytesPerLine()
, bits()
, and Image Information.
public final int numColors()
numColors
in interface QPaintDeviceInterface
public final QPoint offset()
setOffset()
, and Image Information.
public final void writeTo(QDataStream arg__1)
public final void readFrom(QDataStream arg__1)
public final boolean paintingActive()
QPainter::begin()
but not yet called QPainter::end()
for this device; otherwise returns false. QPainter::isActive()
.
paintingActive
in interface QPaintDeviceInterface
public final int physicalDpiX()
Note that if the physicalDpiX()
doesn't equal the logicalDpiX()
, the corresponding QPaintEngine
must handle the resolution mapping.
physicalDpiY()
, and logicalDpiX()
.
physicalDpiX
in interface QPaintDeviceInterface
public final int physicalDpiY()
Note that if the physicalDpiY()
doesn't equal the logicalDpiY()
, the corresponding QPaintEngine
must handle the resolution mapping.
physicalDpiX()
, and logicalDpiY()
.
physicalDpiY
in interface QPaintDeviceInterface
public final int pixel(QPoint pt)
If the position is not valid, the results are undefined.
setPixel()
, valid()
, and Pixel Manipulation.
public final int pixel(int x, int y)
Returns the color of the pixel at coordinates (x, y).
public final int pixelIndex(QPoint pt)
If position is not valid, or if the image is not a paletted image (depth()
> 8), the results are undefined.
valid()
, depth()
, and Pixel Manipulation.
public final int pixelIndex(int x, int y)
Returns the pixel index at (x, y).
public final QRect rect()
width()
, height()
) of the image.
public final QImage rgbSwapped()
The original QImage is not changed.
public final QImage scaled(QSize s, Qt.AspectRatioMode aspectMode)
Qt::IgnoreAspectRatio
, the image is scaled to size.Qt::KeepAspectRatio
, the image is scaled to a rectangle as large as possible inside size, preserving the aspect ratio.Qt::KeepAspectRatioByExpanding
, the image is scaled to a rectangle as small as possible outside size, preserving the aspect ratio.isNull()
, and Image Transformations.
public final QImage scaled(QSize s)
Qt::IgnoreAspectRatio
, the image is scaled to size.Qt::KeepAspectRatio
, the image is scaled to a rectangle as large as possible inside size, preserving the aspect ratio.Qt::KeepAspectRatioByExpanding
, the image is scaled to a rectangle as small as possible outside size, preserving the aspect ratio.isNull()
, and Image Transformations.
public final QImage scaled(QSize s, Qt.AspectRatioMode aspectMode, Qt.TransformationMode mode)
Qt::IgnoreAspectRatio
, the image is scaled to size.Qt::KeepAspectRatio
, the image is scaled to a rectangle as large as possible inside size, preserving the aspect ratio.Qt::KeepAspectRatioByExpanding
, the image is scaled to a rectangle as small as possible outside size, preserving the aspect ratio.isNull()
, and Image Transformations.
public final QImage scaled(int w, int h, Qt.AspectRatioMode aspectMode)
Returns a copy of the image scaled to a rectangle with the given width and height according to the given aspectRatioMode and transformMode.
If either the width or the height is zero or negative, this function returns a null image.
public final QImage scaled(int w, int h)
Returns a copy of the image scaled to a rectangle with the given width and height according to the given aspectRatioMode and transformMode.
If either the width or the height is zero or negative, this function returns a null image.
public final QImage scaled(int w, int h, Qt.AspectRatioMode aspectMode, Qt.TransformationMode mode)
Returns a copy of the image scaled to a rectangle with the given width and height according to the given aspectRatioMode and transformMode.
If either the width or the height is zero or negative, this function returns a null image.
public final QImage scaledToHeight(int h)
This function automatically calculates the width of the image so that the ratio of the image is preserved.
If the given height is 0 or negative, a null image is returned.
public final QImage scaledToHeight(int h, Qt.TransformationMode mode)
This function automatically calculates the width of the image so that the ratio of the image is preserved.
If the given height is 0 or negative, a null image is returned.
public final QImage scaledToWidth(int w)
This function automatically calculates the height of the image so that its aspect ratio is preserved.
If the given width is 0 or negative, a null image is returned.
public final QImage scaledToWidth(int w, Qt.TransformationMode mode)
This function automatically calculates the height of the image so that its aspect ratio is preserved.
If the given width is 0 or negative, a null image is returned.
public final QNativePointer scanLine(int arg__1)
The scanline data is aligned on a 32-bit boundary.
Warning: If you are accessing 32-bpp image data, cast the returned pointer to QRgb* (QRgb has a 32-bit size) and use it to read/write the pixel value. You cannot use the uchar* pointer directly, because the pixel format depends on the byte order on the underlying platform. Use qRed(), qGreen(), qBlue(), and qAlpha() to access the pixels.
bytesPerLine()
, bits()
, and Pixel Manipulation.
public final void setAlphaChannel(QImage alphaChannel)
If alphaChannel is an 8 bit grayscale image, the intensity values are written into this buffer directly. Otherwise, alphaChannel is converted to 32 bit and the intensity of the RGB pixel values is used.
Note that the image will be converted to the Format_ARGB32_Premultiplied
format if the function succeeds.
Use one of the composition mods in QPainter::CompositionMode
instead.
alphaChannel()
, Image Transformations, and Image Formats.
public final void setColor(int i, int c)
If index is outside the current size of the color table, it is expanded with setNumColors()
.
color()
, numColors()
, setColorTable()
, and Pixel Manipulation.
public final void setColorTable(java.util.List colors)
When the image is used, the color table must be large enough to have entries for all the pixel/index values present in the image, otherwise the results are undefined.
colorTable()
, setColor()
, and Image Transformations.
public final void setDotsPerMeterX(int arg__1)
Together with dotsPerMeterY()
, this number defines the intended scale and aspect ratio of the image.
dotsPerMeterX()
, and Image Information.
public final void setDotsPerMeterY(int arg__1)
Together with dotsPerMeterX()
, this number defines the intended scale and aspect ratio of the image.
dotsPerMeterY()
, and Image Information.
public final void setNumColors(int arg__1)
If the color table is expanded, all the extra colors will be set to transparent (i.e qRgba(0, 0, 0, 0)).
When the image is used, the color table must be large enough to have entries for all the pixel/index values present in the image, otherwise the results are undefined.
numColors()
, colorTable()
, setColor()
, and Image Transformations.
public final void setOffset(QPoint arg__1)
offset()
, and Image Information.
public final void setPixel(QPoint pt, int index_or_rgb)
If the image's format is either monochrome or 8-bit, the given index_or_rgb value must be an index in the image's color table, otherwise the parameter must be a QRgb value.
If position is not a valid coordinate pair in the image, or if index_or_rgb >= numColors()
in the case of monochrome and 8-bit images, the result is undefined.
Warning: This function is expensive due to the call of the internal detach() function called within; if performance is a concern, we recommend the use of scanLine()
to access pixel data directly.
pixel()
, and Pixel Manipulation.
public final void setPixel(int x, int y, int index_or_rgb)
Sets the pixel index or color at (x, y) to index_or_rgb.
public final void setText(java.lang.String key, java.lang.String value)
If you just want to store a single text block (i.e., a "comment" or just a description), you can either pass an empty key, or use a generic key like "Description".
The image text is embedded into the image data when you call save()
or QImageWriter::write()
.
Not all image formats support embedded text. You can find out if a specific image or format supports embedding text by using QImageWriter::supportsOption()
. We give an example:
QImageWriter writer; writer.setFormat("png"); if (writer.supportsOption(QImageIOHandler::Description)) qDebug() << "Png supports embedded text";You can use
QImageWriter::supportedImageFormats()
to find out which image formats are available to you. text()
, and textKeys()
.
public final QSize size()
width()
and height()
.
public final java.lang.String text()
setText()
, and textKeys()
.
public final java.lang.String text(java.lang.String key)
setText()
, and textKeys()
.
public final java.util.List textKeys()
You can use these keys with text()
to list the image text for a certain key.
text()
.
public final QImage transformed(QMatrix matrix)
The transformation matrix is internally adjusted to compensate for unwanted translation; i.e. the image produced is the smallest image that contains all the transformed points of the original image. Use the trueMatrix()
function to retrieve the actual matrix used for transforming an image.
trueMatrix()
, and Image Transformations.
public final QImage transformed(QMatrix matrix, Qt.TransformationMode mode)
The transformation matrix is internally adjusted to compensate for unwanted translation; i.e. the image produced is the smallest image that contains all the transformed points of the original image. Use the trueMatrix()
function to retrieve the actual matrix used for transforming an image.
trueMatrix()
, and Image Transformations.
public final QImage transformed(QTransform matrix)
The transformation matrix is internally adjusted to compensate for unwanted translation; i.e. the image produced is the smallest image that contains all the transformed points of the original image. Use the trueMatrix()
function to retrieve the actual matrix used for transforming an image.
Unlike the other overload, this function can be used to perform perspective transformations on images.
trueMatrix()
, and Image Transformations.
public final QImage transformed(QTransform matrix, Qt.TransformationMode mode)
The transformation matrix is internally adjusted to compensate for unwanted translation; i.e. the image produced is the smallest image that contains all the transformed points of the original image. Use the trueMatrix()
function to retrieve the actual matrix used for transforming an image.
Unlike the other overload, this function can be used to perform perspective transformations on images.
trueMatrix()
, and Image Transformations.
public final boolean valid(QPoint pt)
rect()
, and QRect::contains()
.
public final boolean valid(int x, int y)
Returns true if QPoint
(x, y) is a valid coordinate pair within the image; otherwise returns false.
public final int width()
QPixmap
and QWidget
). widthMM()
.
width
in interface QPaintDeviceInterface
public final int widthMM()
width()
.
widthMM
in interface QPaintDeviceInterface
public int metric(QPaintDevice.PaintDeviceMetric metric)
PaintDeviceMetric
.
metric
in interface QPaintDeviceInterface
public QPaintEngine paintEngine()
paintEngine
in interface QPaintDeviceInterface
public static QMatrix trueMatrix(QMatrix arg__1, int w, int h)
When transforming an image using the transformed()
function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. transformed()
returns the smallest image containing all transformed points of the original image. This function returns the modified matrix, which maps points correctly from the original image into the new image.
transformed()
, and Image Transformations.
public static QTransform trueMatrix(QTransform arg__1, int w, int h)
When transforming an image using the transformed()
function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. transformed()
returns the smallest image containing all transformed points of the original image. This function returns the modified matrix, which maps points correctly from the original image into the new image.
Unlike the other overload, this function creates transformation matrices that can be used to perform perspective transformations on images.
transformed()
, and Image Transformations.
public final byte[] copyOfBytes()
public final boolean save(java.lang.String fileName, java.lang.String format, int quality)
The quality factor must be in the range 0 to 100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 (the default) to use the default settings.
Returns true if the image was successfully saved; otherwise returns false.
public final boolean save(java.lang.String fileName, java.lang.String format)
public final boolean save(java.lang.String fileName)
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 load(java.lang.String fileName, java.lang.String format)
The loader attempts to read the image using the specified format. If the format is null, 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.
public final boolean load(java.lang.String fileName)
public final boolean load(QIODevice device, java.lang.String format)
public final boolean load(QIODevice device)
public final boolean loadFromData(byte[] data, java.lang.String format)
QByteArray
data.
public final boolean loadFromData(byte[] data)
QByteArray
data.
public final boolean loadFromData(QByteArray data, java.lang.String format)
public final boolean loadFromData(QByteArray data)
public static QImage fromData(QByteArray data, java.lang.String format)
Loads an image from the given QByteArray data.
public static QImage fromData(QByteArray data)
Loads an image from the given QByteArray data.
public QImage clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |