2
我在Qt中旋转图像时遇到了一些问题。每次我用QPainter旋转图像时,它变得越来越扭曲。这是最初的图像:旋转图像导致Qt失真
一些迭代它成为后:
这是我的代码:
void Ship::Move(int x, int y)
{
QPixmap rotatePixmap(shipPixels.size());
rotatePixmap.fill(Qt::transparent);
QTransform transform;
transform.translate(
rotatePixmap.size().width()/2,
rotatePixmap.size().height()/2
);
transform.rotate(degree);
transform.translate(
- rotatePixmap.size().width()/2,
- rotatePixmap.size().height()/2
);
QPainter p(&rotatePixmap);
p.setRenderHints(
QPainter::Antialiasing | QPainter::SmoothPixmapTransform,
true
);
p.setTransform(transform);
p.drawPixmap(0, 0, shipPixels);
p.end();
shipPixels = rotatePixmap;
this->setPixmap(shipPixels);
this->move(QPoint(x, y));
degree = 0;
}
对我来说,Qt的保持图像质量。行为是完全陌生的。有理由吗?
您需要每次计算新的新的旋转位图。你正在积累四舍五入的错误。 – asawyer
是的,如果你离开船舶像素之间没有触摸帧,而是使用它作为你的锚点,你应该很好去。 – Thadeux
你看到的效果是不可避免的,因为旋转90度以外的任何量都是有损操作。损失加起来。它与Qt无关。 –