zoukankan      html  css  js  c++  java
  • Qt 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)

     1     //方法一:qt自带
     2     int x = QCursor::pos().x();
     3     int y = QCursor::pos().y();
     4     QString text = QString("pos: %1, %2
    ").arg(x).arg(y);
     5 
     6     QPixmap pixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), x, y, 1, 1);
     7     if (!pixmap.isNull())
     8     {
     9         QImage image = pixmap.toImage();
    10         if (!image.isNull())
    11         {
    12             if (image.valid(0, 0))
    13             {
    14                 QColor color = image.pixel(0, 0);
    15                 text += QString("RGB: %1, %2, %3").arg(color.red()).arg(color.green()).arg(color.blue());
    16             }
    17         }
    18     }
    19 
    20     //方法二:windows系统api
    21     POINT pt;
    22     GetCursorPos(&pt);
    23     HDC hDC = GetDC(NULL);
    24     COLORREF color = GetPixel(hDC, pt.x, pt.y);
    25     ReleaseDC(NULL, hDC);
    26     BYTE r = GetRValue(color);
    27     BYTE g = GetGValue(color);
    28     BYTE b = GetBValue(color);
  • 相关阅读:
    【GO】文件二进制读取
    【JAVA】IO FileInputStream 读取二进制文件
    【JAVA】Maven 常用命令
    【JAVA】java8 function apply() compose() andThen()
    【Java】Maven resoucese 目录文件获取
    【数据结构】线索二叉树
    【Java】Java中的null作为方法参数是被当做值传递
    【Python】《Effective Python》 读书笔记 (一)
    【Python】一个try/except/else/finally 组合使用的例子
    【数据结构】二叉树的创建与遍历
  • 原文地址:https://www.cnblogs.com/ybqjymy/p/14313263.html
Copyright © 2011-2022 走看看