QPixmap之颜色摄取器

QPixmap常用方法:

QPixmap(const QString & fileName, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor)

QBitmap mask() const

bool save(const QString & fileName, const char * format = 0, int quality = -1) const

bool save(QIODevice * device, const char * format = 0, int quality = -1) const

QPixmap scaled(const QSize & size, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const

QPixmap scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const

void setMask(const QBitmap & mask)

QImage toImage() const

静态函数

QPixmap fromImage(const QImage & image, Qt::ImageConversionFlags flags = Qt::AutoColor)

QPixmap fromImage(QImage && image, Qt::ImageConversionFlags flags = Qt::AutoColor)

废弃函数

The following members of class QPixmap are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.

Public Functions

(obsolete) void fill(const QPaintDevice * device, const QPoint & p)
(obsolete) void fill(const QPaintDevice * device, int x, int y)
(obsolete) int serialNumber() const

Static Public Members

(obsolete) QPixmap grabWidget(QObject * widget, const QRect & rectangle)
(obsolete) QPixmap grabWidget(QObject * widget, int x = 0, int y = 0, int w = -1, int h = -1)
(obsolete) QPixmap grabWindow(WId window, int x = 0, int y = 0, int width = -1, int height = -1)

    //方法一:qt自带
    int x = QCursor::pos().x();
    int y = QCursor::pos().y();
    QString text = QString("pos: %1, %2\n").arg(x).arg(y);

    QPixmap pixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), x, y, 1, 1);
    if (!pixmap.isNull())
    {
        QImage image = pixmap.toImage();
        if (!image.isNull())
        {
            if (image.valid(0, 0))
            {
                QColor color = image.pixel(0, 0);
                text += QString("RGB: %1, %2, %3").arg(color.red()).arg(color.green()).arg(color.blue());
            }
        }
    }

    //方法二:windows系统api
    POINT pt;
    GetCursorPos(&pt);
    HDC hDC = GetDC(NULL);
    COLORREF color = GetPixel(hDC, pt.x, pt.y);
    ReleaseDC(NULL, hDC);
    BYTE r = GetRValue(color);
    BYTE g = GetGValue(color);
    BYTE b = GetBValue(color);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值