sách gpt4 ai đã đi

Qt图像移动/旋转

In lại 作者:行者123 更新时间:2023-12-04 13:08:56 28 4
mua khóa gpt4 Nike

我只想通过小部件的轴移动图像并围绕小部件的中心旋转(就像任何数字绘画软件中的 Canvas ),但它围绕其左顶点旋转......

QPainter p(this);
QTransform trans;

trans.translate(width()/2, -height()/2);
trans.rotate(angle);

QTransform inverse = trans.inverted();
inverse.translate(-canvas.width()/2, -canvas.height()/2);

p.setTransform(trans);
p.drawImage(inverse.map(canvasPos), canvas);

如何让它正确旋转?

1 Câu trả lời

您可以将图像的初始重新居中、旋转和最终结果在小部件中心的居中结合在一个单一的转换中。

QTransform 上的操作以相反的顺序完成,因为最后一个应用于 QTransform 的操作将是第一个应用于图像的操作:

// QImage canvas;
QPainter p(this);
QTransform trans;

// Move to the center of the widget
trans.translate(width()/2, height()/2);

// Do the rotation
trans.rotate(angle);

// Move to the center of the image
trans.translate(-canvas.width()/2, -canvas.height()/2);

p.setTransform(trans);
// Draw the image at (0,0), because everything is already handled by the transformation
p.drawImage(QPoint(0,0), canvas);

关于Qt图像移动/旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16584285/

28 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com