void PainterImageTest::test(){ QImage image(":/ABBAPOH.png"); QImage result1; QImage result2; QVERIFY(!image.isNull()); image = image.convertToFormat(QImage::Format_ARGB32); image.save("/home/arch/0.png"); { result2 = QImage(image.size(), QImage::Format_ARGB32); QPainter p(&result2); p.drawImage(0, 0, image); } QVERIFY(image == result2); // passes qreal angle = -45; QTransform matrix; matrix.rotate(-angle); result1 = image.transformed(matrix, Qt::SmoothTransformation); { QSize size = result1.size(); result2 = QImage(size, QImage::Format_ARGB32); result2.fill(QColor(255, 255, 255, 0)); QPainter p(&result2); p.setRenderHint(QPainter::SmoothPixmapTransform); p.setRenderHint(QPainter::Antialiasing); p.setRenderHint(QPainter::HighQualityAntialiasing); QTransform matrix; matrix.translate(size.width() / 2.0, size.height() / 2.0); matrix.rotate(-angle); matrix.translate(-image.size().width() / 2.0, -image.size().height() / 2.0); p.setTransform(matrix); p.drawImage(0.0, 0.0, image); } QVERIFY(result1 == result2); // fails}
C++ (Qt)matrix.translate(-image.size().width() / 2.0, -image.size().height() / 2.0);
QSize size = result1.size(); result2 = QImage(size, QImage::Format_ARGB32);
C++ (Qt)matrix = QImage::trueMatrix( matrix, image.width(), image.height() );
C++ (Qt)QTransform matrix;matrix.rotate(-angle); // смещение относительно центраQPointF offset = matrix.map(QPointF(image.width() / 2. image.height() / 2)); // левый верхний угол в увеличенномQPointF left_top = QPointF(size.width() / 2, size.height() / 2) - offset; matrix = QTransform();matrix.translate(left_top.x(), left_top.y()); matrix.rotate(-angle);// рисуем имедж