Qt源码分析--QImage(3)

59 篇文章 1 订阅
37 篇文章 1 订阅
本文档详细介绍了QImage类的几个核心函数,包括:根据key获取文本、获取所有文本键、设置文本键值对、获取图像深度、位平面数量、图像格式、每行字节数、总大小以及缓存键。这些函数对于理解和操作QImage对象的内部信息至关重要。
摘要由CSDN通过智能技术生成

1.QString text(const QString &key = QString()) const;

/*!
    Returns the image text associated with the given \a key. If the
    specified \a key is an empty string, the whole image text is
    returned, with each key-text pair separated by a newline.
    \sa setText(), textKeys()
*/
QString QImage::text(const QString &key) const
{
    if (!d)
        return QString();
    if (!key.isEmpty())
        return d->text.value(key);
    QString tmp;
    for (auto it = d->text.begin(), end = d->text.end(); it != end; ++it)
        tmp += it.key() + QLatin1String(": ") + it.value().simplified() + QLatin1String("\n\n");
    if (!tmp.isEmpty())
        tmp.chop(2); // remove final \n\n
    return tmp;
}

d->text是QMap类型,根据key获取value。

2.QStringList textKeys() const;

QStringList QImage::textKeys() const
{
    return d ? QStringList(d->text.keys()) : QStringList();
}

3. void setText(const QString &key, const QString &value);

void QImage::setText(const QString &key, const QString &value)
{
    if (!d)
        return;
    detach();
    if (d)
        d->text.insert(key, value);
}

添加key和value到QMap里。

4.int depth() const;

/*!
    Returns the depth of the image.
    The image depth is the number of bits used to store a single
    pixel, also called bits per pixel (bpp).
    The supported depths are 1, 8, 16, 24, 32 and 64.
    \sa bitPlaneCount(), convertToFormat(), {QImage#Image Formats}{Image Formats},
    {QImage#Image Information}{Image Information}
*/
int QImage::depth() const
{
    return d ? d->depth : 0;
}

5.int bitPlaneCount() const;

int QImage::bitPlaneCount() const
{
    if (!d)
        return 0;
    int bpc = 0;
    switch (d->format) {
    case QImage::Format_Invalid:
        break;
    case QImage::Format_BGR30:
    case QImage::Format_RGB30:
        bpc = 30;
        break;
    case QImage::Format_RGB32:
    case QImage::Format_RGBX8888:
        bpc = 24;
        break;
    case QImage::Format_RGB666:
        bpc = 18;
        break;
    case QImage::Format_RGB555:
        bpc = 15;
        break;
    case QImage::Format_ARGB8555_Premultiplied:
        bpc = 23;
        break;
    case QImage::Format_RGB444:
        bpc = 12;
        break;
    case QImage::Format_RGBX64:
        bpc = 48;
        break;
    default:
        bpc = qt_depthForFormat(d->format);
        break;
    }
    return bpc;
}

位平面的数量是颜色的位数(bit).

6.Format format() const;

QImage::Format QImage::format() const
{
    return d ? d->format : Format_Invalid;
}

7.qsizetype bytesPerLine() const;

qsizetype QImage::bytesPerLine() const
{
    return d ? d->bytes_per_line : 0;
}

8.qsizetype sizeInBytes() const;

qsizetype QImage::sizeInBytes() const
{
    return d ? d->nbytes : 0;
}

9.qint64 cacheKey() const;

/*!
    Returns a number that identifies the contents of this QImage
    object. Distinct QImage objects can only have the same key if they
    refer to the same contents.
    The key will change when the image is altered.
*/
qint64 QImage::cacheKey() const
{
    if (!d)
        return 0;
    else
        return (((qint64) d->ser_no) << 32) | ((qint64) d->detach_no);
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天天进步2015

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值