我们再来一次,玩qml。
我正在尝试使用<{1}}来生成而 Canvas
。我可以使用这段代码在Image
上正确绘制:
Image
结果如下:
缩放图像时出现问题(放大/缩小):
为什么delegate: Item
{
anchors.horizontalCenter: parent.horizontalCenter
width: img.sourceSize.width * imgScale
height: img.sourceSize.height * imgScale
Image
{
id: img
anchors.fill: parent
source: item_img_path + "/" + Math.random()
fillMode: Image.Stretch
}
Canvas
{
id: markerCanvas
anchors.fill: parent
contextType: "2d"
onPaint:
{
context.reset();
context.globalAlpha = markerOpacity;
if((true === drawingMarker) && (true === markerEnabled) && (-1 !== startXPos) && (-1 !== startYPos))
{
var l_obj = {"startXPos": startXPos, "startYPos": startYPos, "thickness": markerThickness, "color": markerColor};
markerPoints.push(l_obj);
}
for(var i = 0; i < markerPoints.length; i++)
{
context.fillStyle = markerPoints[i]["color"];
context.fillRect(markerPoints[i]["startXPos"], markerPoints[i]["startYPos"], markerPoints[i]["thickness"], markerPoints[i]["thickness"]);
}
}
MouseArea
{
anchors.fill: parent
onPressed:
{
drawingMarker = true;
markerCanvas.forceActiveFocus()
startXPos = mouseX
startYPos = mouseY
markerCanvas.requestPaint()
}
onMouseXChanged:
{
startXPos = mouseX
startYPos = mouseY
markerCanvas.requestPaint()
}
onMouseYChanged:
{
startXPos = mouseX
startYPos = mouseY
markerCanvas.requestPaint()
}
onReleased:
{
endXPos = mouseX;
endYPos = mouseY;
drawingMarker = false;
}
}
}
}
获取重复,为什么绘制坐标会被搞砸?
即使我将Canvas
对象置于 Canvas
内,结果也是一样的。
我希望Image
缩放与Canvas
完全相同,避免重复,并保持绘图坐标与新刻度一致。
任何帮助?
谢谢大家