Not from Image
directly. QDeclarativeImage
has pixmap
, setPixmap
and pixmapChange
, but for some reason the property is not declared. Therefore you cannot use its fom qml. Unfortunately, it also cannot be used with C ++ - these are private calsss.
What you can do is draw an image element in your pixmap and save it to a file.
class Capturer : public QObject { Q_OBJECT public: explicit Capturer(QObject *parent = 0); Q_INVOKABLE void save(QDeclarativeItem *obj); }; void Capturer::save(QDeclarativeItem *item) { QPixmap pix(item->width(), item->height()); QPainter painter(&pix); QStyleOptionGraphicsItem option; item->paint(&painter, &option, NULL); pix.save("/path/to/output.png"); }
Register the context variable "capturer":
int main() {
And use it in your qml:
Rectangle { // ... Image { id: img source: "/path/to/your/source" } MouseArea { anchors.fill: parent onClicked: { capturer.save(img) } } }
sergk source share