Canvas加载图片:
import QtQuick 2.5
import QtQuick.Window 2.0
Window{
visible: true;
width: 1800;
height: 1000;
Canvas {
width: 1500
height: 940
property var ok:"qrc:/new/prefix1/Image/1.png";
onPaint: {
var ct=getContext("2d");
ct.drawImage(ok,0,0);
}
//异步load图片
Component.onCompleted: loadImage(ok);
onImageLoaded: requestPaint();
}
}
Canvas变换:
import QtQuick 2.5
import QtQuick.Window 2.0
Window{
visible: true;
width: 1800;
height: 1500;
Canvas {
width: 1000
height: 1000
contextType: "2d";
onPaint: {
context.lineWidth=2;
context.strokeStyle="blue";
context.fillStyle="red";
context.save();
context.translate(width/2,height/2);
context.beginPath();
context.arc(0,0,30,0,Math.PI*2);
context.arc(0,0,50,0,Math.PI*2);
context.arc(0,0,70,0,Math.PI*2);
context.arc(0,0,90,0,Math.PI*2);
context.stroke();
//恢复之前画布大小
context.restroe();
//restroe 后 save
context.save();
}
}
}