Skip to content
  • 0 Votes
    3 Posts
    3k Views
    robolivableR

    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.