Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt中的直线插值?_C++_Qt - Fatal编程技术网

C++ Qt中的直线插值?

C++ Qt中的直线插值?,c++,qt,C++,Qt,我试图通过分割线条的长度来减少画笔笔划的间距(在QPixmap上)。如果我乘以直线,那么间距会增加,但间距不会减少。此外,该行可以具有的最小长度似乎为1。显然,除以它会减少,可能低于允许的数量?不确定这是否会对pixmap的绘制产生负面影响 以下是违规代码: QLineF line = QLineF(lastPoint, endPoint); float lineLength = line.length(); qDebug() << line.length(); line.setLe

我试图通过分割线条的长度来减少画笔笔划的间距(在QPixmap上)。如果我乘以直线,那么间距会增加,但间距不会减少。此外,该行可以具有的最小长度似乎为1。显然,除以它会减少,可能低于允许的数量?不确定这是否会对pixmap的绘制产生负面影响

以下是违规代码:

QLineF line = QLineF(lastPoint, endPoint);
float lineLength = line.length();
qDebug() << line.length();
line.setLength(lineLength / 50.0f);
qDebug() << line.length();

painter.drawPixmap(line.p1().x() - 16, line.p2().y() - 16, 32, 32, testPixmap);
QLineF line=QLineF(最后一点,端点);
float lineLength=line.length();
qDebug()位置();
绘图=真;
}
}
无效InkSpot::mouseMoveEvent(QMouseEvent*事件)
{
if((事件->按钮()&Qt::LeftButton)&&drawing)
{
drawLineTo(事件->位置());
}
}
无效InkSpot::mouseReleaseEvent(QMouseEvent*事件)
{
如果(事件->按钮()==Qt::LeftButton&&drawing)
{
drawLineTo(事件->位置());
图纸=假;
}
}
无效墨水点::drawLineTo(常量QPoint和端点)
{
QPainter painter(油漆工)和pixmap;
painter.setPen(Qt::NoPen);
画家。挫折(Qt::NoBrush);
QFile*stencilInput;//输入文件,假定为一个方形原始8位灰度图像,没有JPG,没有GIF,没有大小/格式头,文件中只有8位值
char*brushPrototype;//原始笔刷原型
uchar*brushData;//原始笔刷数据
stencilInput=newqfile(“C:/brush3.raw”);//打开raw文件
模具输入->打开(QIODevice::只读);
qdatastreamin;
输入设置设备(模具输入);
int size=stencilInput->size();//将大小设置为原始文件的长度
brushPrototype=new char[size];//创建笔刷原型数组
in.readRawData(brushPrototype,size);//将文件读入原型
brushData=new-uchar[size];//创建构造QImage所需的uchar数组
对于(int i=0;iqDebug()不要使用
QLineF
,使用
QPainterPath
-它有几个非常方便的方法:

qreal QPainterPath::percentAtLength ( qreal len ) const
QPointF QPainterPath::pointAtPercent ( qreal t ) const
qreal length () const
因此,与使用
QLineF
不同,您可以创建一个仅由从旧图形光标位置到新图形光标位置的一条直线组成的绘制路径,获取该直线的长度,并在长度上按间距递增迭代以获得百分比值,从中可以为笔刷的每个位置获取
QPointF
就这么简单

编辑:好的,在这里,还没有测试过,从大脑到终端,但类似这样:

QPointF lastPosition, currentPosition;
qreal spacing;

void draw() {
    QPainterPath path;
    path.moveTo(lastPosition);
    path.lineTo(currentPosition);
    qreal length = path.length();
    qreal pos = 0;

    while (pos < length) {
        qreal percent = path.percentAtLength(pos);
        drawYourPixmapAt(path.pointAtPercent(percent)); // pseudo method, use QPainter and your brush pixmap instead
        pos += spacing;
    }
}
QPointF lastPosition,currentPosition;
间隙;
作废提款(){
QPainterPath路径;
路径。移动到(最后位置);
path.lineTo(当前位置);
qreal length=path.length();
qreal pos=0;
while(pos
我不知道如何构造循环来实现这一点。你能提供一个例子吗?顺便说一句,你真的应该将创建画笔pixmap的代码移动到一个单独的方法中,画笔只需要在更改时创建,没有必要每次画一条线就创建它。重复使用画笔,直到它需要更新为止。
QPointF lastPosition, currentPosition;
qreal spacing;

void draw() {
    QPainterPath path;
    path.moveTo(lastPosition);
    path.lineTo(currentPosition);
    qreal length = path.length();
    qreal pos = 0;

    while (pos < length) {
        qreal percent = path.percentAtLength(pos);
        drawYourPixmapAt(path.pointAtPercent(percent)); // pseudo method, use QPainter and your brush pixmap instead
        pos += spacing;
    }
}