Qt5 QML缩放图像和画布

时间:2015-06-25 15:10:47

标签: qt canvas qml

我们再来一次,玩qml。

我正在尝试使用<{1}}来生成 Canvas。我可以使用这段代码在Image上正确绘制:

Image

结果如下:

enter image description here

缩放图像时出现问题(放大/缩小):

enter image description here

为什么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完全相同,避免重复,并保持绘图坐标与新刻度一致。

任何帮助?

谢谢大家

0 个答案:

没有答案