Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Why is it still not possible to save a QML Image to file?
QtWS25 Last Chance

Why is it still not possible to save a QML Image to file?

Scheduled Pinned Locked Moved QML and Qt Quick
qmlqt quickimagedownloadimage downloadqml image downlqml image to fi
3 Posts 2 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    robolivable
    wrote on 10 Sept 2015, 19:58 last edited by robolivable 9 Oct 2015, 20:00
    #1

    In reference to the following threads:
    https://forum.qt.io/topic/3864/how-to-save-an-image-from-qml-image-element
    https://forum.qt.io/topic/17505/saving-qml-image/2
    https://forum.qt.io/topic/28006/save-image-from-qml

    This feature seems trivial but is surprisingly challenging. What is the easiest approach as of Qt 5.5?

    P 1 Reply Last reply 11 Sept 2015, 07:44
    0
    • R robolivable
      10 Sept 2015, 19:58

      In reference to the following threads:
      https://forum.qt.io/topic/3864/how-to-save-an-image-from-qml-image-element
      https://forum.qt.io/topic/17505/saving-qml-image/2
      https://forum.qt.io/topic/28006/save-image-from-qml

      This feature seems trivial but is surprisingly challenging. What is the easiest approach as of Qt 5.5?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 11 Sept 2015, 07:44 last edited by
      #2

      @robolivable Now you can use grabToImage.

      157

      1 Reply Last reply
      0
      • R Offline
        R Offline
        robolivable
        wrote on 11 Sept 2015, 17:34 last edited by robolivable 9 Nov 2015, 18:26
        #3

        Okay, so the idea here is to utilize the Item element's grabToImage method to save everything inside the element to a file. Placing the Image inside the Item, and calling the method provides the feature I was looking for. Thanks, @p3c0!

        Reference code:

        Item {
            id: "itemInQuestion";
            Image {
                id: myImage;
                source: "http://www.arbitrarySource.com/arbitraryImage.jpeg"
            }
        }
        // ...
        MouseArea {
            id: "someMouseArea";
            onClicked: {
                itemInQuestion.grabToImage(function (result) {
                    result.saveToFile("/arbitrary/file/system/path/myArbitraryImage.jpeg");
                });
            }
        }
        

        EDIT: I hadn't realized the grabToImage method is an inherited method in Image. The use of a wrapping Item is unnecessary in this case. I should also note that this method does not save the actual image, but a lower resolution copy, as quoted from the documentation: "This function will render the item to an offscreen surface and copy that surface from the GPU's memory into the CPU's memory, which can be quite costly." Is there a better way of saving the full resolution image to a file without having to request it from it's source a second time? This sort of brings me back to my original question.

        1 Reply Last reply
        0

        1/3

        10 Sept 2015, 19:58

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved