如何在QML画布上获取精确的绘制像素?我应该扩展哪个Qt对象?

时间:2019-01-27 18:30:28

标签: qt canvas qml qt5 image-segmentation

我正在开发一个程序,该程序可以为用户注释图像上的某些像素,然后我将基于标记的像素运行图像处理算法。

Example

我想获取带注释的像素的坐标以及它们所属的组(蓝色,黄色或用户添加的任何其他彩色标记),它需要在图像上缩放(缩放)时具有鲁棒性,并且能够删除选择的标记(QML Canvas不允许的标记)。

我是使用QGraphicsView中的QtWidgets开发它的,但最终还是使用QML重新启动了该应用程序,因为移动版本会很好,但是我不确定这是否是一个不错的选择。

当前,我有这个(简化版)

Item {
    id: main_area
    // ...

    Image {
        id: image
        anchors.fill: parent
        // ...
    }

    Canvas { // I think this needs to be replaced with my c++ class
        id: scribble_area
        anchors.fill: image

        property real last_x
        property real last_y
        onPaint: {
            var ctx = getContext("2d")
            ctx.lineCap = "round"
            ctx.lineWidth = 10
            ctx.strokeStyle = color_tools.paintColor // it's in another file
            ctx.beginPath()
            ctx.moveTo(last_x, last_y)
            last_x = area.mouseX
            last_y = area.mouseY
            ctx.lineTo(last_x, last_y)
            ctx.stroke()
        }

        MouseArea {
            id: area
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            onPressed: {
                scribble_area.last_x = mouseX
                scribble_area.last_y = mouseY
            }
            onPositionChanged: scribble_area.requestPaint()
        }
    }
}

我不确定用id: image覆盖id: scribble_area是执行我想要的事情的正确方法,使用QGraphicsView,所有内容都存在于同一类中。

我应该从QtQuick中使用哪个Qt类来获得类似于QGraphicsView的结果?

任何有关我的QML / Qt项目结构的建议都非常受欢迎。

0 个答案:

没有答案
相关问题