I need to capture an image from QML which has Canvas
elements. Whereas Canvas
es are displayed fine they are not correctly saved in the picture snapshots.
I have used QQuickWindow grabWindow
method as described in the solutions of this link and the images are saved in the UI thread called by afterRendering
signal (I have tried frameSwapped
signal too). Result is that all QML objects are saved but not Canvas
objects.
Both the renderStrategy
and renderTarget
of Canvas
es are set to the default values. They are simple Canvas
es as shown below:
Canvas {
id:canvas
onPaint:{
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(20, 0);
ctx.bezierCurveTo(-10, 90, 210, 90, 180, 0);
ctx.stroke();
//...
}
}
I have noticed that the afterRendering
signal is called multiple times.
Any suggestion is really appreciated! :)