Qt-interest Archive, May 2007
[Qt 4.3] Blt image upside-down
Message 1 in thread
Hi,
I've been using the Qt 4.3 snapshot 20070327 for an application which
displays images using QPainter::drawImage(). In order to flip the image I've
been scaling the image by -1 in y and then a translation of negative image
height to bring the image back onto the viewable display. This worked a
treat, however since I've moved to the RC1 version and recompiled, this
process now no longer works.
QRect rectDisplay(0, 0, m_displayWidth, m_displayHeight);
painter.scale(1, -1);
painter.translate(0, -rectDisplay.height());
painter.drawImage(rectDisplay, m_Image);
Is this the correct way to flip the image? I've tried supplying negative
values to drawImage() but I see that such functions use negative values as
an indication that the width & height should be determined from the image
itself so this doesn't work either.
How should I blt and image upside down?
Many thanks,
Simon
Message 2 in thread
Hi all,
I've still not come to a solution regarding scaling my QPainter object by a
negative number, it causes my image to no longer be displayed (even if I
modify the examples\painting\transformations example to a negative number).
Is this illegal? Surely it should just flip the image in the appropriate
axis?
Regards,
Simon
---------- Forwarded message ----------
From: Simon Bourne <simon.bourne@xxxxxxxxxxxxx>
Date: 09-May-2007 14:38
Subject: [Qt 4.3] Blt image upside-down
To: qt-interest@xxxxxxxxxxxxx, qt4-preview-feedback@xxxxxxxxxxxxx
Hi,
I've been using the Qt 4.3 snapshot 20070327 for an application which
displays images using QPainter::drawImage(). In order to flip the image I've
been scaling the image by -1 in y and then a translation of negative image
height to bring the image back onto the viewable display. This worked a
treat, however since I've moved to the RC1 version and recompiled, this
process now no longer works.
QRect rectDisplay(0, 0, m_displayWidth, m_displayHeight);
painter.scale(1, -1);
painter.translate(0, -rectDisplay.height());
painter.drawImage(rectDisplay, m_Image);
Is this the correct way to flip the image? I've tried supplying negative
values to drawImage() but I see that such functions use negative values as
an indication that the width & height should be determined from the image
itself so this doesn't work either.
How should I blt and image upside down?
Many thanks,
Simon
Message 3 in thread
I was waiting for an answer too, but I just noticed something that looks
wrong:
painter.scale(1, -1);
I think this should be painter.scale(1, 1); The translation takes case of
flipping. A negative (or zero) scale makes no sense.
JMHO,
Keith
**Please do not reply to me, reply to the list.**
On 05-15-2007 9:55 AM, "Simon Bourne" wrote:
> Hi all,
>
> I've still not come to a solution regarding scaling my QPainter object by a
> negative number, it causes my image to no longer be displayed (even if I
> modify the examples\painting\transformations example to a negative number). Is
> this illegal? Surely it should just flip the image in the appropriate axis?
>
> Regards,
> Simon
>
> ---------- Forwarded message ----------
> From: Simon Bourne <simon.bourne@xxxxxxxxxxxxx>
> Date: 09-May-2007 14:38
> Subject: [Qt 4.3] Blt image upside-down
> To: qt-interest@xxxxxxxxxxxxx, qt4-preview-feedback@xxxxxxxxxxxxx
> <mailto:qt4-preview-feedback@xxxxxxxxxxxxx>
>
>
> Hi,
>
> I've been using the Qt 4.3 snapshot 20070327 for an application which displays
> images using QPainter::drawImage(). In order to flip the image I've been
> scaling the image by -1 in y and then a translation of negative image height
> to bring the image back onto the viewable display. This worked a treat,
> however since I've moved to the RC1 version and recompiled, this process now
> no longer works.
>
> QRect rectDisplay(0, 0, m_displayWidth, m_displayHeight);
> painter.scale(1, -1);
> painter.translate(0, -rectDisplay.height());
> painter.drawImage(rectDisplay, m_Image);
>
> Is this the correct way to flip the image? I've tried supplying negative
> values to drawImage() but I see that such functions use negative values as an
> indication that the width & height should be determined from the image itself
> so this doesn't work either.
>
> How should I blt and image upside down?
>
> Many thanks,
> Simon
>
Message 4 in thread
Simon Bourne wrote:
> QRect rectDisplay(0, 0, m_displayWidth, m_displayHeight);
> painter.scale(1, -1);
> painter.translate(0, -rectDisplay.height());
> painter.drawImage(rectDisplay, m_Image);
Hi Simon,
I assume you're on windows? The code you have above is definitly the
correct way to draw images flipped onto another paint device using
QPainter. The scale(1, -1) combined with translate is correct.
There is currently a bug in QRasterPaintEngine which breaks flipping of
images in this way. If you go into
src/gui/painting/qpaintengine_raster.cpp and comment out the line
#define QT_FAST_SPANS
you'll get the correct behaviour.
On a side note... QImage has a function QImage::mirrored() which you can
use to flip images. If you're drawing the same image flipped multiple
times using QImage::mirrored() once and then reusing the already flipped
image will be significantly faster, as drawing images without
transformation is faster than drawing transformed ones.
best regards,
Gunnar
--
[ signature omitted ]