Is It possible to create a secondary Canvas? Or use a Qml Image inside Canvas
-
in pure javascript, you can create a canvas to then use in conjunction with context.createPattern
and I was wondering if there was a way to do this with qml.
var ctx = canvas.getContext("2d"); //creating a new canvas var canvas = document.createElement('canvas'); canvas.width = 500; canvas.height = 400; var img = canvas.getContext("2d"); draw(img); var objPattern = ctx.createPattern(img, "repeat"); ctx.fillStyle = objPattern;
if that isn't possible then how do you create an Image for createPattern in qml?
I've tried the below but the Image defaults to the top corner on my canvas instead of filling object I draw
Canvas{ id: canvas_id Image{ id: image_id source: "./mysource.png" } onPaint: { var ctx = canvas_id.getContext('2d'); //create a 2nd canvas for fill pattern var pattern = ctx.createPattern(image_id, "repeat"); context.fillStyle = pattern ////drawRect with pattern } }
-
in pure javascript, you can create a canvas to then use in conjunction with context.createPattern
and I was wondering if there was a way to do this with qml.
var ctx = canvas.getContext("2d"); //creating a new canvas var canvas = document.createElement('canvas'); canvas.width = 500; canvas.height = 400; var img = canvas.getContext("2d"); draw(img); var objPattern = ctx.createPattern(img, "repeat"); ctx.fillStyle = objPattern;
if that isn't possible then how do you create an Image for createPattern in qml?
I've tried the below but the Image defaults to the top corner on my canvas instead of filling object I draw
Canvas{ id: canvas_id Image{ id: image_id source: "./mysource.png" } onPaint: { var ctx = canvas_id.getContext('2d'); //create a 2nd canvas for fill pattern var pattern = ctx.createPattern(image_id, "repeat"); context.fillStyle = pattern ////drawRect with pattern } }
@rubxcubedude have you looked at the qml/canvas docu yet?
There is a drawImage function.
http://doc.qt.io/qt-5/qml-qtquick-context2d.html#drawImage-method-2
shoud work with img object, or just the url directly
-
@rubxcubedude have you looked at the qml/canvas docu yet?
There is a drawImage function.
http://doc.qt.io/qt-5/qml-qtquick-context2d.html#drawImage-method-2
shoud work with img object, or just the url directly
@J.Hilk I have. both that method and the createPattern method say they accept an Image, a CanvasImageData, or a URL as acceptable parameters. my question is how do i create the Image and/or canvasImagedata to be used. when i try to define the image in my canvas as shown in my initial posts code, the image gets put at 0,0 instead of inside the rectangle i want it to fill.