Reflecting a QPixmap ?

Clarence Dang dang at kde.org
Sun Aug 5 01:46:27 BST 2007


On Sunday 05 August 2007 04:02, John Tapsell wrote:
>   Does anyone know if I can reflect a QPixmap, without doing the
> horribly slow conversion to a QImage first?  I want to reflect a
> QPixmap around the x-axis.  On my system it takes between 20ms to
> 100ms to use transformation.

I think QPainter::setMatrix() followed by QPainter::drawPixmap() will do it.

I've only tested the matrix under Qt3 and it looks like this:

// width, height = dimensions of image
// horz = horizontal flip
// vert = vertical flip
QMatrix flipMatrix (int width, int height, bool horz, bool vert)
{
    return QMatrix (horz ? -1 : +1,  // m11
                     0,  // m12
                     0,  // m21
                     vert ? -1 : +1,  // m22
                     horz ? (width - 1) : 0,  // dx
                     vert ? (height - 1) : 0);  // dy
}

[trunk/KDE/kdegraphics/kolourpaint/pixmapfx/kpPixmapFX_Transforms.cpp]


I was going to suggest QPixmap::transformed(), which I currently use for 
flipping but then I read that it "is slow because it involves transformation 
to a QImage, non-trivial computations and a transformation back to a 
QPixmap" [http://doc.trolltech.com/4.3/qpixmap.html#transformed].  If this is 
really true, I'll simply switch my code to use QPainter instead.




More information about the kde-core-devel mailing list