⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpixmap.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    int d = data->d;    // Create new pixmap    QPixmap pm(QSize(w, h), d == 1 ? BitmapType : PixmapType);#ifdef Q_WS_X11    pm.x11SetScreen(data->xinfo.screen());#endif // Q_WS_X11    if (!data->uninit && !isNull()) {                // has existing pixmap        // Copy old pixmap        QPainter p(&pm);        p.drawPixmap(0, 0, *this, 0, 0, qMin(width(), w), qMin(height(), h));    }#if defined(Q_WS_MAC)#ifndef QT_MAC_NO_QUICKDRAW    if(data->qd_alpha)        data->macQDUpdateAlpha();#endif#elif defined(Q_WS_X11)    if (data->x11_mask) {        pm.data->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display, RootWindow(data->xinfo.display(), data->xinfo.screen()),                                                      w, h, 1);        GC gc = XCreateGC(X11->display, pm.data->x11_mask, 0, 0);        XCopyArea(X11->display, data->x11_mask, pm.data->x11_mask, gc, 0, 0, qMin(width(), w), qMin(height(), h), 0, 0);        XFreeGC(X11->display, gc);    }#else    if (data->mask) {        QBitmap m = *data->mask;        m.resize(w, h);        pm.setMask(m);    }#endif    *this = pm;}#endif/*!    \fn void QPixmap::resize(int width, int height)    \compat    Use the QPixmap constructor that takes two \c{int}s (\a width and    \a height) instead.    \oldcode        pixmap.resize(10, 20);    \newcode        pixmap = QPixmap(10, 20);    \endcode*//*!    \fn bool QPixmap::selfMask() const    \compat    Returns whether the pixmap is its own mask or not.    This function is no longer relevant since the concept of self    masking doesn't exists anymore.*/#ifndef QT_NO_IMAGE_HEURISTIC_MASK/*!    Creates and returns a heuristic mask for this pixmap.    The function works by selecting a color from one of the corners    and then chipping away pixels of that color, starting at all the    edges.  If \a clipTight is true (the default) the mask is just    large enough to cover the pixels; otherwise, the mask is larger    than the data pixels.    The mask may not be perfect but it should be reasonable, so you    can do things such as the following:    \code        QPixmap myPixmap;        myPixmap->setMask(myPixmap->createHeuristicMask());    \endcode    This function is slow because it involves converting to/from a    QImage, and non-trivial computations.    \sa QImage::createHeuristicMask(), createMaskFromColor()*/QBitmap QPixmap::createHeuristicMask(bool clipTight) const{    QBitmap m = QBitmap::fromImage(toImage().createHeuristicMask(clipTight));    return m;}#endif/*!    Creates and returns a mask for this pixmap based on the given \a    maskColor. If the \a mode is Qt::MaskInColor, all pixels matching the    maskColor will be opaque. If \a mode is Qt::MaskOutColor, all pixels    matching the maskColor will be transparent.    This function is slow because it involves converting to/from a    QImage.    \sa createHeuristicMask(), QImage::createMaskFromColor()*/QBitmap QPixmap::createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const{    QImage image = toImage().convertToFormat(QImage::Format_ARGB32);    return QBitmap::fromImage(image.createMaskFromColor(maskColor.rgba(), mode));}/*! \overload    Creates and returns a mask for this pixmap based on the given \a    maskColor. Same as calling createMaskFromColor(maskColor,    Qt::MaskInColor)    \sa createHeuristicMask(), QImage::createMaskFromColor()*/QBitmap QPixmap::createMaskFromColor(const QColor &maskColor) const{    return createMaskFromColor(maskColor, Qt::MaskInColor);}/*!    Loads a pixmap from the file with the given \a fileName. Returns    true if the pixmap was successfully loaded; otherwise returns    false.    The loader attempts to read the pixmap using the specified \a    format. If the \a format is not specified (which is the default),    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 pixmaps and other resource files in the application's    executable.    If the data needs to be modified to fit in a lower-resolution    result (e.g. converting from 32-bit to 8-bit), use the \a flags to    control the conversion.    Note that QPixmaps are automatically added to the QPixmapCache    when loaded from a file; the key used is internal and can not    be acquired.    \sa loadFromData(), {QPixmap#Reading and Writing Image    Files}{Reading and Writing Image Files}*/bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConversionFlags flags){    if (fileName.isEmpty())        return false;    QFileInfo info(fileName);    QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() + QLatin1Char('_') + info.lastModified().toString() + QLatin1Char('_') +                  QString::number(info.size()) + QLatin1Char('_') + QString::number(data->type);    if (QPixmapCache::find(key, *this))        return true;    QImage image = QImageReader(fileName, format).read();    if (image.isNull())        return false;    QPixmap pm;    if (data->type == BitmapType)        pm = QBitmap::fromImage(image, flags);    else        pm = fromImage(image, flags);    if (!pm.isNull()) {        *this = pm;        QPixmapCache::insert(key, *this);        return true;    }    return false;}/*!    \fn bool QPixmap::loadFromData(const uchar *data, uint len, const char *format, Qt::ImageConversionFlags flags)    Loads a pixmap from the \a len first bytes of the given binary \a    data.  Returns true if the pixmap was loaded successfully;    otherwise returns false.    The loader attempts to read the pixmap using the specified \a    format. If the \a format is not specified (which is the default),    the loader probes the file for a header to guess the file format.    If the data needs to be modified to fit in a lower-resolution    result (e.g. converting from 32-bit to 8-bit), use the \a flags to    control the conversion.    \sa load(), {QPixmap#Reading and Writing Image Files}{Reading and    Writing Image Files}*/bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags){    QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len);    QBuffer b(&a);    b.open(QIODevice::ReadOnly);    QImage image = QImageReader(&b, format).read();    QPixmap pm;    if (data->type == BitmapType)        pm = QBitmap::fromImage(image, flags);    else        pm = fromImage(image, flags);    if (!pm.isNull()) {        *this = pm;        return true;    }    return false;}/*!    \fn bool QPixmap::loadFromData(const QByteArray &data, const char *format, Qt::ImageConversionFlags flags)    \overload    Loads a pixmap from the binary \a data using the specified \a    format and conversion \a flags.*//*!    Saves the pixmap to the file with the given \a fileName using the    specified image file \a format and \a quality factor. Returns true    if successful; otherwise returns false.    The \a quality factor must be in the range [0,100] or -1. Specify    0 to obtain small compressed files, 100 for large uncompressed    files, and -1 to use the default settings.    If \a format is 0, an image format will be chosen from \a fileName's    suffix.    \sa {QPixmap#Reading and Writing Image Files}{Reading and Writing    Image Files}*/bool QPixmap::save(const QString &fileName, const char *format, int quality) const{    if (isNull())        return false;                                // nothing to save    QImageWriter writer(fileName, format);    return doImageIO(&writer, quality);}/*!    \overload    This function writes a QPixmap to the given \a device using the    specified image file \a format and \a quality factor. This can be    used, for example, to save a pixmap directly into a QByteArray:    \quotefromfile snippets/image/image.cpp    \skipto PIX SAVE    \skipto QPixmap    \printuntil save*/bool QPixmap::save(QIODevice* device, const char* format, int quality) const{    if (isNull())        return false;                                // nothing to save    QImageWriter writer(device, format);    return doImageIO(&writer, quality);}/*! \internal*/bool QPixmap::doImageIO(QImageWriter *writer, int quality) const{    if (quality > 100  || quality < -1)        qWarning("QPixmap::save: quality out of range [-1,100]");    if (quality >= 0)        writer->setQuality(qMin(quality,100));    return writer->write(toImage());}// The implementation (and documentation) of// QPixmap::fill(const QWidget *, const QPoint &)// is in qwidget.cpp/*!    \fn void QPixmap::fill(const QWidget *widget, int x, int y)    \overload    Fills the pixmap with the \a widget's background color or pixmap.    The given point, (\a x, \a y), defines an offset in widget    coordinates to which the pixmap's top-left pixel will be mapped    to.*//*! \obsolete    Returns a number that identifies the contents of this QPixmap    object. Distinct QPixmap objects can only have the same serial    number if they refer to the same contents (but they don't have    to).    Use cacheKey() instead.    \warning The serial number doesn't necessarily change when    the pixmap is altered. This means that it may be dangerous to use    it as a cache key. For caching pixmaps, we recommend using the    QPixmapCache class whenever possible.*/int QPixmap::serialNumber() const{    if (isNull())        return 0;    else        return data->ser_no;}/*!    Returns a number that identifies this QPixmap. Distinct QPixmap    objects can only have the same cache key if they refer to the same    contents.    The cacheKey() will change when the pixmap is altered.*/qint64 QPixmap::cacheKey() const{    return (((qint64) data->ser_no) << 32) | ((qint64) (data->detach_no));}static void sendResizeEvents(QWidget *target){    QResizeEvent e(target->size(), QSize());    QApplication::sendEvent(target, &e);    const QObjectList children = target->children();    for (int i = 0; i < children.size(); ++i) {        QWidget *child = static_cast<QWidget*>(children.at(i));        if (child->isWidgetType() && !child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent))            sendResizeEvents(child);    }}/*!    \fn QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rectangle)    Creates a pixmap and paints the given \a widget, restricted by the    given \a rectangle, in it. If the \a widget has any children, then    they are also painted in the appropriate positions.    If no rectangle is specified (the default) the entire widget is    painted.    If \a widget is 0, the specified rectangle doesn't overlap the    widget's rectangle, or an error occurs, the function will return a    null QPixmap.  If the rectangle is a superset of the given \a    widget, the areas outside the \a widget are covered with the    widget's background.    This function actually asks \a widget to paint itself (and its    children to paint themselves) by calling paintEvent() with painter    redirection turned on. But QPixmap also provides the grabWindow()    function which is a bit faster grabbing pixels directly off the    screen. In addition, if there are overlaying windows,    grabWindow(), unlike grabWidget(), will see them.    \warning Do not call this function from QWidget::paintEvent().    \sa grabWindow()*/QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect){    if (!widget)        return QPixmap();    if (widget->testAttribute(Qt::WA_PendingResizeEvent) || !widget->testAttribute(Qt::WA_WState_Created))        sendResizeEvents(widget);    QRect r(rect);    if (r.width() < 0)        r.setWidth(widget->width() - rect.x());    if (r.height() < 0)        r.setHeight(widget->height() - rect.y());    if (!r.intersects(widget->rect()))        return QPixmap();    QPixmap res(r.size());    widget->render(&res, -r.topLeft(), r,                   QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask);    return res;}/*!    \fn QPixmap QPixmap::grabWidget(QWidget *widget, int x, int y, int    width, int height)    \overload    Creates a pixmap and paints the given \a widget, restricted by    QRect(\a x, \a y, \a width, \a height), in it.    \warning Do not call this function from QWidget::paintEvent().*/#if defined(Q_WS_X11) || defined(Q_WS_QWS)/*!    Returns the pixmap's handle to the device context.    Note that, since QPixmap make use of \l {Implicit Data    Sharing}{implicit data sharing}, the detach() function must be    called explicitly to ensure that only \e this pixmap's data is    modified if the pixmap data is shared.    \warning This function is X11 specific; using it is non-portable.    \sa detach()*/Qt::HANDLE QPixmap::handle() const{    return data->hd;}#endif#ifdef QT3_SUPPORTstatic Qt::ImageConversionFlags colorModeToFlags(QPixmap::ColorMode mode){    Qt::ImageConversionFlags flags = Qt::AutoColor;    switch (mode) {      case QPixmap::Color:        flags |= Qt::ColorOnly;        break;      case QPixmap::Mono:        flags |= Qt::MonoOnly;        break;      default:        break;// Nothing.    }    return flags;}/*!    Use the constructor that takes a Qt::ImageConversionFlag instead.*/QPixmap::QPixmap(const QString& fileName, const char *format, ColorMode mode)    : QPaintDevice(){    init(0, 0);    load(fileName, format, colorModeToFlags(mode));}/*!    Constructs a pixmap from the QImage \a image.    Use the static fromImage() function instead.*/QPixmap::QPixmap(const QImage& image)    : QPaintDevice(){    init(0, 0);    if (data->type == BitmapType)        *this = QBitmap::fromImage(image);    else        *this = fromImage(image);}/*!    \overload    Converts the given \a image to a pixmap that is assigned to this    pixmap.    Use the static fromImage() function instead.*/QPixmap &QPixmap::operator=(const QImage &image)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -