本文整理汇总了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())));
}
示例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);
}
示例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();
}