1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Canvas { id: canvas width: container.width height: container.height
property var ctx: null
Component.onCompleted: { loadImage("qrc:/images/logo01.png"); }
onPaint: { if (!ctx) { ctx = getContext("2d") if (!ctx) { console.error("获取Canvas上下文失败!") return } } ctx.clearRect(0, 0, width, height)
ctx.fillStyle = "rgba(255, 0, 0, 0.5)" ctx.strokeStyle = "blue" ctx.lineWidth = 3 ctx.fillRect(50, 50, 200, 100) ctx.strokeRect(50, 50, 200, 100)
ctx.beginPath() ctx.arc(400, 125, 75, 0, Math.PI * 2) ctx.fillStyle = "transparent" ctx.strokeStyle = "green" ctx.lineWidth = 2 ctx.stroke()
ctx.font = "bold 16px 'SimHei'" ctx.fillStyle = "black" ctx.fillText("你好!", 40, 180)
ctx.drawImage("qrc:/images/logo01.png",50, 200, 46, 46)
} }
|