How to save an image from QML Image element?
-
wrote on 23 Mar 2011, 11:54 last edited by
Yay. I figured it out!
The problem was that I was calling this save method when Image.onProgressChanged() fired and Image.progress == 1. This proved however to be before the Image was actually drawn onto the screen. The solution was to call the method when Image.onPaintedGeometryChanged() fired and Image.progress == 1.
-
wrote on 25 Oct 2011, 12:53 last edited by
Hi folks,
The snippet works but I am unsure how the path variable works on Symbian?
What drive the image saves to when it says "saved".Is there a way to set a proper folder like e:\folder on symbian^3?
-
wrote on 28 Oct 2011, 19:59 last edited by
Hey @ngocketit, thanks a lot! It worked great :)
-
wrote on 17 Jun 2014, 12:49 last edited by
Hi
Little help please. That piece of code probably works on Qt 4.7 but in 5.3 it doesn't. -The problem lays in qobject_cast -ing since it requires the source to inherit QObject, but QML Image is based on QtObject class.-
My bad QtObject inherits QObject but I'm still getting empty object after casting. By debugging the source imageobject seems to be normal QQuickImage object. Any ideas?
Since I'm really inexperienced in Qt c++ part, could anyone help with that problem.
Thanx.
-
wrote on 17 Jun 2014, 13:09 last edited by
QDeclarativeView *view = new QDeclarativeView();
QPixmap::grabWidget(view).save(outputFile, 0, 100);create view and grab image file in outputFile
-
wrote on 17 Jun 2014, 13:34 last edited by
Sorry, I'm not quite sure how to implement your solution. Also QDeclarativeView isn't used in Qt5 and Pixmap::grapWidget() also depricated.
But thnx anyways :)
-
wrote on 19 Jun 2014, 10:24 last edited by
sorry I am using older version (As per requirement ) I appreciate your reply
-
wrote on 27 Jun 2014, 13:27 last edited by
Hi
Does anybody have an idea why I can't pass the Image object to the save function. The path comes over nicely but "imageObj" pointer in save() function turns out empty?
-
wrote on 28 Jun 2014, 02:52 last edited by
Hi
I also have an empty pointer. I do not know where to look to solve this problem.
-
wrote on 28 Jun 2014, 03:09 last edited by
For Qt 5 and later, "Canvas":http://qt-project.org/doc/qt-5/qml-qtquick-canvas.html has loadImage(url) and save(filename) functions.
-
wrote on 28 Jun 2014, 03:24 last edited by
wait for QQuickRenderControl
-
wrote on 28 Jun 2014, 03:38 last edited by
I tried to use the Canvas, and also I could not save.
I'll try again tomorrow .. -
wrote on 28 Jun 2014, 04:54 last edited by
Image loading and saving via Canvas:
@import QtQuick 2.2
import QtQuick.Window 2.1Window {
width: imgLoader.sourceSize.width
height: imgLoader.sourceSize.height
visible: true
property string loadUrl: "file://tmp/image.png"
property string saveUrl: "/tmp/i2.png"Canvas { id: root anchors.fill: parent onPaint: { var ctx = getContext("2d") ctx.drawImage(imgLoader, 0, 0) } } MouseArea { anchors.fill: parent onClicked: { if (root.save(saveUrl)) { console.log("save succeeded") } else { console.log("save failed") } } } Image { id: imgLoader visible: false source: loadUrl }
}@
Note that the parameter to Canvas::save() is a filename, not a URL. It fails when "file://tmp/i2.png" is used.
-
wrote on 28 Jun 2014, 14:21 last edited by
jeremy_k thanks it works great.
-
wrote on 1 Aug 2014, 07:57 last edited by
Hi
does the above code really draw an image in the given path?
For me the file gets created but nothing in it... i have given save url as "/storage/sdcard0/a1.png".Can u help me ?
Thanks in Advance,,
-
wrote on 1 Aug 2014, 08:12 last edited by
Hi
I decided to solve this a bit differently. I created a new QML type (c++ class) that takes in image url (local or remote) and spits out local url. In case of beginning http:// or https:// class checks if image is already downloaded from the remote server and in that case spits the local url right out w/o wasting the precious mobile data bandwidth.And then there a QML component that fills out the Image type source property when the local url is returned from my so called "Caching class". If anybody's interest I can strip it out of my project and put it up to github with decent comments.
-
wrote on 1 Aug 2014, 08:44 last edited by
Hi DonRico
If u can post that code that would be an great help for me...can u?Thanks
-
wrote on 1 Aug 2014, 08:52 last edited by
Ok, I'll try to find some spare time to separate it and put it.
-
wrote on 4 Aug 2014, 07:33 last edited by
Ok, the exmaple project is available in https://github.com/DonRico/QT-Image-Caching . There might be some issues since I've written QT for 2mos for now but it should give you the general idea.
-
wrote on 4 Aug 2014, 21:50 last edited by
Caching can also be handled with a "QQuickImageProvider":https://qt-project.org/doc/qt-5/qquickimageprovider.htmlQQuickImageProvider.
After defining and register a provider, image urls can be written as "image://ProviderName/path/to/image".
The same concept exists for Qt 4 in the form of QDeclarativeImageProvider.