Qt提供了四个类来处理图像数据:QImage,QPixmap,QBitmap和QPicture。
- QImage 针对 I/O 以及直接像素访问和操作进行了设计和优化,
- 而 QPixmap 专为在屏幕上显示图像而设计和优化。
- QBitmap 只是一个继承 QPixmap 的便利类,保证深度为 1。
- 最后,QPicture 类是一个绘制设备,用于记录和重播 QPainter 命令。
QImage 类提供独立于硬件的图像表示形式,允许直接访问像素数据,并可用作绘画设备。
因为 QImage 是 QPaintDevice 的子类,所以 QPainter 可以直接在图像上绘制。 在 QImage 上使用 QPainter 时,可以在当前 GUI 线程以外的其他线程中执行绘制。
QImage 类支持由格式枚举描述的多种图像格式。其中包括单色、8 位、32 位和 alpha 混合图像,这些图像在所有版本的 Qt 4.x 中都可用。
QImage 提供了一组函数,可用于获取有关图像的各种信息。还有几个功能可以转换图像。
QImage 对象可以按值传递,因为 QImage 类使用隐式数据共享。Qmage对象也可以流式传输和比较。
QImage Class
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. More...
| Header: | #include <QImage> |
| qmake: | QT += gui |
| Inherits: | QPaintDevice |
Note: All functions in this class are reentrant.
Public Types
| enum | Format { Format_Invalid, Format_Mono, Format_MonoLSB, Format_Indexed8, Format_RGB32, …, Format_BGR888 } |
| enum | InvertMode { InvertRgb, InvertRgba } |
Public Functions
| QImage(QImage &&other) | |
| QImage(const QImage &image) | |
| QImage(const QString &fileName, const char *format = nullptr) | |
| QImage(const char *const [] xpm) | |
| QImage(const uchar *data, int width, int height, int bytesPerLine, QImage::Format format, QImageCleanupFunction cleanupFunction = nullptr, void *cleanupInfo = nullptr) | |
| QImage(uchar *data, int width, int height, int bytesPerLine, QImage::Format format, QImageCleanupFunction cleanupFunction = nullptr, void *cleanupInfo = nullptr) | |
| QImage(const uchar *data, int width, int height, QImage::Format format, QImageCleanupFunction cleanupFunction = nullptr, void *cleanupInfo = nullptr) | |
| QImage(uchar *data, int width, int height, QImage::Format format, QImageCleanupFunction cleanupFunction = nullptr, void *cleanupInfo = nullptr) | |
| QImage(int width, int height, QImage::Format format) | |
| QImage(const QSize &size, QImage::Format format) | |
| QImage() | |
| QImage & | operator=(QImage &&other) |
| QImage & | operator=(const QImage &image) |
| virtual | ~QImage() |
| bool | allGray() const |
| void | applyColorTransform(const QColorTransform &transform) |
| int | bitPlaneCount() const |
| uchar * | bits() |
| const uchar * | bits() const |
| int | bytesPerLine() const |
| qint64 | cacheKey() const |
| QRgb | color(int i) const |
| int | colorCount() const |
| QColorSpace | colorSpace() const |
| QVector<QRgb> | colorTable() const |
| const uchar * | constBits() const |
| const uchar * | constScanLine(int i) const |
| void | convertTo(QImage::Format format, Qt::ImageConversionFlags flags = Qt::AutoColor) |
| void | convertToColorSpace(const QColorSpace &colorSpace) |
| QImage | convertToFormat(QImage::Format format, Qt::ImageConversionFlags flags = Qt::AutoColor) const & |
| QImage | convertToFormat(QImage::Format format, Qt::ImageConversionFlags flags = Qt::AutoColor) && |
| QImage | convertToFormat(QImage::Format format, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const |
| QImage | convertedToColorSpace(const QColorSpace &colorSpace) const |
| QImage | copy(const QRect &rectangle = QRect()) const |
| QImage | copy(int x, int y, int width, int height) const |
| QImage | createAlphaMask(Qt::ImageConversionFlags flags = Qt::AutoColor) const |
| QImage | createHeuristicMask(bool clipTight = true) const |
| QImage | createMaskFromColor(QRgb color, Qt::MaskMode mode = Qt::MaskInColor) const |
| int | depth() const |
| qreal | devicePixelRatio() const |
| int | dotsPerMeterX() const |
| int | dotsPerMeterY() const |
| void | fill(uint pixelValue) |
| void | fill(const QColor &color) |
| void | fill(Qt::GlobalColor color) |
| QImage::Format | format() const |
| bool | hasAlphaChannel() const |
| int | height() const |
| void | invertPixels(QImage::InvertMode mode = InvertRgb) |
| bool | isGrayscale() const |
| bool | isNull() const |
| bool | load(const QString &fileName, const char *format = nullptr) |
| bool | load(QIODevice *device, const char *format) |
| bool | loadFromData(const uchar *data, int len, const char *format = nullptr) |
| bool | loadFromData(const QByteArray &data, const char *format = nullptr) |
| QImage | mirrored(bool horizontal = false, bool vertical = true) const & |
| QImage && | mirrored(bool horizontal = false, bool vertical = true) && |
| QPoint | offset() const |
| QRgb | pixel(const QPoint &position) const |
| QRgb | pixel(int x, int y) const |
| QColor | pixelColor(const QPoint &position) const |
| QColor | pixelColor(int x, int y) const |
| QPixelFormat | pixelFormat() const |
| int | pixelIndex(const QPoint &position) const |
| int | pixelIndex(int x, int y) const |
| QRect | rect() const |
| bool | reinterpretAsFormat(QImage::Format format) |
| QImage | rgbSwapped() const & |
| QImage && | rgbSwapped() && |
| bool | save(const QString &fileName, const char *format = nullptr, int quality = -1) const |
| bool | save(QIODevice *device, const char *format = nullptr, int quality = -1) const |
| QImage | scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const |
| QImage | scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const |
| QImage | scaledToHeight(int height, Qt::TransformationMode mode = Qt::FastTransformation) const |
| QImage | scaledToWidth(int width, Qt::TransformationMode mode = Qt::FastTransformation) const |
| uchar * | scanLine(int i) |
| const uchar * | scanLine(int i) const |
| void | setAlphaChannel(const QImage &alphaChannel) |
| void | setColor(int index, QRgb colorValue) |
| void | setColorCount(int colorCount) |
| void | setColorSpace(const QColorSpace &colorSpace) |
| void | setColorTable(const QVector<QRgb> colors) |
| void | setDevicePixelRatio(qreal scaleFactor) |
| void | setDotsPerMeterX(int x) |
| void | setDotsPerMeterY(int y) |
| void | setOffset(const QPoint &offset) |
| void | setPixel(const QPoint &position, uint index_or_rgb) |
| void | setPixel(int x, int y, uint index_or_rgb) |
| void | setPixelColor(const QPoint &position, const QColor &color) |
| void | setPixelColor(int x, int y, const QColor &color) |
| void | setText(const QString &key, const QString &text) |
| QSize | size() const |
| qsizetype | sizeInBytes() const |
| void | swap(QImage &other) |
| QString | text(const QString &key = QString()) const |
| QStringList | textKeys() const |
| CGImageRef | toCGImage() const |
| QImage | transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const |
| bool | valid(const QPoint &pos) const |
| bool | valid(int x, int y) const |
| int | width() const |
| QVariant | operator QVariant() const |
| bool | operator!=(const QImage &image) const |
| bool | operator==(const QImage &image) const |
Static Public Members
| QImage | fromData(const uchar *data, int size, const char *format = nullptr) |
| QImage | fromData(const QByteArray &data, const char *format = nullptr) |
| QImage::Format | toImageFormat(QPixelFormat format) |
| QPixelFormat | toPixelFormat(QImage::Format format) |
| QTransform | trueMatrix(const QTransform &matrix, int width, int height) |
Protected Functions
| QImage | smoothScaled(int w, int h) const |
Related Non-Members
| typedef | QImageCleanupFunction |
| QDataStream & | operator<<(QDataStream &stream, const QImage &image) |
| QDataStream & | operator>>(QDataStream &stream, QImage &image) |
详细说明
Qt提供了四个类来处理图像数据:QImage,QPixmap,QBitmap和QPicture。 QImage 针对 I/O 以及直接像素访问和操作进行了设计和优化,而 QPixmap 专为在屏幕上显示图像而设计和优化。QBitmap 只是一个继承 QPixmap 的便利类,保证深度为 1。最后,QPicture 类是一个绘制设备,用于记录和重播 QPainter 命令。
因为 QImage 是 QPaintDevice 的子类,所以 QPainter 可以直接在图像上绘制。 在 QImage 上使用 QPainter 时,可以在当前 GUI 线程以外的其他线程中执行绘制。
QImage 类支持由格式枚举描述的多种图像格式。其中包括单色、8 位、32 位和 alpha 混合图像,这些图像在所有版本的 Qt 4.x 中都可用。
QImage 提供了一组函数,可用于获取有关图像的各种信息。还有几个功能可以转换图像。
QImage 对象可以按值传递,因为 QImage 类使用隐式数据共享。Qmage对象也可以流式传输和比较。

浙公网安备 33010602011771号