Printing grabToImage (rounded pictures)
-
Hi everyone,
I need to create some IDs with picture, names etc. ... about 8 ids should be printed on one DINA4 paper.
My current approach is using "grabToImage"var component = Qt.createComponent("IdLayout.qml"); var idLayout = idLayout = component.createObject(root, {"model": root.model}); var stat = idLayout.grabToImage(function(result) { result.saveToFile("ausweise.png"); }); console.log("Success: ", stat);
It kinda seems to work except from the fact that I don't know how IdLayout has the perfect size of DINA4 ... but with a little bit of try and error this works.
The only problem seem to be rounded Images. The common approach with layers doesn't work with grabToImage for some reason ...Image { id: img Layout.alignment: Qt.AlignHCenter Layout.preferredWidth: 100 Layout.preferredHeight: 100 source: '../Images/user.png' fillMode: Image.PreserveAspectCrop layer.enabled: true layer.effect: OpacityMask { maskSource: mask } Rectangle { id: mask width: 100 height: 100 radius: 50 visible: false } }
Any reason why grabToImage doesn't work with grabToImage()?
So my next approach canvas seem to work only with some pictures
Canvas { width: 120 height: 120 onPaint: { var ctx = getContext("2d"); // store current context setup ctx.save() ctx.strokeStyle = '#ff2a68' ctx.beginPath() ctx.roundedRect(0, 0, 120, 120, 60, 60) ctx.closePath() // create clip from the path ctx.clip() // draw image with clip applied ctx.drawImage(pfad, 0, 0, 120, 120) ctx.stroke(); // restore previous context ctx.restore() } Component.onCompleted: { loadImage(pfad); } onImageLoaded: { requestPaint(); } }
the stroke is just for testing purposes.
I have at least two pictures (one png, one jpeg), which work perfectly with that (also mixed) -> pfad is a model attribute (it's the path).
With all the pictures from my camera, which are jpg (and one other jpeg) it doesn't work. I'm pretty sure the paths are all correct! Because if I just use an Image instead it works perfectly.So has anyone an idea why those approaches with rounded pictures don't work or only partly? Or has another solution?