当前位置: 首页>>代码示例>>C++>>正文


C++ CanvasItem::pixmap方法代码示例

本文整理汇总了C++中CanvasItem::pixmap方法的典型用法代码示例。如果您正苦于以下问题:C++ CanvasItem::pixmap方法的具体用法?C++ CanvasItem::pixmap怎么用?C++ CanvasItem::pixmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CanvasItem的用法示例。


在下文中一共展示了CanvasItem::pixmap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pickColor

QColor Core::pickColor(const QPointF& point, const QVariantList& canvasItems) {
    QPixmap pixmap;
    for (int i = canvasItems.count() - 1; i >= 0; i--) {
        QObject* obj = qvariant_cast<QObject*>(canvasItems.at(i));
        CanvasItem* canvasItem = qobject_cast<CanvasItem*>(obj);
        QPixmap* canvasPixmap = canvasItem->pixmap();
        if (pixmap.isNull()) {
            pixmap = QPixmap(canvasPixmap->width(), canvasPixmap->height());
            pixmap.fill(Qt::white);
        }
        QPainter painter(&pixmap);
        painter.drawPixmap(0, 0, *canvasPixmap);
    }

    return QColor(pixmap.toImage().pixel(qRound(point.x()), qRound(point.y())));
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例2: writePng

void Core::writePng(const QString& pngPath, const QVariantList& canvasItems) {
    QPixmap pixmap;
    for (int i = canvasItems.count() - 1; i >= 0; i--)
    {
        QObject* obj = qvariant_cast<QObject*>(canvasItems.at(i));
        CanvasItem* canvasItem = qobject_cast<CanvasItem*>(obj);
        QPixmap* canvasPixmap = canvasItem->pixmap();
        if (pixmap.isNull()) {
            pixmap = QPixmap(canvasPixmap->width(), canvasPixmap->height());
            pixmap.fill(Qt::white);
        }
        QPainter painter(&pixmap);
        painter.drawPixmap(0, 0, *canvasPixmap);
    }
    pixmap.save(pngPath);
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例3: writeOra

void Core::writeOra(const QString& oraPath, const QSize& canvasSize, const QVariantList layerList) {
    QZipWriter zipWriter(oraPath);
    zipWriter.setCompressionPolicy(QZipWriter::AutoCompress);

    QByteArray xmlByteArray;

    // mimetype file
    xmlByteArray.append("image/openraster");
    zipWriter.addFile("mimetype", xmlByteArray);

    // stack.xml file
    QXmlStreamWriter stream(&xmlByteArray);
    stream.setAutoFormatting(true);

    stream.writeStartDocument();

    stream.writeStartElement("image");
    stream.writeAttribute("w", QString::number(canvasSize.width()));
    stream.writeAttribute("h",QString::number(canvasSize.height()));
    stream.writeStartElement("stack");

    QByteArray ba;
    QBuffer buffer(&ba);

    for (int i = 0; i < layerList.count(); i++) {
        QMap<QString, QVariant> map = layerList.at(i).toMap();
        QString name = map.value("name").toString();
        QString isVisible = map.value("isVisible").toString();
        QString isLock = map.value("isLock").toString();
        QString isSelected = map.value("isSelected").toString();

        buffer.open(QIODevice::WriteOnly);
        QObject* obj = qvariant_cast<QObject*>(map.value("canvasItem"));
        CanvasItem* canvasItem = qobject_cast<CanvasItem*>(obj);
        QPixmap* pixmap = canvasItem->pixmap();
        pixmap->save(&buffer, "PNG");
        buffer.close();

        QString src = "data/" + name + ".png";
        zipWriter.addFile(src, ba);

        // layer
        stream.writeStartElement("layer");
        stream.writeAttribute("name", name);
        stream.writeAttribute("composite-op", "svg:src-over");
        stream.writeAttribute("visibility", isVisible == "true" ? "visible" : "hidden");
        stream.writeAttribute("edit-locked", isLock);
        stream.writeAttribute("selected", isSelected);
        stream.writeAttribute("src", src);
        stream.writeAttribute("x", "0");
        stream.writeAttribute("y", "0");
        stream.writeAttribute("opacity", "1.0");
        stream.writeEndElement(); // layer
    }

    stream.writeEndElement(); // stack
    stream.writeEndElement(); // image
    stream.writeEndDocument(); // document
    zipWriter.addFile("stack.xml", xmlByteArray);

    zipWriter.close();
}
开发者ID:,项目名称:,代码行数:62,代码来源:


注:本文中的CanvasItem::pixmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。